CMP0057 cmake config_error ai_generated true

CMake 错误:未设置策略 CMP0057:在 CMake 3.3 之前的版本中,if() 命令不支持 IN_LIST 运算符。

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

其他格式: JSON · Markdown 中文 · English
88%修复率
85%置信度
1证据数
2023-03-15首次发现

版本兼容性

版本状态引入弃用备注
CMake 3.2 active
CMake 3.3 active
CMake 3.10 active
CMake 3.16 active

根因分析

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

English

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

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

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

    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% 失败

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

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

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