cmake config_error ai_generated true

CMake Error: CMake Error in CMakeLists.txt: Unknown CMake command "cmake_policy".

ID: cmake/missing-cmake-policies-package

Also available as: JSON · Markdown · 中文
87%Fix Rate
82%Confidence
1Evidence
2024-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
CMake 2.8 active
CMake 3.5 active
CMake 3.20 active

Root Cause

The cmake_policy command is used incorrectly (e.g., misspelled, wrong case, or called before cmake_minimum_required) or CMake version is too old to support it.

generic

中文

cmake_policy 命令使用不正确(例如拼写错误、大小写错误或在 cmake_minimum_required 之前调用),或者 CMake 版本太旧不支持它。

Official Documentation

https://cmake.org/cmake/help/latest/command/cmake_policy.html

Workarounds

  1. 95% success Ensure cmake_minimum_required(VERSION 3.0) is placed before any cmake_policy calls. Example: cmake_minimum_required(VERSION 3.0) then cmake_policy(SET CMP0000 NEW).
    Ensure cmake_minimum_required(VERSION 3.0) is placed before any cmake_policy calls. Example: cmake_minimum_required(VERSION 3.0) then cmake_policy(SET CMP0000 NEW).
  2. 90% success Check for typos: use cmake_policy (lowercase, underscore) not cmakepolicy or CMakePolicy. Correct syntax: cmake_policy(VERSION 3.0).
    Check for typos: use cmake_policy (lowercase, underscore) not cmakepolicy or CMakePolicy. Correct syntax: cmake_policy(VERSION 3.0).
  3. 85% success If using an old CMake version, upgrade to at least 3.0, or use conditional code: if(CMAKE_VERSION VERSION_GREATER 2.6) cmake_policy(...) endif().
    If using an old CMake version, upgrade to at least 3.0, or use conditional code: if(CMAKE_VERSION VERSION_GREATER 2.6) cmake_policy(...) endif().

中文步骤

  1. 确保 cmake_minimum_required(VERSION 3.0) 放在任何 cmake_policy 调用之前。示例:cmake_minimum_required(VERSION 3.0) 然后 cmake_policy(SET CMP0000 NEW)。
  2. 检查拼写错误:使用 cmake_policy(小写,下划线),而不是 cmakepolicy 或 CMakePolicy。正确语法:cmake_policy(VERSION 3.0)。
  3. 如果使用旧版 CMake,升级到至少 3.0,或使用条件代码:if(CMAKE_VERSION VERSION_GREATER 2.6) cmake_policy(...) endif()。

Dead Ends

Common approaches that don't work:

  1. 90% fail

    cmake_policy was introduced in CMake 2.6; if cmake_minimum_required is set to a lower version, the command may be unrecognized.

  2. 100% fail

    cmake_policy is a built-in command, not a variable; using set() with it creates a variable that does nothing.