From 16a93de0a81e913d71f86835b267516ea4875517 Mon Sep 17 00:00:00 2001 From: "Daniele E. Domenichelli" Date: Mon, 20 Nov 2017 11:09:58 +0100 Subject: WriteBasicConfigVersionFile: Add SameMinorVersion COMPATIBILITY option --- .../BasicConfigVersion-SameMinorVersion.cmake.in | 50 ++++++++++++++++++++++ Modules/CMakePackageConfigHelpers.cmake | 12 +++--- Modules/WriteBasicConfigVersionFile.cmake | 2 +- 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 Modules/BasicConfigVersion-SameMinorVersion.cmake.in (limited to 'Modules') diff --git a/Modules/BasicConfigVersion-SameMinorVersion.cmake.in b/Modules/BasicConfigVersion-SameMinorVersion.cmake.in new file mode 100644 index 0000000000..59ca253767 --- /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 f5a8e59dba..e37f34f6fe 100644 --- a/Modules/CMakePackageConfigHelpers.cmake +++ b/Modules/CMakePackageConfigHelpers.cmake @@ -122,7 +122,7 @@ # # write_basic_package_version_file( # [VERSION ] -# COMPATIBILITY ) +# COMPATIBILITY ) # # # Writes a file for use as ``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-.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 7c9467ab36..2f7c80ab81 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) # ) # # -- cgit v1.2.1