cmake
config_error
ai_generated
true
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%Fix Rate
84%Confidence
1Evidence
2023-07-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| CMake 3.13 | active | — | — | — |
| CMake 3.14 | active | — | — | — |
| CMake 3.20 | active | — | — | — |
Root Cause
CMake policy CMP0077 is not explicitly set, causing option() to behave inconsistently when a normal variable with the same name exists.
generic中文
未显式设置CMake策略CMP0077,导致当存在同名普通变量时,option()行为不一致。
Official Documentation
https://cmake.org/cmake/help/latest/policy/CMP0077.htmlWorkarounds
-
95% success Set the policy to NEW at the beginning of CMakeLists.txt: cmake_policy(SET CMP0077 NEW)
Set the policy to NEW at the beginning of CMakeLists.txt: cmake_policy(SET CMP0077 NEW)
-
80% success If the old behavior is needed, set to OLD: cmake_policy(SET CMP0077 OLD), but this is not recommended for new projects.
If the old behavior is needed, set to OLD: cmake_policy(SET CMP0077 OLD), but this is not recommended for new projects.
中文步骤
在CMakeLists.txt开头设置策略为NEW:cmake_policy(SET CMP0077 NEW)
如果需要旧行为,设置为OLD:cmake_policy(SET CMP0077 OLD),但不推荐用于新项目。
Dead Ends
Common approaches that don't work:
-
40% fail
The warning may lead to subtle bugs where option() does not behave as expected, especially in cache variable scenarios.
-
50% fail
OLD behavior may break modern CMake patterns and cause unexpected cache variable behavior.