如何简化此cmake文件?

时间:2015-03-16 12:59:27

标签: c++ qt cmake qt5

我有这个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中使用的约定了解不多,所以我无法查找'解决方案'被称为。

2 个答案:

答案 0 :(得分:1)

你在找这样的东西:

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)

答案 1 :(得分:0)

您可以像这样使用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)