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
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| CMake 3.10 | active | — | — | — |
| CMake 3.18 | active | — | — | — |
| CPack 3.20 | active | — | — | — |
Root Cause
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.
generic中文
当使用带有组件的 CPack 时,每个组件的版本必须与项目版本匹配;当跨组件不一致地设置 CPACK_COMPONENT_<compName>_VERSION 时会发生不匹配。
Official Documentation
https://cmake.org/cmake/help/latest/module/CPackComponent.htmlWorkarounds
-
90% success Set all component versions to the same value, e.g., `set(CPACK_COMPONENT_RUNTIME_VERSION "2.0.0")` and `set(CPACK_COMPONENT_HEADERS_VERSION "2.0.0")` to match the project version.
Set all component versions to the same value, e.g., `set(CPACK_COMPONENT_RUNTIME_VERSION "2.0.0")` and `set(CPACK_COMPONENT_HEADERS_VERSION "2.0.0")` to match the project version.
-
85% success Remove explicit version settings for components and rely on the project version by not setting any CPACK_COMPONENT_*_VERSION variables.
Remove explicit version settings for components and rely on the project version by not setting any CPACK_COMPONENT_*_VERSION variables.
-
80% success Use `set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE ON)` to combine all components into a single package, bypassing version checks.
Use `set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE ON)` to combine all components into a single package, bypassing version checks.
中文步骤
将所有组件版本设置为相同值,例如 `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)` 将所有组件合并到一个包中,绕过版本检查。
Dead Ends
Common approaches that don't work:
-
Deleting all CPACK_COMPONENT_*_VERSION variables
70% fail
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% fail
Setting a global CPACK_PACKAGE_VERSION may not override component-specific versions, leading to persistent mismatches.
-
Disabling component grouping in CPack
75% fail
Using CPack without components (GROUPING IGNORE) may suppress the error but creates a monolithic package that defeats the purpose of component-based installation.