Commit 3d821633 authored by Brad King's avatar Brad King
Browse files

Merge branch 'find_package_prefer_config_fix' into release-3.15

Merge-request: !3446
parents e815fad4 22e65d10
...@@ -502,8 +502,13 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args, ...@@ -502,8 +502,13 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG")) { if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG")) {
if (this->UseConfigFiles && this->FindPackageUsingConfigMode()) { if (this->UseConfigFiles && this->FindPackageUsingConfigMode()) {
loadedPackage = true; loadedPackage = true;
} else if (this->FindPackageUsingModuleMode()) { } else {
loadedPackage = true; if (this->FindPackageUsingModuleMode()) {
loadedPackage = true;
} else {
// The package was not loaded. Report errors.
HandlePackageMode(HandlePackageModeType::Module);
}
} }
} else { } else {
if (this->UseFindModules && this->FindPackageUsingModuleMode()) { if (this->UseFindModules && this->FindPackageUsingModuleMode()) {
...@@ -603,7 +608,7 @@ bool cmFindPackageCommand::FindPackageUsingConfigMode() ...@@ -603,7 +608,7 @@ bool cmFindPackageCommand::FindPackageUsingConfigMode()
this->IgnoredPaths.insert(ignored.begin(), ignored.end()); this->IgnoredPaths.insert(ignored.begin(), ignored.end());
// Find and load the package. // Find and load the package.
return this->HandlePackageMode(); return this->HandlePackageMode(HandlePackageModeType::Config);
} }
void cmFindPackageCommand::SetModuleVariables(const std::string& components) void cmFindPackageCommand::SetModuleVariables(const std::string& components)
...@@ -722,7 +727,8 @@ bool cmFindPackageCommand::FindModule(bool& found) ...@@ -722,7 +727,8 @@ bool cmFindPackageCommand::FindModule(bool& found)
return true; return true;
} }
bool cmFindPackageCommand::HandlePackageMode() bool cmFindPackageCommand::HandlePackageMode(
HandlePackageModeType handlePackageModeType)
{ {
this->ConsideredConfigs.clear(); this->ConsideredConfigs.clear();
...@@ -817,6 +823,12 @@ bool cmFindPackageCommand::HandlePackageMode() ...@@ -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 // package not found
if (result && !found) { if (result && !found) {
// warn if package required or neither quiet nor in config mode // warn if package required or neither quiet nor in config mode
......
...@@ -103,7 +103,14 @@ private: ...@@ -103,7 +103,14 @@ private:
bool FindModule(bool& found); bool FindModule(bool& found);
void AddFindDefinition(const std::string& var, const char* val); void AddFindDefinition(const std::string& var, const char* val);
void RestoreFindDefinitions(); void RestoreFindDefinitions();
bool HandlePackageMode();
enum /*class*/ HandlePackageModeType
{
Module,
Config
};
bool HandlePackageMode(HandlePackageModeType type);
bool FindConfig(); bool FindConfig();
bool FindPrefixedConfig(); bool FindPrefixedConfig();
bool FindFrameworkConfig(); bool FindFrameworkConfig();
......
...@@ -579,3 +579,16 @@ endif() ...@@ -579,3 +579,16 @@ endif()
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF) set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF)
set(CMAKE_PREFIX_PATH) 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()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment