diff options
author | Rolf Eike Beer <eike@sf-mail.de> | 2018-10-02 20:36:29 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-10-04 14:32:13 (GMT) |
commit | aa51bfd74f906b5447b6243aac7e0dec08d5bc6d (patch) | |
tree | b3c30ff37034ce7fb6b613cb303cec44608a4bd5 | |
parent | fd02538974dd952a8639d371c2c0067d30d5469a (diff) | |
download | CMake-aa51bfd74f906b5447b6243aac7e0dec08d5bc6d.zip CMake-aa51bfd74f906b5447b6243aac7e0dec08d5bc6d.tar.gz CMake-aa51bfd74f906b5447b6243aac7e0dec08d5bc6d.tar.bz2 |
FindPkgConfig: support also > and < operators for version compares
Fixes: #18416
-rw-r--r-- | Help/release/3.13.rst | 4 | ||||
-rw-r--r-- | Modules/FindPkgConfig.cmake | 4 | ||||
-rw-r--r-- | Tests/RunCMake/FindPkgConfig/FindPkgConfig_VERSION_OPERATORS.cmake | 83 | ||||
-rw-r--r-- | Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake | 1 |
4 files changed, 91 insertions, 1 deletions
diff --git a/Help/release/3.13.rst b/Help/release/3.13.rst index b08f21d..7cff3df 100644 --- a/Help/release/3.13.rst +++ b/Help/release/3.13.rst @@ -157,6 +157,10 @@ Modules * The :module:`FindPkgConfig` module gained an option to create imported targets in global scope. +* The :module:`FindPkgConfig` module gained support for ``<`` and ``>`` + operators for version checks in addition to the already supported + operators ``>=``, ``<=``, and ``=``. + * Modules :module:`FindPython3`, :module:`FindPython2` and :module:`FindPython` gain capability to control order of resource lookup on macOS (Framework) and Windows (Registry). diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 3934867..a96df99 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -397,7 +397,7 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma set(_pkg_check_modules_exist_query) # check whether version is given - if (_pkg_check_modules_pkg MATCHES "(.*[^><])(>=|=|<=)(.*)") + if (_pkg_check_modules_pkg MATCHES "(.*[^><])(=|[><]=?)(.*)") set(_pkg_check_modules_pkg_name "${CMAKE_MATCH_1}") set(_pkg_check_modules_pkg_op "${CMAKE_MATCH_2}") set(_pkg_check_modules_pkg_ver "${CMAKE_MATCH_3}") @@ -415,9 +415,11 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma list(APPEND _pkg_check_modules_packages "${_pkg_check_modules_pkg_name}") # create the final query which is of the format: + # * <pkg-name> > <version> # * <pkg-name> >= <version> # * <pkg-name> = <version> # * <pkg-name> <= <version> + # * <pkg-name> < <version> # * --exists <pkg-name> list(APPEND _pkg_check_modules_exist_query --print-errors --short-errors) if (_pkg_check_modules_pkg_op) diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_VERSION_OPERATORS.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_VERSION_OPERATORS.cmake new file mode 100644 index 0000000..2a505c6 --- /dev/null +++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_VERSION_OPERATORS.cmake @@ -0,0 +1,83 @@ +cmake_minimum_required(VERSION 3.12) + +project(FindPkgConfig_IMPORTED_TARGET C) + +find_package(PkgConfig REQUIRED) + +message(STATUS "source: ${CMAKE_CURRENT_SOURCE_DIR} bin ${CMAKE_CURRENT_BINARY_DIR}") + +# Setup for the remaining package tests below +set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH) +set(fakePkgDir ${CMAKE_CURRENT_BINARY_DIR}/pc-fakepackage) +file(WRITE ${fakePkgDir}/lib/libcmakeinternalfakepackage.a "") +file(WRITE ${fakePkgDir}/lib/cmakeinternalfakepackage.lib "") +file(WRITE ${fakePkgDir}/lib/pkgconfig/cmakeinternalfakepackage.pc +"Name: CMakeInternalFakePackage +Description: Dummy package for FindPkgConfig VERSION_OPERATORS test +Version: 8.9 +Libs: -lcmakeinternalfakepackage +") + +# Always find the .pc file in the calls further below so that we can test that +# the import target find_library() calls handle the NO...PATH options correctly +set(ENV{PKG_CONFIG_PATH} ${fakePkgDir}/lib/pkgconfig) + +pkg_check_modules(FakePackageGE REQUIRED QUIET "cmakeinternalfakepackage >= 8") +if (NOT FakePackageGE_FOUND) + message(FATAL_ERROR "fake package >= 8 not found") +endif() + +pkg_check_modules(FakePackageGE_FAIL QUIET "cmakeinternalfakepackage >= 8.10") +if (FakePackageGE_FAIL_FOUND) + message(FATAL_ERROR "fake package >= 8.10 found") +endif() + +pkg_check_modules(FakePackageLE REQUIRED QUIET "cmakeinternalfakepackage<=9") +if (NOT FakePackageLE_FOUND) + message(FATAL_ERROR "fake package <= 9 not found") +endif() + +pkg_check_modules(FakePackageLE_FAIL QUIET "cmakeinternalfakepackage <= 8.1") +if (FakePackageLE_FAIL_FOUND) + message(FATAL_ERROR "fake package <= 8.1 found") +endif() + +pkg_check_modules(FakePackageGT REQUIRED QUIET "cmakeinternalfakepackage > 8") +if (NOT FakePackageGT_FOUND) + message(FATAL_ERROR "fake package > 8 not found") +endif() + +pkg_check_modules(FakePackageGT_FAIL QUIET "cmakeinternalfakepackage > 8.9") +if (FakePackageGT_FAIL_FOUND) + message(FATAL_ERROR "fake package > 8.9 found") +endif() + +pkg_check_modules(FakePackageLT REQUIRED QUIET "cmakeinternalfakepackage<9") +if (NOT FakePackageLT_FOUND) + message(FATAL_ERROR "fake package < 9 not found") +endif() + +pkg_check_modules(FakePackageLT_FAIL QUIET "cmakeinternalfakepackage < 8.9") +if (FakePackageLT_FAIL_FOUND) + message(FATAL_ERROR "fake package < 8.9 found") +endif() + +pkg_check_modules(FakePackageEQ REQUIRED QUIET "cmakeinternalfakepackage=8.9") +if (NOT FakePackageEQ_FOUND) + message(FATAL_ERROR "fake package = 8.9 not found") +endif() + +pkg_check_modules(FakePackageEQ_FAIL QUIET "cmakeinternalfakepackage = 8.8") +if (FakePackageEQ_FAIL_FOUND) + message(FATAL_ERROR "fake package = 8.8 found") +endif() + +pkg_check_modules(FakePackageEQ_INV QUIET "cmakeinternalfakepackage == 8.9") +if (FakePackageEQ_FAIL_FOUND) + message(FATAL_ERROR "fake package == 8.9 found") +endif() + +pkg_check_modules(FakePackageLLT_INV QUIET "cmakeinternalfakepackage <<= 9") +if (FakePackageLLT_FAIL_FOUND) + message(FATAL_ERROR "fake package <<= 9 found") +endif() diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake index e12b52f..671ff51 100644 --- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake +++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake @@ -16,4 +16,5 @@ if (PKG_CONFIG_FOUND) run_cmake(FindPkgConfig_GET_VARIABLE) run_cmake(FindPkgConfig_cache_variables) run_cmake(FindPkgConfig_IMPORTED_TARGET) + run_cmake(FindPkgConfig_VERSION_OPERATORS) endif () |