diff options
author | Brad King <brad.king@kitware.com> | 2017-09-08 13:48:10 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2017-09-08 13:48:15 (GMT) |
commit | d4f58a9cd8e3709a0cb176814226da324b17e0fe (patch) | |
tree | 8939ef4126064d26cada5c50328a62afa722353d | |
parent | 2581ab4395aa7dd2ecec98bf69b03e23c09af73a (diff) | |
parent | 91935d9e54ac1ce6d49c5672b1247b9fe3391568 (diff) | |
download | CMake-d4f58a9cd8e3709a0cb176814226da324b17e0fe.zip CMake-d4f58a9cd8e3709a0cb176814226da324b17e0fe.tar.gz CMake-d4f58a9cd8e3709a0cb176814226da324b17e0fe.tar.bz2 |
Merge topic 'fphsa-version-cleanup'
91935d9e FPHSA: lower-case for cmake_parse_arguments + move config-mode related code
aec27c15 FPHSA: use more localized _FOUND_VERSION instead of VERSION.
0019bfeb FPHSA: Add (failing) unit test in case a cache variable VERSION is present
81844334 FPHSA: add (failing) unit test for found version being equal to 0.
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Rolf Eike Beer <eike@sf-mail.de>
Merge-request: !1224
7 files changed, 53 insertions, 29 deletions
diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index b851a90..7b08bea 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -175,11 +175,12 @@ endmacro() function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) -# set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in -# new extended or in the "old" mode: +# Set up the arguments for `cmake_parse_arguments`. set(options CONFIG_MODE HANDLE_COMPONENTS) set(oneValueArgs FAIL_MESSAGE VERSION_VAR FOUND_VAR) set(multiValueArgs REQUIRED_VARS) + +# Check whether we are in 'simple' or 'extended' mode: set(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} ) list(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX) @@ -188,8 +189,7 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) set(FPHSA_REQUIRED_VARS ${ARGN}) set(FPHSA_VERSION_VAR) else() - - CMAKE_PARSE_ARGUMENTS(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN}) + cmake_parse_arguments(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN}) if(FPHSA_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"") @@ -198,6 +198,18 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) if(NOT FPHSA_FAIL_MESSAGE) set(FPHSA_FAIL_MESSAGE "DEFAULT_MSG") endif() + + # In config-mode, we rely on the variable <package>_CONFIG, which is set by find_package() + # when it successfully found the config-file, including version checking: + if(FPHSA_CONFIG_MODE) + list(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG) + list(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS) + set(FPHSA_VERSION_VAR ${_NAME}_VERSION) + endif() + + if(NOT FPHSA_REQUIRED_VARS) + message(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()") + endif() endif() # now that we collected all arguments, process them @@ -206,18 +218,6 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}") endif() - # In config-mode, we rely on the variable <package>_CONFIG, which is set by find_package() - # when it successfully found the config-file, including version checking: - if(FPHSA_CONFIG_MODE) - list(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG) - list(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS) - set(FPHSA_VERSION_VAR ${_NAME}_VERSION) - endif() - - if(NOT FPHSA_REQUIRED_VARS) - message(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()") - endif() - list(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR) string(TOUPPER ${_NAME} _NAME_UPPER) @@ -289,15 +289,15 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # version handling: set(VERSION_MSG "") set(VERSION_OK TRUE) - set(VERSION ${${FPHSA_VERSION_VAR}}) # check with DEFINED here as the requested or found version may be "0" 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 "${VERSION}") + 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) @@ -312,31 +312,31 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) else () set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*") endif () - string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${VERSION}") + 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 \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_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 \"${VERSION}\")") + set(VERSION_MSG "(found suitable exact version \"${_FOUND_VERSION}\")") endif () unset(_VERSION_HEAD) else () if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL VERSION) - set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_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 \"${VERSION}\")") + set(VERSION_MSG "(found suitable exact version \"${_FOUND_VERSION}\")") endif () endif () unset(_VERSION_DOTS) else() # minimum version specified: - if (${_NAME}_FIND_VERSION VERSION_GREATER VERSION) - set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"") + 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 \"${VERSION}\", minimum required is \"${${_NAME}_FIND_VERSION}\")") + set(VERSION_MSG "(found suitable version \"${_FOUND_VERSION}\", minimum required is \"${${_NAME}_FIND_VERSION}\")") endif () endif() @@ -351,13 +351,14 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) endif() else () - if(VERSION) - set(VERSION_MSG "(found version \"${VERSION}\")") + # Check with DEFINED as the found version may be 0. + if(DEFINED ${FPHSA_VERSION_VAR}) + set(VERSION_MSG "(found version \"${${FPHSA_VERSION_VAR}}\")") endif() endif () if(VERSION_OK) - string(APPEND DETAILS "[v${VERSION}(${${_NAME}_FIND_VERSION})]") + string(APPEND DETAILS "[v${${FPHSA_VERSION_VAR}}(${${_NAME}_FIND_VERSION})]") else() set(${_NAME}_FOUND FALSE) endif() diff --git a/Tests/RunCMake/FPHSA/FindPseudoNoVersionVar.cmake b/Tests/RunCMake/FPHSA/FindPseudoNoVersionVar.cmake new file mode 100644 index 0000000..d961c64 --- /dev/null +++ b/Tests/RunCMake/FPHSA/FindPseudoNoVersionVar.cmake @@ -0,0 +1,6 @@ +# pseudo find_module without specifying VERSION_VAR + +set(FOOBAR TRUE) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PseudoNoVersionVar REQUIRED_VARS FOOBAR) diff --git a/Tests/RunCMake/FPHSA/RunCMakeTest.cmake b/Tests/RunCMake/FPHSA/RunCMakeTest.cmake index e9b2a7a..1b71a31 100644 --- a/Tests/RunCMake/FPHSA/RunCMakeTest.cmake +++ b/Tests/RunCMake/FPHSA/RunCMakeTest.cmake @@ -4,6 +4,17 @@ run_cmake(BadFoundVar) # The pseudo module will "find" a package with the given version. Check if the # version selection code in FPHSA works correctly. + +# Find a package with version 0. +set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=0") +run_cmake(any_version_find_0) + +# Find a package with more customary version number, without requestion a specific version and in +# the presence of a cache variable VERSION. +set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudoNoVersionVar_VERSION=1.2.3.4.5_SHOULD_BE_IGNORED" "-DVERSION=BAD_VERSION") +run_cmake(any_version_VERSION_cache_variable) + +# Find a package with a more customary version number, without requestion a specific version. set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=1.2.3.4.5") run_cmake(any_version) diff --git a/Tests/RunCMake/FPHSA/any_version_VERSION_cache_variable-stdout.txt b/Tests/RunCMake/FPHSA/any_version_VERSION_cache_variable-stdout.txt new file mode 100644 index 0000000..f9acece --- /dev/null +++ b/Tests/RunCMake/FPHSA/any_version_VERSION_cache_variable-stdout.txt @@ -0,0 +1,2 @@ +Found PseudoNoVersionVar: TRUE * ++ diff --git a/Tests/RunCMake/FPHSA/any_version_VERSION_cache_variable.cmake b/Tests/RunCMake/FPHSA/any_version_VERSION_cache_variable.cmake new file mode 100644 index 0000000..9f27897 --- /dev/null +++ b/Tests/RunCMake/FPHSA/any_version_VERSION_cache_variable.cmake @@ -0,0 +1 @@ +find_package(PseudoNoVersionVar REQUIRED) diff --git a/Tests/RunCMake/FPHSA/any_version_find_0-stdout.txt b/Tests/RunCMake/FPHSA/any_version_find_0-stdout.txt new file mode 100644 index 0000000..861a339 --- /dev/null +++ b/Tests/RunCMake/FPHSA/any_version_find_0-stdout.txt @@ -0,0 +1,2 @@ +Found Pseudo: [^ +]*\(found version "0\"\) diff --git a/Tests/RunCMake/FPHSA/any_version_find_0.cmake b/Tests/RunCMake/FPHSA/any_version_find_0.cmake new file mode 100644 index 0000000..b34a540 --- /dev/null +++ b/Tests/RunCMake/FPHSA/any_version_find_0.cmake @@ -0,0 +1 @@ +find_package(Pseudo REQUIRED) |