cmake
config_error
ai_generated
true
CMake警告(开发):未设置策略CMP0077:option()尊重普通变量。运行"cmake --help-policy CMP0077"查看策略详情。使用cmake_policy命令设置策略并抑制此警告。
CMake Warning (dev): Policy CMP0077 is not set: option() honors normal variables. Run "cmake --help-policy CMP0077" for policy details. Use the cmake_policy command to set the policy and suppress this warning.
ID: cmake/policy-cmp0077-not-set
90%修复率
84%置信度
1证据数
2023-07-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| CMake 3.13 | active | — | — | — |
| CMake 3.14 | active | — | — | — |
| CMake 3.20 | active | — | — | — |
根因分析
未显式设置CMake策略CMP0077,导致当存在同名普通变量时,option()行为不一致。
English
CMake policy CMP0077 is not explicitly set, causing option() to behave inconsistently when a normal variable with the same name exists.
官方文档
https://cmake.org/cmake/help/latest/policy/CMP0077.html解决方案
-
在CMakeLists.txt开头设置策略为NEW:cmake_policy(SET CMP0077 NEW)
-
如果需要旧行为,设置为OLD:cmake_policy(SET CMP0077 OLD),但不推荐用于新项目。
无效尝试
常见但无效的做法:
-
40% 失败
The warning may lead to subtle bugs where option() does not behave as expected, especially in cache variable scenarios.
-
50% 失败
OLD behavior may break modern CMake patterns and cause unexpected cache variable behavior.