diff options
-rw-r--r-- | Help/release/dev/WriteBasicConfigVersionFile_SameMinorVersion.rst | 5 | ||||
-rw-r--r-- | Modules/BasicConfigVersion-SameMinorVersion.cmake.in | 50 | ||||
-rw-r--r-- | Modules/CMakePackageConfigHelpers.cmake | 12 | ||||
-rw-r--r-- | Modules/WriteBasicConfigVersionFile.cmake | 2 | ||||
-rw-r--r-- | Tests/FindPackageTest/CMakeLists.txt | 79 |
5 files changed, 141 insertions, 7 deletions
diff --git a/Help/release/dev/WriteBasicConfigVersionFile_SameMinorVersion.rst b/Help/release/dev/WriteBasicConfigVersionFile_SameMinorVersion.rst new file mode 100644 index 0000000..7f1c4d0 --- /dev/null +++ b/Help/release/dev/WriteBasicConfigVersionFile_SameMinorVersion.rst @@ -0,0 +1,5 @@ +WriteBasicConfigFile_SameMinorVersion +------------------------------------- + +* The :command:`write_basic_package_version_file` understands a new + ``SameMinorVersion`` option for the ``COMPATIBILITY`` argument. diff --git a/Modules/BasicConfigVersion-SameMinorVersion.cmake.in b/Modules/BasicConfigVersion-SameMinorVersion.cmake.in new file mode 100644 index 0000000..59ca253 --- /dev/null +++ b/Modules/BasicConfigVersion-SameMinorVersion.cmake.in @@ -0,0 +1,50 @@ +# This is a basic version file for the Config-mode of find_package(). +# It is used by write_basic_package_version_file() as input file for configure_file() +# to create a version-file which can be installed along a config.cmake file. +# +# The created file sets PACKAGE_VERSION_EXACT if the current version string and +# the requested version string are exactly the same and it sets +# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version, +# but only if the requested major and minor versions are the same as the current +# one. +# The variable CVF_VERSION must be set before calling configure_file(). + + +set(PACKAGE_VERSION "@CVF_VERSION@") + +if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + + if("@CVF_VERSION@" MATCHES "^([0-9]+)\\.([0-9]+)") + set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") + set(CVF_VERSION_MINOR "${CMAKE_MATCH_2}") + else() + set(CVF_VERSION_MAJOR "@CVF_VERSION@") + 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) + else() + set(PACKAGE_VERSION_COMPATIBLE FALSE) + endif() + + if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() + + +# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: +if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@CMAKE_SIZEOF_VOID_P@" STREQUAL "") + return() +endif() + +# check that the installed version has the same 32/64bit-ness as the one which is currently searching: +if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "@CMAKE_SIZEOF_VOID_P@") + math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8") + set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") + set(PACKAGE_VERSION_UNSUITABLE TRUE) +endif() diff --git a/Modules/CMakePackageConfigHelpers.cmake b/Modules/CMakePackageConfigHelpers.cmake index f5a8e59..e37f34f 100644 --- a/Modules/CMakePackageConfigHelpers.cmake +++ b/Modules/CMakePackageConfigHelpers.cmake @@ -122,7 +122,7 @@ # # write_basic_package_version_file(<filename> # [VERSION <major.minor.patch>] -# COMPATIBILITY <AnyNewerVersion|SameMajorVersion|ExactVersion> ) +# COMPATIBILITY <AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion> ) # # # Writes a file for use as ``<package>ConfigVersion.cmake`` file to @@ -144,6 +144,9 @@ # requested, e.g. version 2.0 will not be considered compatible if 1.0 is # requested. This mode should be used for packages which guarantee backward # compatibility within the same major version. +# If ``SameMinorVersion`` is used, the behaviour is the same as +# ``SameMajorVersion``, but both major and minor version must be the same as +# requested, e.g version 0.2 will not be compatible if 0.1 is requested. # If ``ExactVersion`` is used, then the package is only considered compatible if # the requested version matches exactly its own version number (not considering # the tweak version). For example, version 1.2.3 of a package is only @@ -154,10 +157,9 @@ # macro. # # Internally, this macro executes :command:`configure_file()` to create the -# resulting version file. Depending on the ``COMPATIBILITY``, either the file -# ``BasicConfigVersion-SameMajorVersion.cmake.in`` or -# ``BasicConfigVersion-AnyNewerVersion.cmake.in`` is used. Please note that -# these two files are internal to CMake and you should not call +# resulting version file. Depending on the ``COMPATIBILITY``, the corresponding +# ``BasicConfigVersion-<COMPATIBILITY>.cmake.in`` file is used. +# Please note that these files are internal to CMake and you should not call # :command:`configure_file()` on them yourself, but they can be used as starting # point to create more sophisticted custom ``ConfigVersion.cmake`` files. # diff --git a/Modules/WriteBasicConfigVersionFile.cmake b/Modules/WriteBasicConfigVersionFile.cmake index 7c9467a..2f7c80a 100644 --- a/Modules/WriteBasicConfigVersionFile.cmake +++ b/Modules/WriteBasicConfigVersionFile.cmake @@ -11,7 +11,7 @@ # # WRITE_BASIC_CONFIG_VERSION_FILE( filename # [VERSION major.minor.patch] -# COMPATIBILITY (AnyNewerVersion|SameMajorVersion) +# COMPATIBILITY (AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion) # ) # # diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt index 1a6f204..ae3f3a2 100644 --- a/Tests/FindPackageTest/CMakeLists.txt +++ b/Tests/FindPackageTest/CMakeLists.txt @@ -565,6 +565,84 @@ endif() ####################### +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/Zot123ConfigVersion.cmake + VERSION 1.2.3.17 + COMPATIBILITY SameMinorVersion) + +unset(PACKAGE_VERSION_UNSUITABLE) +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_FIND_VERSION 2.3.4) +set(PACKAGE_FIND_VERSION_MAJOR 2) +set(PACKAGE_FIND_VERSION_MINOR 3) +include(${CMAKE_CURRENT_BINARY_DIR}/Zot123ConfigVersion.cmake) +if(PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Found Zot123 with version 1.2.3.17, but 2.3.4 was requested !") +endif() +if(PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !") +endif() + +set(PACKAGE_FIND_VERSION 0.0.1) +set(PACKAGE_FIND_VERSION_MAJOR 0) +set(PACKAGE_FIND_VERSION_MINOR 0) +include(${CMAKE_CURRENT_BINARY_DIR}/Zot123ConfigVersion.cmake) +if(PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Found Zot123 with version 1.2.3.17, but 0.0.1 was requested !") +endif() +if(PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !") +endif() + +set(PACKAGE_FIND_VERSION 1.0.0) +set(PACKAGE_FIND_VERSION_MAJOR 1) +set(PACKAGE_FIND_VERSION_MINOR 0) +include(${CMAKE_CURRENT_BINARY_DIR}/Zot123ConfigVersion.cmake) +if(PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Found Zot123 with version 1.2.3.17 (1.0.0 was requested) !") +endif() +if(PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !") +endif() + +set(PACKAGE_FIND_VERSION 1.2.0) +set(PACKAGE_FIND_VERSION_MAJOR 1) +set(PACKAGE_FIND_VERSION_MINOR 2) +include(${CMAKE_CURRENT_BINARY_DIR}/Zot123ConfigVersion.cmake) +if(NOT PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Did not find Zot123 with version 1.2.3.17 (1.2.0 was requested) !") +endif() +if(PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !") +endif() + +set(PACKAGE_FIND_VERSION 1.2.3) +set(PACKAGE_FIND_VERSION_MAJOR 1) +set(PACKAGE_FIND_VERSION_MINOR 2) +include(${CMAKE_CURRENT_BINARY_DIR}/Zot123ConfigVersion.cmake) +if(NOT PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Did not find Zot123 with version 1.2.3.17 (1.2.3 was requested) !") +endif() +if(PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !") +endif() + +set(PACKAGE_FIND_VERSION 1.2.3.17) +set(PACKAGE_FIND_VERSION_MAJOR 1) +set(PACKAGE_FIND_VERSION_MINOR 2) +include(${CMAKE_CURRENT_BINARY_DIR}/Zot123ConfigVersion.cmake) +if(NOT PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Did not find Zot123 with version 1.2.3.17 (1.2.3.17 was requested) !") +endif() +if(NOT PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT not set, although it should be !") +endif() + +if(PACKAGE_VERSION_UNSUITABLE) + message(SEND_ERROR "PACKAGE_VERSION_UNSUITABLE set, but must not be !") +endif() + +####################### + write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake VERSION 1.2.3.17 COMPATIBILITY ExactVersion) @@ -618,7 +696,6 @@ if(PACKAGE_VERSION_EXACT) message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !") endif() - set(PACKAGE_FIND_VERSION 1.2.3.17) set(PACKAGE_VERSION_EXACT FALSE) set(PACKAGE_VERSION_COMPATIBLE FALSE) |