mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 10:50:16 -06:00
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
This commit is contained in:
committed by
Brad King
parent
57ccad0001
commit
8f50f135ae
@@ -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}\")")
|
||||
|
||||
@@ -38,9 +38,12 @@ run_cmake(exact_1.2.3.5)
|
||||
unset(RunCMake_DEFAULT_stderr)
|
||||
|
||||
# check if searching for a version 0 works
|
||||
list(APPEND RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=0")
|
||||
set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=0")
|
||||
run_cmake(exact_0_matching)
|
||||
|
||||
set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=")
|
||||
run_cmake(empty_version)
|
||||
|
||||
# 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)
|
||||
|
||||
1
Tests/RunCMake/FPHSA/empty_version-result.txt
Normal file
1
Tests/RunCMake/FPHSA/empty_version-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
9
Tests/RunCMake/FPHSA/empty_version-stderr.txt
Normal file
9
Tests/RunCMake/FPHSA/empty_version-stderr.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
^CMake Error at [^
|
||||
]*/Modules/FindPackageHandleStandardArgs.cmake:[0-9]+ \(message\):
|
||||
Could NOT find Pseudo: \(Required is at least version "1"\) \(found TRUE\)
|
||||
Call Stack \(most recent call first\):
|
||||
[^
|
||||
]*/Modules/FindPackageHandleStandardArgs.cmake:[0-9]+ \(_FPHSA_FAILURE_MESSAGE\)
|
||||
FindPseudo.cmake:[0-9]+ \(find_package_handle_standard_args\)
|
||||
empty_version.cmake:[0-9]+ \(find_package\)
|
||||
CMakeLists.txt:[0-9]+ \(include\)$
|
||||
1
Tests/RunCMake/FPHSA/empty_version.cmake
Normal file
1
Tests/RunCMake/FPHSA/empty_version.cmake
Normal file
@@ -0,0 +1 @@
|
||||
find_package(Pseudo 1 REQUIRED)
|
||||
Reference in New Issue
Block a user