diff options
author | Andrea Pappacoda <andrea@pappacoda.it> | 2022-08-01 00:52:06 +0200 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-09-07 10:11:06 -0400 |
commit | 8f50f135aefa3f287a87c80cc8edb3deee8ee198 (patch) | |
tree | cf11e4d91d6d8b797272528b21217e9e7266e8cb /Modules | |
parent | 57ccad00010cd32d07592f6cefd004714e6993ad (diff) | |
download | cmake-8f50f135aefa3f287a87c80cc8edb3deee8ee198.tar.gz |
FPHSA: Improve error message when VERSION_VAR is empty or has been unset()
Previously, when `VERSION_VAR` is set but empty, FPHSA emitted a
confusing error message, saying that the package was found but of an
unsuitable version "". Fix the error message to state that the package
was not found.
Fixes: #23807
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindPackageHandleStandardArgs.cmake | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index fbcf7cd88b..6de7dbf129 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -535,9 +535,10 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) set(VERSION_MSG "") set(VERSION_OK TRUE) - # check with DEFINED here as the requested or found version may be "0" + # 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(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) @@ -547,6 +548,7 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) find_package_check_version ("${_FOUND_VERSION}" VERSION_OK RESULT_MESSAGE_VARIABLE VERSION_MSG ${FPCV_HANDLE_VERSION_RANGE}) else() + set(VERSION_OK FALSE) # 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}\")") |