# CMake错误：CMakeLists.txt中：未知的CMake命令"my_custom_function"。

- **ID:** `cmake/unknown-cmake-command`
- **领域:** cmake
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

CMakeLists.txt调用了一个未定义的函数或宏，原因是缺少include、拼写错误或不支持的模块。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| cmake 2.8 | active | — | — |
| cmake 3.0 | active | — | — |
| cmake 3.16 | active | — | — |
| cmake 3.28 | active | — | — |

## 解决方案

1. ```
   检查拼写错误：确保命令拼写正确（例如'target_link_libraries'而不是'target_link_library'）。
   ```
2. ```
   如果命令来自自定义模块，在调用前添加include(MyModule)，或使用include(path/to/module.cmake)。
   ```
3. ```
   如果命令来自旧版CMake，升级CMake或使用兼容性包装：cmake_minimum_required(VERSION 3.10)。
   ```

## 无效尝试

- **Typing the command name in a different case (e.g., 'My_Function' vs 'my_function')** — CMake commands are case-insensitive but must match exactly; case issues rarely cause this error. (30% 失败率)
- **Adding the command as a comment to suppress the error** — Comments are ignored; the command must be defined or removed. (100% 失败率)
- **Installing a third-party module without including it** — The module must be included with include() or find_package() before use. (80% 失败率)
