# CMake 错误：目标 "mytarget" 的 CUDA_ARCHITECTURES 为空。

- **ID:** `cmake/missing-cuda-architectures`
- **领域:** cmake
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 93%

## 根因

CMake 3.18+ 要求为使用 CUDA 的目标显式指定 CUDA 架构；如果未设置，则默认为空，导致构建失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.18 | active | — | — |
| 3.20 | active | — | — |
| 3.22 | active | — | — |
| 3.28 | active | — | — |

## 解决方案

1. ```
   设置有效的 CUDA 架构，例如 `set_target_properties(mytarget PROPERTIES CUDA_ARCHITECTURES "75")` 用于 Turing GPU。
   ```
2. ```
   设置全局架构：在定义目标之前 `set(CMAKE_CUDA_ARCHITECTURES "75;86")`。
   ```

## 无效尝试

- **Set CMAKE_CUDA_ARCHITECTURES to empty string to bypass the check.** — CMake policy CMP0104 enforces non-empty architectures; empty string still triggers the error. (90% 失败率)
- **Add `set(CMAKE_CUDA_ARCHITECTURES OFF)` to CMakeLists.txt.** — OFF is not a valid architecture; CMake interprets it as empty and fails. (80% 失败率)
