Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,806
    • Issues 3,806
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 10
    • Merge requests 10
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #22207

Closed
Open
Created May 18, 2021 by Robert Maynard@robertmaynardDeveloper

write_basic_package_version_file fails to handle patch version properly

Presuming the following project example:

project(test LANGUAGES CXX VERSION 2021.05.00)
...
write_basic_package_version_file("${CMAKE_BUILD_IDR}/test-config-version.cmake"
                                 COMPATIBILITY SameMinorVersion)

And the following find_package call:

find_package(test 2021.05)

You would expect that the test-config-version.cmake generated file would correctly match to 2021.05 as it has the same Major and Minor versions. But write_basic_package_version_file encodes the minor version as 05.00 instead of 05 and therefore can't match as the generated file uses exact matching logic.

To demonstrate here is an example test-config-version.cmake and you can see that it doesn't properly determine that a patch version exists on PACKAGE_VERSION and therefore generates a bad regex.

set(PACKAGE_VERSION "2021.05.00")

if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
  set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()

  if("2021.05.00" MATCHES "^([0-9]+)\\.([0-9]+)")
    set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
    set(CVF_VERSION_MINOR "${CMAKE_MATCH_2}")
  else()
    set(CVF_VERSION_MAJOR "2021.05.00")
    set(CVF_VERSION_MINOR "")
  endif()

  if(PACKAGE_FIND_VERSION_RANGE)
    ..trimmed
  else()
    if((PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR) AND
        (PACKAGE_FIND_VERSION_MINOR STREQUAL CVF_VERSION_MINOR))
      set(PACKAGE_VERSION_COMPATIBLE TRUE)
    else()
      set(PACKAGE_VERSION_COMPATIBLE FALSE)
    endif()

    if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
      set(PACKAGE_VERSION_EXACT TRUE)
    endif()
  endif()
endif()


Tested with CMake 3.20.2
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking