CMake政策的范围是什么? [英] What is the scope of CMake policies?
问题描述
我有一个带有多个子目录的CMake项目,例如:
I've got a CMake project with several subdirectories, like this one:
dir1
subdir11
subdir12
dir2
subdir21
subdir22
根CMakeLists。 txt:
Root CMakeLists.txt:
add_subdirectory(dir1)
add_subdirectory(dir2)
CMake dir1和dir2中的列表类似:
CMakeLists in dir1 and dir2 are similar:
add_subdirectory(subdir11)
add_subdirectory(subdir12)
和
add_subdirectory(subdir21)
add_subdirectory(subdir22)
子目录中的CMakeLists会进行实际工作。
And CMakeLists in subdirs do actual work.
文件 dir1 / subdir12 / CMakeLists.txt
将 CMP0046
策略设置为 OLD
:
cmake_policy(SET CMP0046 OLD) #silently ignore missing dependencies
我的问题是-CMP0046的此设置是否传播到 subdir21
和 subdir22
吗?
My question is - will this setting of CMP0046 propagate to subdir21
and subdir22
?
推荐答案
No. This question is best answered straight from the documentation...
策略设置使用堆栈作用域。进入项目的新子目录(带有
add_subdirectory)时,将压入
堆栈的新级别,并在退出时弹出该堆栈。因此,在项目的一个目录中设置
策略不会影响父目录或同级
目录,但会影响子目录。
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)
如果要将策略应用于subdir21和subdir22,则需要添加它在那里,或考虑将其添加到公共父级。
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.
这篇关于CMake政策的范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!