# CMake 错误：install TARGETS 未指定 DESTINATION，也未指定 RUNTIME、ARCHIVE、LIBRARY 或 BUNDLE 组件。

- **ID:** `cmake/install-target-destination-not-set`
- **领域:** cmake
- **类别:** install_error
- **验证级别:** ai_generated
- **修复率:** 93%

## 根因

install(TARGETS) 命令必须为每种目标类型指定目标路径或组件；否则 CMake 不知道将安装文件放在哪里。

## 版本兼容性

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

## 解决方案

1. ```
   为每种目标类型添加 DESTINATION：install(TARGETS mylib RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib/static)。示例：install(TARGETS myapp RUNTIME DESTINATION bin)。
   ```
2. ```
   为所有组件使用单一 DESTINATION：install(TARGETS mylib DESTINATION lib)。这适用于不分离运行时/存档的简单库。
   ```

## 无效尝试

- **** — If a target produces both a runtime and a library, both must have destinations; specifying only one leaves the other undefined. (80% 失败率)
- **** — CMAKE_INSTALL_PREFIX sets the root, but install(TARGETS) needs explicit DESTINATION relative to that root. (95% 失败率)
