PROJECT_IS_TOP_LEVEL.rst 875 B

12345678910111213141516171819202122232425262728293031
  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()
  17. The variable value will be true in:
  18. * the top-level directory of the project
  19. * the top-level directory of an external project added by :module:`ExternalProject`
  20. The variable value will be false in:
  21. * a directory added by :command:`add_subdirectory`
  22. * a directory added by :module:`FetchContent`