_IS_TOP_LEVEL documentation incorrect for add_subdirectory behaviour
The current documentation for PROJECT_IS_TOP_LEVEL
says:
The variable value will be false in:
- a directory added by add_subdirectory()
but I think it means to say "in a directory added by add_subdirectory() which contains a project() call". I'm not sure, but I'm also assuming it also means "and in any cmake files it include()s or parses as a result of another add_subdirectory".
I tried it out and that seems to be the case: it is still true in a CMakeLists.txt file added by add_subdirectory() if the added CMakeLists.txt file does not call project(). This also seems consistent with the documentation's earlier statement that- (emphasis added)
[it is] A boolean variable indicating whether the most recently called project() command in the current scope or above was in the top level CMakeLists.txt file.
The current documentation for <PROJECT-NAME>_IS_TOP_LEVEL
says the exact same thing, which I'm guessing is a bad copy-paste? I even wonder if the whole "The variable value will be false in:" section for this documentation page is incorrect and should be removed. I tried creating a project "my_project", and then creating in a subdirectory a CMakeLists.txt calling project("my_project_example"), and in the top one adding it via add_subdirectory() and printing a message if "my_project_IS_TOP_LEVEL
" was true in the example subdirectory. The message printed, but it doesn't print if changing it to check for my_project_example_IS_TOP_LEVEL
.