summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2020-12-14 13:55:05 (GMT)
committerCraig Scott <craig.scott@crascit.com>2020-12-14 22:24:09 (GMT)
commit55c3b6a77e700554e6303f5cd6c4e443499363d8 (patch)
tree863c579ad420c3f7849ac7e8e46211d1dfcaadae /Modules
parent82b25be80afc92da045d04a37e121a3fa97392c0 (diff)
downloadCMake-55c3b6a77e700554e6303f5cd6c4e443499363d8.zip
CMake-55c3b6a77e700554e6303f5cd6c4e443499363d8.tar.gz
CMake-55c3b6a77e700554e6303f5cd6c4e443499363d8.tar.bz2
CMakePackageConfigHelpers: Relax restrictions on version range
Diffstat (limited to 'Modules')
-rw-r--r--Modules/BasicConfigVersion-SameMajorVersion.cmake.in33
-rw-r--r--Modules/BasicConfigVersion-SameMinorVersion.cmake.in40
-rw-r--r--Modules/CMakePackageConfigHelpers.cmake7
3 files changed, 52 insertions, 28 deletions
diff --git a/Modules/BasicConfigVersion-SameMajorVersion.cmake.in b/Modules/BasicConfigVersion-SameMajorVersion.cmake.in
index 662900d..dc04e54 100644
--- a/Modules/BasicConfigVersion-SameMajorVersion.cmake.in
+++ b/Modules/BasicConfigVersion-SameMajorVersion.cmake.in
@@ -9,13 +9,6 @@
# The variable CVF_VERSION must be set before calling configure_file().
-if (PACKAGE_FIND_VERSION_RANGE)
- message(AUTHOR_WARNING
- "`find_package()` specify a version range but the version strategy "
- "(SameMajorVersion) of the module `${PACKAGE_FIND_NAME}` is incompatible "
- "with this request. Only the lower endpoint of the range will be used.")
-endif()
-
set(PACKAGE_VERSION "@CVF_VERSION@")
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
@@ -28,14 +21,30 @@ else()
set(CVF_VERSION_MAJOR "@CVF_VERSION@")
endif()
- if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR)
- set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if(PACKAGE_FIND_VERSION_RANGE)
+ # both endpoints of the range must have the expected major version
+ math (EXPR CVF_VERSION_MAJOR_NEXT "${CVF_VERSION_MAJOR} + 1")
+ if (NOT PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR
+ OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX_MAJOR STREQUAL CVF_VERSION_MAJOR)
+ OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX VERSION_LESS_EQUAL CVF_VERSION_MAJOR_NEXT)))
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ elseif(PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR
+ AND ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS_EQUAL PACKAGE_FIND_VERSION_MAX)
+ OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MAX)))
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ else()
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ endif()
else()
- set(PACKAGE_VERSION_COMPATIBLE FALSE)
- endif()
+ if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR)
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ else()
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ endif()
- if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
+ if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
endif()
endif()
diff --git a/Modules/BasicConfigVersion-SameMinorVersion.cmake.in b/Modules/BasicConfigVersion-SameMinorVersion.cmake.in
index bddf4ce..9bb2efc 100644
--- a/Modules/BasicConfigVersion-SameMinorVersion.cmake.in
+++ b/Modules/BasicConfigVersion-SameMinorVersion.cmake.in
@@ -10,13 +10,6 @@
# The variable CVF_VERSION must be set before calling configure_file().
-if (PACKAGE_FIND_VERSION_RANGE)
- message(AUTHOR_WARNING
- "`find_package()` specify a version range but the version strategy "
- "(SameMinorVersion) of the module `${PACKAGE_FIND_NAME}` is incompatible "
- "with this request. Only the lower endpoint of the range will be used.")
-endif()
-
set(PACKAGE_VERSION "@CVF_VERSION@")
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
@@ -31,15 +24,36 @@ else()
set(CVF_VERSION_MINOR "")
endif()
- if((PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR) AND
- (PACKAGE_FIND_VERSION_MINOR STREQUAL CVF_VERSION_MINOR))
- set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if(PACKAGE_FIND_VERSION_RANGE)
+ # both endpoints of the range must have the expected major and minor versions
+ math (EXPR CVF_VERSION_MINOR_NEXT "${CVF_VERSION_MINOR} + 1")
+ if (NOT (PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR
+ AND PACKAGE_FIND_VERSION_MIN_MINOR STREQUAL CVF_VERSION_MINOR)
+ OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE"
+ AND NOT (PACKAGE_FIND_VERSION_MAX_MAJOR STREQUAL CVF_VERSION_MAJOR
+ AND PACKAGE_FIND_VERSION_MAX_MINOR STREQUAL CVF_VERSION_MINOR))
+ OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE"
+ AND NOT PACKAGE_FIND_VERSION_MAX VERSION_LESS_EQUAL ${CVF_VERSION_MAJOR}.${CVF_VERSION_MINOR_NEXT})))
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ elseif(PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR
+ AND PACKAGE_FIND_VERSION_MIN_MINOR STREQUAL CVF_VERSION_MINOR
+ AND ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS_EQUAL PACKAGE_FIND_VERSION_MAX)
+ OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MAX)))
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ else()
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ endif()
else()
- set(PACKAGE_VERSION_COMPATIBLE FALSE)
- endif()
+ 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)
+ if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
endif()
endif()
diff --git a/Modules/CMakePackageConfigHelpers.cmake b/Modules/CMakePackageConfigHelpers.cmake
index 372e9f4..ad719ef 100644
--- a/Modules/CMakePackageConfigHelpers.cmake
+++ b/Modules/CMakePackageConfigHelpers.cmake
@@ -177,9 +177,10 @@ macro.
packages with no binaries.
.. versionadded:: 3.19
- ``COMPATIBILITY_MODE`` ``AnyNewerVersion`` handles the version range
- if any is specified (see :command:`find_package` command for the details).
- All other modes are incompatible with version ranges and will display an
+ ``COMPATIBILITY_MODE`` ``AnyNewerVersion``, ``SameMajorVersion`` and
+ ``SameMinorVersion`` handle the version range if any is specified
+ (see :command:`find_package` command for the details).
+ ``ExactVersion`` mode is incompatible with version ranges and will display an
author warning if one is specified.
Internally, this macro executes :command:`configure_file()` to create the