diff options
author | Brad King <brad.king@kitware.com> | 2022-09-15 14:52:23 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-09-15 15:00:02 (GMT) |
commit | 07f0a78874e0cf8013654ff4bac5e7192a324609 (patch) | |
tree | 963c5a09903c69978de7973d639f959f6c8bff64 | |
parent | 01a25d72c69b0a9a60c1a62939d6a2c543448118 (diff) | |
download | CMake-07f0a78874e0cf8013654ff4bac5e7192a324609.zip CMake-07f0a78874e0cf8013654ff4bac5e7192a324609.tar.gz CMake-07f0a78874e0cf8013654ff4bac5e7192a324609.tar.bz2 |
FPHSA: Fix regression when VERSION_VAR is missing
If a package is found but FPHSA is called by the find module without a
`VERSION_VAR`, and the `find_package` call specifies a version, we have
previously accepted the package as found. This was accidentally
regressed by commit 8f50f135ae (FPHSA: Improve error message when
VERSION_VAR is empty or has been unset(), 2022-08-01). Restore it and
add a test case.
-rw-r--r-- | Modules/FindPackageHandleStandardArgs.cmake | 22 | ||||
-rw-r--r-- | Tests/RunCMake/FPHSA/RunCMakeTest.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/FPHSA/exact_1_no_version_var-stdout.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/FPHSA/exact_1_no_version_var.cmake | 1 |
4 files changed, 18 insertions, 9 deletions
diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index 6de7dbf..56ba1e6 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -538,17 +538,21 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # check that the version variable is not empty to avoid emitting a misleading # message (i.e. `Found unsuitable version ""`) if (DEFINED ${_NAME}_FIND_VERSION) - if(NOT "${${FPHSA_VERSION_VAR}}" STREQUAL "") - set(_FOUND_VERSION ${${FPHSA_VERSION_VAR}}) - if (FPHSA_HANDLE_VERSION_RANGE) - set (FPCV_HANDLE_VERSION_RANGE HANDLE_VERSION_RANGE) + if(DEFINED ${FPHSA_VERSION_VAR}) + if(NOT "${${FPHSA_VERSION_VAR}}" STREQUAL "") + set(_FOUND_VERSION ${${FPHSA_VERSION_VAR}}) + if (FPHSA_HANDLE_VERSION_RANGE) + set (FPCV_HANDLE_VERSION_RANGE HANDLE_VERSION_RANGE) + else() + set(FPCV_HANDLE_VERSION_RANGE NO_AUTHOR_WARNING_VERSION_RANGE) + endif() + find_package_check_version ("${_FOUND_VERSION}" VERSION_OK RESULT_MESSAGE_VARIABLE VERSION_MSG + ${FPCV_HANDLE_VERSION_RANGE}) else() - set(FPCV_HANDLE_VERSION_RANGE NO_AUTHOR_WARNING_VERSION_RANGE) + set(VERSION_OK FALSE) endif() - find_package_check_version ("${_FOUND_VERSION}" VERSION_OK RESULT_MESSAGE_VARIABLE VERSION_MSG - ${FPCV_HANDLE_VERSION_RANGE}) - else() - set(VERSION_OK FALSE) + endif() + if("${${FPHSA_VERSION_VAR}}" STREQUAL "") # if the package was not found, but a version was given, add that to the output: if(${_NAME}_FIND_VERSION_EXACT) set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")") diff --git a/Tests/RunCMake/FPHSA/RunCMakeTest.cmake b/Tests/RunCMake/FPHSA/RunCMakeTest.cmake index e389e6b..3b095a6 100644 --- a/Tests/RunCMake/FPHSA/RunCMakeTest.cmake +++ b/Tests/RunCMake/FPHSA/RunCMakeTest.cmake @@ -44,6 +44,9 @@ run_cmake(exact_0_matching) set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=") run_cmake(empty_version) +set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}") +run_cmake(exact_1_no_version_var) + # check custom error message set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DCustomMessage_VERSION=1.2.3.4") run_cmake(custom_message_1) diff --git a/Tests/RunCMake/FPHSA/exact_1_no_version_var-stdout.txt b/Tests/RunCMake/FPHSA/exact_1_no_version_var-stdout.txt new file mode 100644 index 0000000..7cbdf6e --- /dev/null +++ b/Tests/RunCMake/FPHSA/exact_1_no_version_var-stdout.txt @@ -0,0 +1 @@ +-- Found Pseudo: TRUE \(Required is at least version "1"\) diff --git a/Tests/RunCMake/FPHSA/exact_1_no_version_var.cmake b/Tests/RunCMake/FPHSA/exact_1_no_version_var.cmake new file mode 100644 index 0000000..7b7ff34 --- /dev/null +++ b/Tests/RunCMake/FPHSA/exact_1_no_version_var.cmake @@ -0,0 +1 @@ +find_package(Pseudo 1 REQUIRED) |