Skip to content

Error out on Major-Version Conflicts #674

@josephbirkner

Description

@josephbirkner

Currently, the only version conflict that is detected/logged by CPM is when a package with a lower version has been added before a package with a higher version. This is inconvenient, as a major-version conflict will most certainly lead to compile errors down the line, and need to be manually traced back to the version issue. Something that could very easily be added to cpm_check_if_package_already_added . E.g.

# checks if a package has been added before
function(cpm_check_if_package_already_added CPM_ARGS_NAME CPM_ARGS_VERSION)
  if("${CPM_ARGS_NAME}" IN_LIST CPM_PACKAGES)
    CPMGetPackageVersion(${CPM_ARGS_NAME} CPM_PACKAGE_VERSION)

    # Major version (first number) mismatch check
    string(REGEX MATCH "^[0-9]+" _cpm_exist_major "${CPM_PACKAGE_VERSION}")
    string(REGEX MATCH "^[0-9]+" _cpm_req_major   "${CPM_ARGS_VERSION}")

    if(_cpm_exist_major AND _cpm_req_major AND
       NOT _cpm_exist_major STREQUAL _cpm_req_major)
      message(
        FATAL_ERROR
          "${CPM_INDENT} Major version of ${CPM_ARGS_NAME} differs: "
          "requested ${CPM_ARGS_VERSION} (major ${_cpm_req_major}) "
          "but already included ${CPM_PACKAGE_VERSION} (major ${_cpm_exist_major})."
      )
    endif()

    # Warn if same major, but required version is newer
    cpm_get_fetch_properties(${CPM_ARGS_NAME})
    set(${CPM_ARGS_NAME}_ADDED NO)
    set(CPM_PACKAGE_ALREADY_ADDED
        YES
        PARENT_SCOPE
    )
    cpm_export_variables(${CPM_ARGS_NAME})
  else()
    set(CPM_PACKAGE_ALREADY_ADDED
        NO
        PARENT_SCOPE
    )
  endif()
endfunction()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions