如何在CMake中使用现有的QMake项目(.pro项目文件)作为“外部项目”?

时间:2015-10-23 17:51:08

标签: qt cmake external projects-and-solutions qmake

是否有一个简明的文档或示例,说明如何将现有的QMake项目与.pro项目文件一起用作CMake中的“外部项目”?这可以在qtcreator中通过将一个项目标记为另一个项目的依赖项来完成,但是使用ExternalProject()CMake语法更明确地定义它会更好。

相关问题:CMake: How to build external projects and include their targets

1 个答案:

答案 0 :(得分:1)

这样的事情有效。然后,您可以通过打开.pro文件从主CMake项目树中的qtcreator编辑文件, OR ;非常适合在SomeGarbageApplication中快速迭代QT小部件,SomeGarbageApplication是大型cmake构建树的一部分。

macro(DeclareProjectFiles  Tag  Filez)
######### Trick: use this syntax to make arbitrary files
#########             appear in IDE project. #######################
### Note: pass in the raw name of a list variable,
###   since it will get expanded here in this macro.
  add_custom_target(${Tag}_files  ALL
                    pwd
                    COMMAND ls -ltrh
                    COMMENT  " ${Tag} files thunk... got list: [ ${${Filez}} ]"
                    VERBATIM
                    SOURCES  ${${Filez}}
                   )    
endmacro()

    message(STATUS "QT_QMAKE_EXE is:  ${QT_QMAKE_EXECUTABLE}")

set(Z  SomeGarbageApplication)
file(GLOB  ${Z}_Files
            ./*.cpp
            ./*.h
            ./*.ui
            ./*.pro
            ./*.png
            ./*.jpg)

DeclareProjectFiles( ${Z}_grbg  ${Z}_Files )

add_custom_target(${Z}_pro  ALL)

set(ExtraQMakeArgs  -r -spec linux-g++ CONFIG+=release)

# note: use killall because this can/will fail if the exe is running
#       But, need || true to not fail build when it's not running. 

add_custom_command(TARGET  ${Z}_pro
                   COMMAND  killall
                   ARGS     -q -9 -v ${Z} || true
                   COMMAND  ${QT_QMAKE_EXECUTABLE}
                   ARGS     -query
                   COMMAND  ${QT_QMAKE_EXECUTABLE}
                   ARGS     ${CMAKE_CURRENT_SOURCE_DIR}/${Z}.pro ${ExtraQMakeArgs}
                   COMMAND  make  ${Z}
                   ARGS     -j4
                   COMMAND  cp
                   ARGS     ${Z} ${CMAKE_CURRENT_SOURCE_DIR}/${${Z}_config}  ${CMAKE_BINARY_DIR}/bin/
                   WORKING_DIRECTORY  ${CMAKE_CURRENT_BINARY_DIR}
                   VERBATIM
                   )    
#################################################################