5

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?

Dejwi
  • 4,393
  • 12
  • 45
  • 74

1 Answers1

7

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()
arrowd
  • 33,231
  • 8
  • 79
  • 110