1PROJECT_IS_TOP_LEVEL 2-------------------- 3 4.. versionadded:: 3.21 5 6A boolean variable indicating whether the most recently called 7:command:`project` command in the current scope or above was in the top 8level ``CMakeLists.txt`` file. 9 10Some modules should only be included as part of the top level 11``CMakeLists.txt`` file to not cause unintended side effects in the build 12tree, and this variable can be used to conditionally execute such code. For 13example, consider the :module:`CTest` module, which creates targets and 14options: 15 16.. code-block:: cmake 17 18 project(MyProject) 19 ... 20 if(PROJECT_IS_TOP_LEVEL) 21 include(CTest) 22 endif() 23 24The variable value will be true in: 25 26* the top-level directory of the project 27* the top-level directory of an external project added by :module:`ExternalProject` 28 29The variable value will be false in: 30 31* a directory added by :command:`add_subdirectory` 32* a directory added by :module:`FetchContent` 33