CMP0057 cmake config_error ai_generated true

CMake Error: Policy CMP0057 is not set: IN_LIST operator is not supported in if() commands before CMake 3.3.

ID: cmake/policy-cmp0057-not-supported

Also available as: JSON · Markdown · 中文
88%Fix Rate
85%Confidence
1Evidence
2023-03-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
CMake 3.2 active
CMake 3.3 active
CMake 3.10 active
CMake 3.16 active

Root Cause

IN_LIST operator in if() command requires CMake 3.3+ and policy CMP0057 set to NEW; running older CMake or policy not set causes error.

generic

中文

if() 命令中的 IN_LIST 运算符需要 CMake 3.3+ 并将策略 CMP0057 设为 NEW;运行较旧 CMake 或未设置策略会导致错误。

Official Documentation

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

Workarounds

  1. 95% success Set cmake_minimum_required(VERSION 3.3) or higher at top of CMakeLists.txt, or explicitly call cmake_policy(SET CMP0057 NEW) before using IN_LIST.
    Set cmake_minimum_required(VERSION 3.3) or higher at top of CMakeLists.txt, or explicitly call cmake_policy(SET CMP0057 NEW) before using IN_LIST.
  2. 85% success Replace IN_LIST with a macro that iterates manually for CMake <3.3 compatibility.
    Replace IN_LIST with a macro that iterates manually for CMake <3.3 compatibility.

中文步骤

  1. Set cmake_minimum_required(VERSION 3.3) or higher at top of CMakeLists.txt, or explicitly call cmake_policy(SET CMP0057 NEW) before using IN_LIST.
  2. Replace IN_LIST with a macro that iterates manually for CMake <3.3 compatibility.

Dead Ends

Common approaches that don't work:

  1. Setting cmake_minimum_required(VERSION 3.1) to bypass 80% fail

    Lower minimum version does not enable policy CMP0057; IN_LIST still fails.

  2. Using if(DEFINED var IN_LIST list) syntax from older CMake 90% fail

    DEFINED IN_LIST is not a valid syntax; CMake parses it incorrectly.

  3. Removing IN_LIST and using foreach loop with manual check 30% fail

    Code works but is inefficient; doesn't fix the underlying policy issue for other modules.