Commit 805cb43d authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'find_package_prefer_config_fix'

22e65d10 find_package: Fixed CMAKE_FIND_PACKAGE_PREFER_CONFIG Module fallback
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !3446
parents 8f8b9539 22e65d10
......@@ -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
......
......@@ -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();
......
......@@ -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()
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