From 8d71fa92838f9fd3d444963c6ea6ea0d7be39cf3 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 27 Feb 2017 17:15:49 +0100 Subject: [PATCH] FindPkgConfig: use new version checking "library >= version" syntax Instead of the deprecated --atleast-version one. --- Modules/FindPkgConfig.cmake | 39 +++++++------------ .../FindPkgConfig/dummy-pkg-config.bat | 11 +++++- .../FindPkgConfig/dummy-pkg-config.sh | 32 ++++++++------- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index 1958f4b434..a69081f203 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -360,39 +360,26 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma set(_pkg_check_modules_pkg_ver) endif() - # handle the operands - if (_pkg_check_modules_pkg_op STREQUAL ">=") - list(APPEND _pkg_check_modules_exist_query --atleast-version) - endif() - - if (_pkg_check_modules_pkg_op STREQUAL "=") - list(APPEND _pkg_check_modules_exist_query --exact-version) - endif() - - if (_pkg_check_modules_pkg_op STREQUAL "<=") - list(APPEND _pkg_check_modules_exist_query --max-version) - endif() - - # create the final query which is of the format: - # * --atleast-version - # * --exact-version - # * --max-version - # * --exists - if (_pkg_check_modules_pkg_op) - list(APPEND _pkg_check_modules_exist_query "${_pkg_check_modules_pkg_ver}") - else() - list(APPEND _pkg_check_modules_exist_query --exists) - endif() - list(APPEND _pkg_check_modules_exist_query --print-errors --short-errors) - _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_VERSION) _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_PREFIX) _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_INCLUDEDIR) _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_LIBDIR) - list(APPEND _pkg_check_modules_exist_query "${_pkg_check_modules_pkg_name}") list(APPEND _pkg_check_modules_packages "${_pkg_check_modules_pkg_name}") + # create the final query which is of the format: + # * >= + # * = + # * <= + # * --exists + list(APPEND _pkg_check_modules_exist_query --print-errors --short-errors) + if (_pkg_check_modules_pkg_op) + list(APPEND _pkg_check_modules_exist_query "${_pkg_check_modules_pkg_name} ${_pkg_check_modules_pkg_op} ${_pkg_check_modules_pkg_ver}") + else() + list(APPEND _pkg_check_modules_exist_query --exists) + list(APPEND _pkg_check_modules_exist_query "${_pkg_check_modules_pkg_name}") + endif() + # execute the query execute_process( COMMAND ${PKG_CONFIG_EXECUTABLE} ${_pkg_check_modules_exist_query} diff --git a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat index f2f86b0a6c..b03837030c 100755 --- a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat +++ b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat @@ -1,7 +1,11 @@ @ECHO OFF + +:LOOP + IF "%1"=="" ( EXIT /B 255 ) + IF "%1"=="--version" ( ECHO 0.0-cmake-dummy EXIT /B 0 @@ -13,6 +17,11 @@ IF "%1"=="--exists" ( ECHO Found: %PKG_CONFIG_PATH% IF NOT "%*"=="%PKG_CONFIG_PATH%" ( EXIT /B 1 + ) ELSE ( + EXIT /B 0 ) ) -EXIT /B 0 +SHIFT +IF NOT "%~1"=="" GOTO LOOP + +EXIT /B 255 diff --git a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh index abe14bf98a..56bba30dd4 100755 --- a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh +++ b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.sh @@ -4,18 +4,20 @@ # to the --exists argument with the PKG_CONFIG_PATH environment variable # and returns 1 if they are different. -case $1 in - --version) - echo "0.0-cmake-dummy" - ;; - --exists) - shift - eval last=\${$#} - echo "Expected: ${last}" - echo "Found: ${PKG_CONFIG_PATH}" - [ "${last}" = "${PKG_CONFIG_PATH}" ] || exit 1 - ;; - *) - exit 255 - ;; -esac +while [ $# -gt 0 ]; do + case $1 in + --version) + echo "0.0-cmake-dummy" + exit 0 + ;; + --exists) + shift + eval last=\${$#} + echo "Expected: ${last}" + echo "Found: ${PKG_CONFIG_PATH}" + [ "${last}" = "${PKG_CONFIG_PATH}" ] && exit 0 || exit 1 + ;; + esac + shift +done +exit 255