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

- **ID:** `cmake/policy-cmp0057-not-supported`
- **领域:** cmake
- **类别:** config_error
- **错误码:** `CMP0057`
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CMake 3.2 | active | — | — |
| CMake 3.3 | active | — | — |
| CMake 3.10 | active | — | — |
| CMake 3.16 | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **Setting cmake_minimum_required(VERSION 3.1) to bypass** — Lower minimum version does not enable policy CMP0057; IN_LIST still fails. (80% 失败率)
- **Using if(DEFINED var IN_LIST list) syntax from older CMake** — DEFINED IN_LIST is not a valid syntax; CMake parses it incorrectly. (90% 失败率)
- **Removing IN_LIST and using foreach loop with manual check** — Code works but is inefficient; doesn't fix the underlying policy issue for other modules. (30% 失败率)
