cmake install_error ai_generated true

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

Also available as: JSON · Markdown · 中文
85%Fix Rate
81%Confidence
1Evidence
2024-05-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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.html

Workarounds

  1. 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.
  2. 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.
  3. 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.

中文步骤

  1. 将所有组件版本设置为相同值,例如 `set(CPACK_COMPONENT_RUNTIME_VERSION "2.0.0")` 和 `set(CPACK_COMPONENT_HEADERS_VERSION "2.0.0")` 以匹配项目版本。
  2. 移除组件的显式版本设置,通过不设置任何 CPACK_COMPONENT_*_VERSION 变量来依赖项目版本。
  3. 使用 `set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE ON)` 将所有组件合并到一个包中,绕过版本检查。

Dead Ends

Common approaches that don't work:

  1. 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.

  2. 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.

  3. 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.