project(): Introduce PROJECT_IS_TOP_LEVEL normal and <project-name>_IS_TOP_LEVEL variables
To make a project's CML file trivial to consume by directly (add_subdirectory
) or indirectly (FetchContent
or libraries wrapping it like CPM.cmake) making it part of the build tree, there are certain things that must only conditionally be executed, such as inclusion of the CPack
module, enabling tests and other targets only useful for developers of the given project, fixing the include dir location, basically doing anything other than providing targets of the project intended to be consumed.
CMake automatically providing variables to do this check would fit in well with the others.
Behavior:
A call to project(Example)
would set the normal variable PROJECT_IS_TOP_LEVEL
and the cache variable Example_IS_TOP_LEVEL
to the value returned by cmMakefile#IsRootMakefile()
.
Would this require an additional policy due to the new variables?
If this is something that is desirable, I will submit a PR for the implementation and documentation.