Qt/CMake 新源文件有困难
Qt/CMake difficulty with new source files
我使用 Qt 的方式是,与 Qt 相关的文件位于单独的子目录中 GUI
,并且我使用 CMake 文件,其相关部分如下所示。基本上这个设置有效,但是当我添加一个新文件(类似于自己的小部件)时,新文件编译正常,但在链接阶段找不到新对象。我过去常常删除 build 子目录,之后一切正常。所以,我的问题是:我对 CMake 有什么误解吗? (我想这些症状是由一些缓存问题引起的)
include_directories(${Qt5Widgets_INCLUDES} GUI/include main/include)
add_definitions(${Qt5Widgets_DEFINITIONS})
file(GLOB_RECURSE QOBJECT_HEADERS
"GUI/include/*.h"
)
file(GLOB_RECURSE QOBJECT_SOURCES
"GUI/*.cpp"
)
QT5_WRAP_CPP(hdr_moc ${QOBJECT_HEADERS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS} -std=c++11 -Wall")
add_executable(simGUI main/sim_GUI.cpp ${QOBJECT_SOURCES}
${hdr_moc})
# Use the Widgets module from Qt 5.
target_link_libraries(simGUI Qt5::Widgets)
来自 CMake 文档:
We do not recommend using
GLOB
to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate.
典型的方法是手动列出所有文件。