Dejwi
Dejwi

Reputation: 4487

CMake check if the main project was called

I've got this kind of project directory design:

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

How can I check in subproject1/CMakeLists.txt file if subproject1 cmake was called by the Main project, or as a standalone one?

Upvotes: 6

Views: 1647

Answers (1)

arrowd
arrowd

Reputation: 34401

Here you go:

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()

Upvotes: 8

Related Questions