CMake 错误:CPack 组件 "runtime" 的版本为 1.0.0,但组件 "headers" 的版本为 2.0.0。所有组件必须具有相同的版本。
CMake Error: CPack component "runtime" has version 1.0.0 but component "headers" has version 2.0.0. All components must have the same version.
ID: cmake/cpack-component-version-mismatch
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| CMake 3.10 | active | — | — | — |
| CMake 3.18 | active | — | — | — |
| CPack 3.20 | active | — | — | — |
根因分析
当使用带有组件的 CPack 时,每个组件的版本必须与项目版本匹配;当跨组件不一致地设置 CPACK_COMPONENT_<compName>_VERSION 时会发生不匹配。
English
When using CPack with components, each component's version must match the project version; a mismatch occurs when CPACK_COMPONENT_<compName>_VERSION is set inconsistently across components.
官方文档
https://cmake.org/cmake/help/latest/module/CPackComponent.html解决方案
-
将所有组件版本设置为相同值,例如 `set(CPACK_COMPONENT_RUNTIME_VERSION "2.0.0")` 和 `set(CPACK_COMPONENT_HEADERS_VERSION "2.0.0")` 以匹配项目版本。
-
移除组件的显式版本设置,通过不设置任何 CPACK_COMPONENT_*_VERSION 变量来依赖项目版本。
-
使用 `set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE ON)` 将所有组件合并到一个包中,绕过版本检查。
无效尝试
常见但无效的做法:
-
Deleting all CPACK_COMPONENT_*_VERSION variables
70% 失败
Removing version specifications from all components may default to the project version, but CPack may still fail if any component has an explicit version set elsewhere.
-
Setting only CPACK_PACKAGE_VERSION without adjusting component versions
80% 失败
Setting a global CPACK_PACKAGE_VERSION may not override component-specific versions, leading to persistent mismatches.
-
Disabling component grouping in CPack
75% 失败
Using CPack without components (GROUPING IGNORE) may suppress the error but creates a monolithic package that defeats the purpose of component-based installation.