Listing header files in Visual Studio C++ project generated by cmake

后端 未结 4 1163
南方客
南方客 2020-12-12 18:44

I\'m building a cmake based build system for our product. The problem is that Visual Studio project, generated by cmake, doesn\'t display header files in solution browser.

4条回答
  •  心在旅途
    2020-12-12 19:45

    I had the same problem while working at a build system for a Qt project and I came out with this solution, thanks to the other posts on this page. I included a complete example adapted from my makefiles. Hope this helps!

    cmake_minimum_required (VERSION 2.6) 
    project (DemoSolution)
    
    find_package(Qt4 REQUIRED)
    include(${QT_USE_FILE})
    add_definitions(${QT_DEFINITIONS})
    
    include_directories (../../include/)
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    
    file(GLOB Demo_SOURCES *.cpp)
    file(GLOB Demo_HEADERS *.hpp)
    file(GLOB Demo_FORMS *.ui)
    file(GLOB Demo_RESOURCES resources.qrc)
    
    qt4_wrap_cpp(Demo_MOC ${Demo_HEADERS})
    qt4_wrap_ui(Demo_FORMS_HEADERS ${Demo_FORMS})
    qt4_add_resources(Demo_RESOURCES_RCC ${Demo_RESOURCES})
    
    source_group("Headers" FILES ${Demo_HEADERS})
    source_group("MOC" FILES ${Demo_MOC})
    
    set(QT_USE_QTNETWORK, true)
    set(QT_USE_QTSQL, true)
    set(QT_USE_QTXML, true)
    
    add_library(Demo SHARED
        ${Demo_SOURCES}
        ${Demo_HEADERS}
        ${Demo_MOC}
        ${Demo_FORMS_HEADERS}
        ${Demo_RESOURCES_RCC}
        )
    
    target_link_libraries(Demo ${QT_LIBRARIES})
    add_definitions(-D_DEMO_EXPORTS)
    

提交回复
热议问题