# CMake 错误：无法确定 CMAKE_SYSTEM_NAME = "Generic" 的平台名称

- **ID:** `cmake/generic-platform-name-unknown`
- **领域:** cmake
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

CMake 无法为给定的系统名称找到有效的平台文件；通常发生在使用自定义工具链文件而未正确指定 CMAKE_SYSTEM_NAME 时。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| cmake 3.26.0 | active | — | — |
| cmake 3.27.0 | active | — | — |
| cmake 3.28.0 | active | — | — |

## 解决方案

1. ```
   在项目的 cmake 模块路径中创建名为 'Platform/Generic.cmake' 的自定义平台文件，包含最小设置：

# cmake/Platform/Generic.cmake
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_CXX_COMPILER_WORKS TRUE)

然后设置 CMAKE_MODULE_PATH 指向该目录。
   ```
2. ```
   通过正确设置工具链文件来使用现有的 'Generic' 平台：

cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake -DCMAKE_SYSTEM_NAME=Generic /path/to/source

确保 toolchain.cmake 设置了 CMAKE_SYSTEM_NAME 为 Generic。
   ```

## 无效尝试

- **Set CMAKE_SYSTEM_NAME to "Linux" or "Windows" arbitrarily** — Forces a platform file that may not match the target environment, causing linker or compiler errors. (70% 失败率)
- **Remove CMAKE_SYSTEM_NAME entirely** — CMake will auto-detect the host system, which defeats cross-compilation and may produce wrong binaries. (85% 失败率)
