diff options
author | Cristian Adam <cristian.adam@gmail.com> | 2019-06-13 21:58:30 (GMT) |
---|---|---|
committer | Cristian Adam <cristian.adam@gmail.com> | 2019-06-13 21:58:30 (GMT) |
commit | 22e65d10c175081ed5f21f86c7064c014fc3f39c (patch) | |
tree | a673d33900c33c132c1528072064cc1ec4970f57 | |
parent | a4231943117f5ba3dd0fdc6c8b1824334162b69f (diff) | |
download | CMake-22e65d10c175081ed5f21f86c7064c014fc3f39c.zip CMake-22e65d10c175081ed5f21f86c7064c014fc3f39c.tar.gz CMake-22e65d10c175081ed5f21f86c7064c014fc3f39c.tar.bz2 |
find_package: Fixed CMAKE_FIND_PACKAGE_PREFER_CONFIG Module fallback
Fixes: #19361
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 20 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.h | 9 | ||||
-rw-r--r-- | Tests/FindPackageTest/CMakeLists.txt | 13 | ||||
-rw-r--r-- | Tests/FindPackageTest/PreferConfigOnlyModule/FindACME.cmake | 1 |
4 files changed, 38 insertions, 5 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 8eefaa7..828488f 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -502,8 +502,13 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args, if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG")) { if (this->UseConfigFiles && this->FindPackageUsingConfigMode()) { loadedPackage = true; - } else if (this->FindPackageUsingModuleMode()) { - loadedPackage = true; + } else { + if (this->FindPackageUsingModuleMode()) { + loadedPackage = true; + } else { + // The package was not loaded. Report errors. + HandlePackageMode(HandlePackageModeType::Module); + } } } else { if (this->UseFindModules && this->FindPackageUsingModuleMode()) { @@ -603,7 +608,7 @@ bool cmFindPackageCommand::FindPackageUsingConfigMode() this->IgnoredPaths.insert(ignored.begin(), ignored.end()); // Find and load the package. - return this->HandlePackageMode(); + return this->HandlePackageMode(HandlePackageModeType::Config); } void cmFindPackageCommand::SetModuleVariables(const std::string& components) @@ -722,7 +727,8 @@ bool cmFindPackageCommand::FindModule(bool& found) return true; } -bool cmFindPackageCommand::HandlePackageMode() +bool cmFindPackageCommand::HandlePackageMode( + HandlePackageModeType handlePackageModeType) { this->ConsideredConfigs.clear(); @@ -817,6 +823,12 @@ bool cmFindPackageCommand::HandlePackageMode() } } + if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG") && !found && + handlePackageModeType == HandlePackageModeType::Config) { + // Config mode failed. Allow Module case. + result = false; + } + // package not found if (result && !found) { // warn if package required or neither quiet nor in config mode diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 4f6d97c..316ca0f 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -103,7 +103,14 @@ private: bool FindModule(bool& found); void AddFindDefinition(const std::string& var, const char* val); void RestoreFindDefinitions(); - bool HandlePackageMode(); + + enum /*class*/ HandlePackageModeType + { + Module, + Config + }; + bool HandlePackageMode(HandlePackageModeType type); + bool FindConfig(); bool FindPrefixedConfig(); bool FindFrameworkConfig(); diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt index 8802b73..affe5d5 100644 --- a/Tests/FindPackageTest/CMakeLists.txt +++ b/Tests/FindPackageTest/CMakeLists.txt @@ -579,3 +579,16 @@ endif() set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF) set(CMAKE_PREFIX_PATH) + +############################################################################ +##Test find_package CMAKE_FIND_PACKAGE_PREFER_CONFIG with module fallback + +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PreferConfigOnlyModule) + +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) + +find_package(ACME REQUIRED) + +if(NOT ACME_FOUND) + message(SEND_ERROR "Did not find ACME package") +endif() diff --git a/Tests/FindPackageTest/PreferConfigOnlyModule/FindACME.cmake b/Tests/FindPackageTest/PreferConfigOnlyModule/FindACME.cmake new file mode 100644 index 0000000..7a4e1b3 --- /dev/null +++ b/Tests/FindPackageTest/PreferConfigOnlyModule/FindACME.cmake @@ -0,0 +1 @@ +set(ACME_FOUND TRUE) |