我有这个CMakeLists.txt。
从模式来看,似乎有一种更好、更干净的方法可以做到这一点。
QT5_WRAP_CPP(windowui_moc ../../include/QtDisplay/WindowUI.hpp)
QT5_WRAP_CPP(mainwindow_moc ../../include/QtDisplay/MainWindow.hpp)
QT5_WRAP_CPP(editor_moc ../../include/QtDisplay/SpiderEditor.hpp)
QT5_WRAP_CPP(output_moc ../../include/QtDisplay/OutputPane.hpp)
add_library(Display WindowUI.cpp MainWindow.cpp SpiderEditor.cpp OutputPane.cpp
${windowui_moc} ${mainwindow_moc} ${editor_moc} ${output_moc})
qt5_use_modules(Display Widgets Core)
我对 cmake 中使用的约定了解不多,所以我无法查找"解决方案"的名称。
您是否正在寻找这样的东西:
set (Display_src
${PROJECT_SOURCE_DIR}/WindowUI.cpp
${PROJECT_SOURCE_DIR}/MainWindow.cpp
${PROJECT_SOURCE_DIR}/SpiderEditor.cpp
${PROJECT_SOURCE_DIR}/OutputPane.cpp
)
set (Display_hdr
${PROJECT_SOURCE_DIR}/../../include/QtDisplay/WindowUI.hpp
${PROJECT_SOURCE_DIR}/../../include/QtDisplay/MainWindow.hpp
${PROJECT_SOURCE_DIR}/../../include/QtDisplay/SpiderEditor.hpp
${PROJECT_SOURCE_DIR}/../../include/QtDisplay/OutputPane.hpp
)
qt5_wrap_cpp (Display_hdr_moc ${Display_hdr})
add_library (Display
${Display_src}
${Display_hdr_moc}
)
# For Qt 5.2+
target_link_libraries (Display Qt5::Widgets)
# For Qt 5.1.
# qt5_use_modules(Display Widgets Core)
你可以像这样使用 CMake 的 automoc 功能:
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_library(Display MainWindow.cpp SpiderEditor.cpp OutputPane.cpp)
qt5_use_modules(Display Widgets Core)