在Qt項目的構建系統中工作時,我遇到了同樣的問題,並且出現了這個解決方案,這要歸功於此頁面上的其他帖子。我包含了一個從我的makefiles改編的完整示例。希望這可以幫助!
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)
作爲獎勵,你可以做source_group(頭文件$ {} INCS)在一個單獨的顯示它們VS文件夾 – 2009-09-01 03:08:40