# CMake 错误：CPack DMG：代码签名失败，错误代码为 1

- **ID:** `cmake/cpack-dmg-signing-failure`
- **领域:** cmake
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

CPack DMG 生成器尝试对磁盘映像进行签名，但签名身份或授权缺失或无效。

## 版本兼容性

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

## 解决方案

1. ```
   在 CMakeLists.txt 中，在包含 CPack 之前设置 CPACK_DMG_SKIP_CODESIGN 为 TRUE：

set(CPACK_DMG_SKIP_CODESIGN TRUE)
include(CPack)
   ```
2. ```
   通过运行以下命令确保存在有效的签名身份：

security find-identity -v -p basic

然后将 CPACK_DMG_SIGNING_IDENTITY 设置为匹配的身份字符串：

set(CPACK_DMG_SIGNING_IDENTITY "Developer ID Application: Your Name (TEAMID)")
   ```

## 无效尝试

- **Reinstall Xcode Command Line Tools** — Xcode tools are usually not the issue; the problem is a missing or expired signing certificate, not the tools themselves. (80% 失败率)
- **Set CPACK_DMG_DS_STORE to an empty path** — This only changes the DS_Store file location, not the signing process; signing still fails. (90% 失败率)
