diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 20 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.h | 9 |
2 files changed, 24 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(); |