CMake检查主项目是否被调用

时间:2012-11-08 12:39:25

标签: cmake

我有这种项目目录设计:

Main:
    CMakeLists.txt
    subproject1:
         CMakeLists.txt   
    subproject2
         CMakeLists.txt   

如果主项目调用subproject1 cmake,或者作为独立项目调用subproject1 / CMakeLists.txt文件,我该怎么办?

1 个答案:

答案 0 :(得分:5)

你走了:

if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
# We are building as stand-alone project
project(subproject1)
...
else()
# We are building as part of Main project
endif()