CMP0074 cmake config_error ai_generated true

CMake Error: Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables. Run "cmake --help-policy CMP0074" for policy details.

ID: cmake/policy-cmp0074-not-set-find-package

Also available as: JSON · Markdown · 中文
95%Fix Rate
84%Confidence
1Evidence
2023-04-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
cmake 3.12 active
cmake 3.15 active
cmake 3.20 active
cmake 3.25 active

Root Cause

CMake 3.12+ has a new policy CMP0074 that controls whether find_package honors <PackageName>_ROOT environment variables. If the policy is not set explicitly, CMake issues an error to force the developer to decide.

generic

中文

CMake 3.12+ 引入了新策略 CMP0074,用于控制 find_package 是否遵循 <PackageName>_ROOT 环境变量。如果未显式设置该策略,CMake 会报错以强制开发者决定。

Official Documentation

https://cmake.org/cmake/help/latest/policy/CMP0074.html

Workarounds

  1. 95% success Add before any find_package call: cmake_policy(SET CMP0074 NEW) to enable the new behavior.
    Add before any find_package call: cmake_policy(SET CMP0074 NEW) to enable the new behavior.
  2. 90% success Add cmake_policy(SET CMP0074 OLD) to use legacy behavior (ignore <PackageName>_ROOT).
    Add cmake_policy(SET CMP0074 OLD) to use legacy behavior (ignore <PackageName>_ROOT).
  3. 85% success Set cmake_minimum_required(VERSION 3.11) to avoid the policy entirely, but this may not be ideal for modern projects.
    Set cmake_minimum_required(VERSION 3.11) to avoid the policy entirely, but this may not be ideal for modern projects.

中文步骤

  1. 在任何 find_package 调用之前添加:cmake_policy(SET CMP0074 NEW) 以启用新行为。
  2. 添加 cmake_policy(SET CMP0074 OLD) 以使用旧行为(忽略 <PackageName>_ROOT)。
  3. 设置 cmake_minimum_required(VERSION 3.11) 以完全避免该策略,但这可能不适用于现代项目。

Dead Ends

Common approaches that don't work:

  1. 70% fail

    CMAKE_POLICY_DEFAULT_CMP0074 is a variable, not a policy command. Must use cmake_policy(SET CMP0074 NEW) explicitly.

  2. 95% fail

    Without policy set, CMake will still error out. The policy must be set before find_package.

  3. 50% fail

    Policy CMP0074 exists in 3.12+; using an older version may suppress the error but also lose new features. Not a proper fix.