# CMake 错误：check_cxx_source_compiles 失败，错误信息为：'error: #error Architecture not supported'

- **ID:** `cmake/check-cxx-source-compiles-arch-specific`
- **领域:** cmake
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 78%

## 根因

CMake 的 TryCompile 检查使用的源代码片段包含架构守卫（#ifdef __arm__ 等），在当前目标 CPU 上失败，导致特性检测返回 false 并中止。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CMake 3.27 | active | — | — |
| CMake 3.28 | active | — | — |
| GCC 12 | active | — | — |
| Clang 16 | active | — | — |

## 解决方案

1. ```
   通过设置 check_cxx_source_compiles 会定义的变量来覆盖测试，例如在 CMakeCache.txt 中设置 set(HAVE_ARCH_SUPPORT 1) 或通过命令行 -DHAVE_ARCH_SUPPORT=ON。
   ```
2. ```
   修补 CMake 模块文件（例如 /usr/share/cmake-3.28/Modules/FindSomething.cmake），移除架构检查或将你的架构添加到 #ifndef 列表中。
   ```

## 无效尝试

- **Set CMAKE_CXX_FLAGS to -march=native or -march=armv8-a** — The error is in the test source itself, not in the flags. Changing march doesn't remove the #error directive. (60% 失败率)
- **Delete CMakeCache.txt and reconfigure** — The cache is not the problem; the test source is hardcoded in the Find module or CMake module. (50% 失败率)
