summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2020-09-24 11:28:52 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-09-24 11:29:03 (GMT)
commitac5195c408a713c9c31388ef9b3c0e6f5173b2da (patch)
tree0bc6f2e902b775bbcfaacc83c3a82c77c69e983b /Modules
parentd18c564210dd20692536b4988afc8356c5926694 (diff)
parent5b3356263cf8f00c79c25aa9e3ac71ffd8cc7e7e (diff)
downloadCMake-ac5195c408a713c9c31388ef9b3c0e6f5173b2da.zip
CMake-ac5195c408a713c9c31388ef9b3c0e6f5173b2da.tar.gz
CMake-ac5195c408a713c9c31388ef9b3c0e6f5173b2da.tar.bz2
Merge topic 'find_package-version-range'
5b3356263c CMakePackageConfigHelpers: Add version range support 6bfc442fde FPHSA: add support of version range d7df81067b find_package: Add support of version range 09095dbcd2 cmFindPackageCommand: Refactoring Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Michael Hirsch, Ph.D. <michael@scivision.dev> Merge-request: !5226
Diffstat (limited to 'Modules')
-rw-r--r--Modules/BasicConfigVersion-AnyNewerVersion.cmake.in21
-rw-r--r--Modules/BasicConfigVersion-ExactVersion.cmake.in7
-rw-r--r--Modules/BasicConfigVersion-SameMajorVersion.cmake.in7
-rw-r--r--Modules/BasicConfigVersion-SameMinorVersion.cmake.in7
-rw-r--r--Modules/CMakePackageConfigHelpers.cmake5
-rw-r--r--Modules/FindPackageHandleStandardArgs.cmake242
6 files changed, 226 insertions, 63 deletions
diff --git a/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in b/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in
index a6e5fda..46b8b2a 100644
--- a/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in
+++ b/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in
@@ -9,12 +9,23 @@
set(PACKAGE_VERSION "@CVF_VERSION@")
-if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
- set(PACKAGE_VERSION_COMPATIBLE FALSE)
+if (PACKAGE_FIND_VERSION_RANGE)
+ # Package version must be in the requested version range
+ if ((PACKAGE_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MIN)
+ OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_GREATER PACKAGE_FIND_VERSION_MAX)
+ OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION_MAX)))
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ else()
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ endif()
else()
- set(PACKAGE_VERSION_COMPATIBLE TRUE)
- if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
- set(PACKAGE_VERSION_EXACT TRUE)
+ if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ else()
+ set(PACKAGE_VERSION_COMPATIBLE TRUE)
+ if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
+ set(PACKAGE_VERSION_EXACT TRUE)
+ endif()
endif()
endif()
diff --git a/Modules/BasicConfigVersion-ExactVersion.cmake.in b/Modules/BasicConfigVersion-ExactVersion.cmake.in
index 43fc4d0..3507a22 100644
--- a/Modules/BasicConfigVersion-ExactVersion.cmake.in
+++ b/Modules/BasicConfigVersion-ExactVersion.cmake.in
@@ -9,6 +9,13 @@
# 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 "
+ "(ExactVersion) 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("@CVF_VERSION@" MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)\\.") # strip the tweak version
diff --git a/Modules/BasicConfigVersion-SameMajorVersion.cmake.in b/Modules/BasicConfigVersion-SameMajorVersion.cmake.in
index 8c3b6a2..662900d 100644
--- a/Modules/BasicConfigVersion-SameMajorVersion.cmake.in
+++ b/Modules/BasicConfigVersion-SameMajorVersion.cmake.in
@@ -9,6 +9,13 @@
# 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)
diff --git a/Modules/BasicConfigVersion-SameMinorVersion.cmake.in b/Modules/BasicConfigVersion-SameMinorVersion.cmake.in
index e2030d2..bddf4ce 100644
--- a/Modules/BasicConfigVersion-SameMinorVersion.cmake.in
+++ b/Modules/BasicConfigVersion-SameMinorVersion.cmake.in
@@ -10,6 +10,13 @@
# 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)
diff --git a/Modules/CMakePackageConfigHelpers.cmake b/Modules/CMakePackageConfigHelpers.cmake
index 22fc953..50d7605 100644
--- a/Modules/CMakePackageConfigHelpers.cmake
+++ b/Modules/CMakePackageConfigHelpers.cmake
@@ -159,6 +159,11 @@ If your project has more elaborated version matching rules, you will need to
write your own custom ``ConfigVersion.cmake`` file instead of using this
macro.
+.. note:: ``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 range and will display an
+ author warning if a one is specified.
+
If ``ARCH_INDEPENDENT`` is given, the installed package version will be
considered compatible even if it was built for a different architecture than
the requested architecture. Otherwise, an architecture check will be performed,
diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake
index 4fb0825..4d252bc 100644
--- a/Modules/FindPackageHandleStandardArgs.cmake
+++ b/Modules/FindPackageHandleStandardArgs.cmake
@@ -5,16 +5,19 @@
FindPackageHandleStandardArgs
-----------------------------
-This module provides a function intended to be used in :ref:`Find Modules`
-implementing :command:`find_package(<PackageName>)` calls. It handles the
-``REQUIRED``, ``QUIET`` and version-related arguments of ``find_package``.
-It also sets the ``<PackageName>_FOUND`` variable. The package is
-considered found if all variables listed contain valid results, e.g.
-valid filepaths.
+This module provides functions intended to be used in :ref:`Find Modules`
+implementing :command:`find_package(<PackageName>)` calls.
.. command:: find_package_handle_standard_args
- There are two signatures::
+ This command handles the ``REQUIRED``, ``QUIET`` and version-related
+ arguments of :command:`find_package`. It also sets the
+ ``<PackageName>_FOUND`` variable. The package is considered found if all
+ variables listed contain valid results, e.g. valid filepaths.
+
+ There are two signatures:
+
+ .. code-block:: cmake
find_package_handle_standard_args(<PackageName>
(DEFAULT_MSG|<custom-failure-message>)
@@ -25,6 +28,7 @@ valid filepaths.
[FOUND_VAR <result-var>]
[REQUIRED_VARS <required-var>...]
[VERSION_VAR <version-var>]
+ [HANDLE_VERSION_RANGE]
[HANDLE_COMPONENTS]
[CONFIG_MODE]
[NAME_MISMATCHED]
@@ -69,6 +73,11 @@ valid filepaths.
version and the version which has been actually found, both
if the version is ok or not.
+ ``HANDLE_VERSION_RANGE``
+ Enable handling of a version range, if one is specified. Without this
+ option, a developer warning will be displayed if a version range is
+ specified.
+
``HANDLE_COMPONENTS``
Enable handling of package components. In this case, the command
will report which components have been found and which are missing,
@@ -151,10 +160,54 @@ In this case, a ``FindAutmoc4.cmake`` module wraps a call to
directory for ``automoc4``. Then the call to
``find_package_handle_standard_args`` produces a proper success/failure
message.
+
+.. command:: find_package_check_version
+
+ Helper function which can be used to check if a ``<version>`` is valid
+ against version-related arguments of :command:`find_package`.
+
+ .. code-block:: cmake
+
+ find_package_check_version(<version> <result-var>
+ [HANDLE_VERSION_RANGE]
+ [RESULT_MESSAGE_VARIABLE <message-var>]
+ )
+
+ The ``<result-var>`` will hold a boolean value giving the result of the check.
+
+ The options are:
+
+ ``HANDLE_VERSION_RANGE``
+ Enable handling of a version range, if one is specified. Without this
+ option, a developer warning will be displayed if a version range is
+ specified.
+
+ ``RESULT_MESSAGE_VARIABLE <message-var>``
+ Specify a variable to get back a message describing the result of the check.
+
+Example for the usage:
+
+.. code-block:: cmake
+
+ find_package_check_version(1.2.3 result HANDLE_VERSION_RANGE
+ RESULT_MESSAGE_VARIABLE reason)
+ if (result)
+ message (STATUS "${reason}")
+ else()
+ message (FATAL_ERROR "${reason}")
+ endif()
#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake)
+
+cmake_policy(PUSH)
+# numbers and boolean constants
+cmake_policy (SET CMP0012 NEW)
+# IN_LIST operator
+cmake_policy (SET CMP0057 NEW)
+
+
# internal helper macro
macro(_FPHSA_FAILURE_MESSAGE _msg)
set (__msg "${_msg}")
@@ -207,10 +260,112 @@ macro(_FPHSA_HANDLE_FAILURE_CONFIG_MODE)
endmacro()
+function(FIND_PACKAGE_CHECK_VERSION version result)
+ cmake_parse_arguments (PARSE_ARGV 2 FPCV "HANDLE_VERSION_RANGE;NO_AUTHOR_WARNING_VERSION_RANGE" "RESULT_MESSAGE_VARIABLE" "")
+
+ if (FPCV_UNPARSED_ARGUMENTS)
+ message (FATAL_ERROR "find_package_check_version(): ${FPCV_UNPARSED_ARGUMENTS}: unexpected arguments")
+ endif()
+ if ("RESULT_MESSAGE_VARIABLE" IN_LIST FPCV_KEYWORDS_MISSING_VALUES)
+ message (FATAL_ERROR "find_package_check_version(): RESULT_MESSAGE_VARIABLE expects an argument")
+ endif()
+
+ set (${result} FALSE PARENT_SCOPE)
+ if (FPCV_RESULT_MESSAGE_VARIABLE)
+ unset (${FPCV_RESULT_MESSAGE_VARIABLE} PARENT_SCOPE)
+ endif()
+
+ if (CMAKE_FIND_PACKAGE_NAME)
+ set (package ${CMAKE_FIND_PACKAGE_NAME})
+ else()
+ message (FATAL_ERROR "find_package_check_version(): Cannot be used outside a 'Find Module'")
+ endif()
+
+ if (NOT FPCV_NO_AUTHOR_WARNING_VERSION_RANGE
+ AND ${package}_FIND_VERSION_RANGE AND NOT FPCV_HANDLE_VERSION_RANGE)
+ message(AUTHOR_WARNING
+ "`find_package()` specify a version range but the option "
+ "HANDLE_VERSION_RANGE` is not passed to `find_package_check_version()`. "
+ "Only the lower endpoint of the range will be used.")
+ endif()
+
+
+ set (version_ok FALSE)
+ unset (version_msg)
+
+ if (FPCV_HANDLE_VERSION_RANGE AND ${package}_FIND_VERSION_RANGE)
+ if (${package}_FIND_VERSION_MIN VERSION_GREATER ${package}_FIND_VERSION_MAX
+ OR (${package}_FIND_VERSION_MIN VERSION_EQUAL ${package}_FIND_VERSION_MAX
+ AND ${package}_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE"))
+ set (version_msg "Found unsuitable version \"${version}\", required range is empty (\"${${package}_FIND_VERSION_RANGE}\")")
+ elseif ((${package}_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE"
+ AND version VERSION_GREATER_EQUAL ${package}_FIND_VERSION_MIN)
+ AND ((${package}_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE"
+ AND version VERSION_LESS_EQUAL ${package}_FIND_VERSION_MAX)
+ OR (${package}_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE"
+ AND version VERSION_LESS ${package}_FIND_VERSION_MAX)))
+ set (version_ok TRUE)
+ set(version_msg "(found suitable version \"${version}\", required range is \"${${package}_FIND_VERSION_RANGE}\")")
+ else()
+ set(version_msg "Found unsuitable version \"${version}\", required range is \"${${package}_FIND_VERSION_RANGE}\"")
+ endif()
+ elseif (DEFINED ${package}_FIND_VERSION)
+ if(${package}_FIND_VERSION_EXACT) # exact version required
+ # count the dots in the version string
+ string(REGEX REPLACE "[^.]" "" version_dots "${version}")
+ # add one dot because there is one dot more than there are components
+ string(LENGTH "${version_dots}." version_dots)
+ if (version_dots GREATER ${package}_FIND_VERSION_COUNT)
+ # Because of the C++ implementation of find_package() ${package}_FIND_VERSION_COUNT
+ # is at most 4 here. Therefore a simple lookup table is used.
+ if (${package}_FIND_VERSION_COUNT EQUAL 1)
+ set(version_regex "[^.]*")
+ elseif (${package}_FIND_VERSION_COUNT EQUAL 2)
+ set(version_regex "[^.]*\\.[^.]*")
+ elseif (${package}_FIND_VERSION_COUNT EQUAL 3)
+ set(version_regex "[^.]*\\.[^.]*\\.[^.]*")
+ else()
+ set(version_regex "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*")
+ endif()
+ string(REGEX REPLACE "^(${version_regex})\\..*" "\\1" version_head "${version}")
+ if (NOT ${package}_FIND_VERSION VERSION_EQUAL version_head)
+ set(version_msg "Found unsuitable version \"${version}\", but required is exact version \"${${package}_FIND_VERSION}\"")
+ else ()
+ set(version_ok TRUE)
+ set(version_msg "(found suitable exact version \"${_FOUND_VERSION}\")")
+ endif ()
+ else ()
+ if (NOT ${package}_FIND_VERSION VERSION_EQUAL version)
+ set(version_msg "Found unsuitable version \"${version}\", but required is exact version \"${${package}_FIND_VERSION}\"")
+ else ()
+ set(version_ok TRUE)
+ set(version_msg "(found suitable exact version \"${version}\")")
+ endif ()
+ endif ()
+ else() # minimum version
+ if (${package}_FIND_VERSION VERSION_GREATER version)
+ set(version_msg "Found unsuitable version \"${version}\", but required is at least \"${${package}_FIND_VERSION}\"")
+ else()
+ set(version_ok TRUE)
+ set(version_msg "(found suitable version \"${version}\", minimum required is \"${${package}_FIND_VERSION}\")")
+ endif()
+ endif()
+ else ()
+ set(version_ok TRUE)
+ set(version_msg "(found version \"${version}\")")
+ endif()
+
+ set (${result} ${version_ok} PARENT_SCOPE)
+ if (FPCV_RESULT_MESSAGE_VARIABLE)
+ set (${FPCV_RESULT_MESSAGE_VARIABLE} "${version_msg}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+
function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
# Set up the arguments for `cmake_parse_arguments`.
- set(options CONFIG_MODE HANDLE_COMPONENTS NAME_MISMATCHED)
+ set(options CONFIG_MODE HANDLE_COMPONENTS NAME_MISMATCHED HANDLE_VERSION_RANGE)
set(oneValueArgs FAIL_MESSAGE REASON_FAILURE_MESSAGE VERSION_VAR FOUND_VAR)
set(multiValueArgs REQUIRED_VARS)
@@ -278,7 +433,14 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
"to follow a certain pattern.")
endif ()
-# now that we collected all arguments, process them
+ if (${_NAME}_FIND_VERSION_RANGE AND NOT FPHSA_HANDLE_VERSION_RANGE)
+ message(AUTHOR_WARNING
+ "`find_package()` specify a version range but the module ${_NAME} does "
+ "not support this capability. Only the lower endpoint of the range "
+ "will be used.")
+ endif()
+
+ # now that we collected all arguments, process them
if("x${FPHSA_FAIL_MESSAGE}" STREQUAL "xDEFAULT_MSG")
set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}")
@@ -364,61 +526,22 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
if (DEFINED ${_NAME}_FIND_VERSION)
if(DEFINED ${FPHSA_VERSION_VAR})
set(_FOUND_VERSION ${${FPHSA_VERSION_VAR}})
-
- if(${_NAME}_FIND_VERSION_EXACT) # exact version required
- # count the dots in the version string
- string(REGEX REPLACE "[^.]" "" _VERSION_DOTS "${_FOUND_VERSION}")
- # add one dot because there is one dot more than there are components
- string(LENGTH "${_VERSION_DOTS}." _VERSION_DOTS)
- if (_VERSION_DOTS GREATER ${_NAME}_FIND_VERSION_COUNT)
- # Because of the C++ implementation of find_package() ${_NAME}_FIND_VERSION_COUNT
- # is at most 4 here. Therefore a simple lookup table is used.
- if (${_NAME}_FIND_VERSION_COUNT EQUAL 1)
- set(_VERSION_REGEX "[^.]*")
- elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 2)
- set(_VERSION_REGEX "[^.]*\\.[^.]*")
- elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 3)
- set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*")
- else ()
- set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*")
- endif ()
- string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${_FOUND_VERSION}")
- unset(_VERSION_REGEX)
- if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _VERSION_HEAD)
- set(VERSION_MSG "Found unsuitable version \"${_FOUND_VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
- set(VERSION_OK FALSE)
- else ()
- set(VERSION_MSG "(found suitable exact version \"${_FOUND_VERSION}\")")
- endif ()
- unset(_VERSION_HEAD)
- else ()
- if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _FOUND_VERSION)
- set(VERSION_MSG "Found unsuitable version \"${_FOUND_VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
- set(VERSION_OK FALSE)
- else ()
- set(VERSION_MSG "(found suitable exact version \"${_FOUND_VERSION}\")")
- endif ()
- endif ()
- unset(_VERSION_DOTS)
-
- else() # minimum version specified:
- if (${_NAME}_FIND_VERSION VERSION_GREATER _FOUND_VERSION)
- set(VERSION_MSG "Found unsuitable version \"${_FOUND_VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"")
- set(VERSION_OK FALSE)
- else ()
- set(VERSION_MSG "(found suitable version \"${_FOUND_VERSION}\", minimum required is \"${${_NAME}_FIND_VERSION}\")")
- endif ()
+ if (FPHSA_HANDLE_VERSION_RANGE)
+ set (FPCV_HANDLE_VERSION_RANGE HANDLE_VERSION_RANGE)
+ else()
+ set(FPCV_HANDLE_VERSION_RANGE NO_AUTHOR_WARNING_VERSION_RANGE)
endif()
-
+ find_package_check_version (${_FOUND_VERSION} VERSION_OK RESULT_MESSAGE_VARIABLE VERSION_MSG
+ ${FPCV_HANDLE_VERSION_RANGE})
else()
-
# if the package was not found, but a version was given, add that to the output:
if(${_NAME}_FIND_VERSION_EXACT)
- set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")")
+ set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")")
+ elseif (FPHSA_HANDLE_VERSION_RANGE AND ${_NAME}_FIND_VERSION_RANGE)
+ set(VERSION_MSG "(Required is version range \"${${_NAME}_FIND_VERSION_RANGE}\")")
else()
- set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")")
+ set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")")
endif()
-
endif()
else ()
# Check with DEFINED as the found version may be 0.
@@ -464,3 +587,6 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
set(${_NAME}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE)
set(${_NAME_UPPER}_FOUND ${${_NAME}_FOUND} PARENT_SCOPE)
endfunction()
+
+
+cmake_policy(POP)