I've got a CMake project with several subdirectories, like this one:
dir1
subdir11
subdir12
dir2
subdir21
subdir22
Root CMakeLists.txt:
add_subdirectory(dir1)
add_subdirectory(dir2)
CMakeLists in dir1 and dir2 are similar:
add_subdirectory(subdir11)
add_subdirectory(subdir12)
and
add_subdirectory(subdir21)
add_subdirectory(subdir22)
And CMakeLists in subdirs do actual work.
The file dir1/subdir12/CMakeLists.txt
sets the CMP0046
policy to OLD
:
cmake_policy(SET CMP0046 OLD) #silently ignore missing dependencies
My question is - will this setting of CMP0046 propagate to subdir21
and subdir22
?
No. This question is best answered straight from the documentation...
Policy settings are scoped using a stack. A new level of the stack is pushed when entering a new subdirectory of the project (with add_subdirectory) and popped when leaving it. Therefore setting a policy in one directory of a project will not affect parent or sibling directories but will affect subdirectories.
For making temporary changes to a specific level, without including sub_directories, you can use
cmake_policy(PUSH)
cmake_policy(POP)
If you want the policy applied in subdir21 and subdir22 you either need to add it there explicitly or consider adding it to the common parent.
Per the comment for this answer https://unix.stackexchange.com/a/512695/48776
It's possible to set policy globally with set(CMAKE_POLICY_DEFAULT_CMP0046 OLD)
I have tried on different 3.x versions, it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With