PROJECT_IS_TOP_LEVEL.rst 576 B

123456789101112131415161718192021
  1. PROJECT_IS_TOP_LEVEL
  2. --------------------
  3. .. versionadded:: 3.21
  4. A boolean variable indicating whether :command:`project` was called in a top
  5. level ``CMakeLists.txt`` file.
  6. Some modules should only be included as part of the top level
  7. ``CMakeLists.txt`` file to not cause unintended side effects in the build
  8. tree, and this variable can be used to conditionally execute such code. For
  9. example, consider the :module:`CTest` module, which creates targets and
  10. options:
  11. .. code-block:: cmake
  12. project(MyProject)
  13. ...
  14. if(PROJECT_IS_TOP_LEVEL)
  15. include(CTest)
  16. endif()