cmake - CMake 策略的范围是什么?

标签 cmake

我有一个包含多个子目录的 CMake 项目,例如:

dir1
    subdir11
    subdir12
dir2
    subdir21
    subdir22

根 CMakeLists.txt:
add_subdirectory(dir1)
add_subdirectory(dir2)

dir1 和 dir2 中的 CMakeLists 类似:
add_subdirectory(subdir11)
add_subdirectory(subdir12)


add_subdirectory(subdir21)
add_subdirectory(subdir22)

子目录中的 CMakeLists 做实际工作。

文件dir1/subdir12/CMakeLists.txt设置CMP0046政策至OLD :
cmake_policy(SET CMP0046 OLD) #silently ignore missing dependencies

我的问题是 - CMP0046 的这个设置会传播到 subdir21subdir22 ?

最佳答案

不。这个问题最好直接回答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.



要对特定级别进行临时更改,不包括 sub_directories,您可以使用
cmake_policy(PUSH)
cmake_policy(POP)

如果您希望在 subdir21 和 subdir22 中应用该策略,则需要将其显式添加到该处或考虑将其添加到公共(public)父级。

关于cmake - CMake 策略的范围是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29123444/

相关文章:

c++ - cmake生成VS项目不能断点

android - 错误 :Error occurred while communicating with CMake server

c++ - 终止 CMAKE 目标的连续执行?

c++ - Cmake 重新生成变量变化

cmake - CPack 无法使用 AppleScript 调整磁盘镜像和音量图标

c++ - 使用 cmake 制作项目源目录的头文件后代

OpenCV 3.0 安装问题

cmake 解析错误 :Invalid escape sequence\o

linux - 使用 CMake 在 Windows 下针对 Linux 进行跨平台构建

c++ - 通过 CMake 将外部库包含到 CLion 项目中