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