find_package: Restore longer message when config files were considered

Since commit v3.9.0-rc1~58^2 (find_package: shorten output for missing
package in config mode, 2017-05-09) we print only the one line

    - Could NOT find Foo (missing: Foo_DIR)

when package Foo cannot be found in CONFIG mode and it is not REQUIRED.
However, in the case that package configuration files were found but not
used, this one line message leaves out important information.  This can
happen when a package configuration file sets `Foo_FOUND` to `FALSE` or
when its package version file does not match the requested version.
Restore the longer message in these cases.  Otherwise a seemingly valid
explicit `Foo_DIR` setting appears to be silently ignored even if it was
considered.

Fixes: #17029
This commit is contained in:
Brad King
2017-07-07 08:06:03 -04:00
parent 372de3f803
commit e7730d78b4
12 changed files with 47 additions and 2 deletions

View File

@@ -739,7 +739,8 @@ bool cmFindPackageCommand::HandlePackageMode()
if (result && !found) {
// warn if package required or neither quiet nor in config mode
if (this->Required ||
!(this->Quiet || (this->UseConfigFiles && !this->UseFindModules))) {
!(this->Quiet || (this->UseConfigFiles && !this->UseFindModules &&
this->ConsideredConfigs.empty()))) {
// The variable is not set.
std::ostringstream e;
std::ostringstream aw;

View File

@@ -17,3 +17,5 @@ run_cmake(PackageRoot)
run_cmake(PolicyPush)
run_cmake(PolicyPop)
run_cmake(SetFoundFALSE)
run_cmake(WrongVersion)
run_cmake(WrongVersionConfig)

View File

@@ -0,0 +1,9 @@
CMake Warning at SetFoundFALSE.cmake:2 \(find_package\):
Found package configuration file:
.*/Tests/RunCMake/find_package/SetFoundFALSEConfig.cmake
but it set SetFoundFALSE_FOUND to FALSE so package "SetFoundFALSE" is
considered to be NOT FOUND.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@@ -1 +0,0 @@
-- Could NOT find SetFoundFALSE \(missing: SetFoundFALSE_DIR\)

View File

@@ -0,0 +1,4 @@
set(PACKAGE_VERSION 1)
if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 1)
set(PACKAGE_VERSION_COMPATIBLE 1)
endif()

View File

@@ -0,0 +1,4 @@
set(PACKAGE_VERSION 2)
if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 2)
set(PACKAGE_VERSION_COMPATIBLE 1)
endif()

View File

@@ -0,0 +1,11 @@
^CMake Warning at WrongVersion.cmake:[0-9]+ \(find_package\):
Could not find a configuration file for package "VersionedA" that is
compatible with requested version "3".
The following configuration files were considered but not accepted:
.*/Tests/RunCMake/find_package/VersionedA-[12]/VersionedAConfig.cmake, version: [12]
.*/Tests/RunCMake/find_package/VersionedA-[12]/VersionedAConfig.cmake, version: [12]
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1,2 @@
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(VersionedA 3)

View File

@@ -0,0 +1,11 @@
^CMake Warning at WrongVersionConfig.cmake:[0-9]+ \(find_package\):
Could not find a configuration file for package "VersionedA" that is
compatible with requested version "3".
The following configuration files were considered but not accepted:
.*/Tests/RunCMake/find_package/VersionedA-[12]/VersionedAConfig.cmake, version: [12]
.*/Tests/RunCMake/find_package/VersionedA-[12]/VersionedAConfig.cmake, version: [12]
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1,2 @@
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(VersionedA 3)