summaryrefslogtreecommitdiffstats
path: root/Source/cmFindPackageCommand.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmFindPackageCommand.cxx')
-rw-r--r--Source/cmFindPackageCommand.cxx171
1 files changed, 137 insertions, 34 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index bd58f56..ef0197a 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -156,6 +156,11 @@ cmFindPackageCommand::cmFindPackageCommand()
"The full path to the configuration file is stored in the cmake "
"variable <package>_CONFIG."
"\n"
+ "All configuration files which have been considered by CMake while "
+ "searching for an installation of the package with an appropriate "
+ "version are stored in the cmake variable <package>_CONSIDERED_CONFIGS, "
+ "the associated versions in <package>_CONSIDERED_VERSIONS. "
+ "\n"
"If the package configuration file cannot be found CMake "
"will generate an error describing the problem unless the QUIET "
"argument is specified. If REQUIRED is specified and the package "
@@ -596,6 +601,15 @@ bool cmFindPackageCommand
}
}
+ // get igonored paths from vars and reroot them.
+ std::vector<std::string> ignored;
+ this->GetIgnoredPaths(ignored);
+ this->RerootPaths(ignored);
+
+ // Construct a set of ignored paths
+ this->IgnoredPaths.clear();
+ this->IgnoredPaths.insert(ignored.begin(), ignored.end());
+
// Find and load the package.
bool result = this->HandlePackageMode();
this->AppendSuccessInformation();
@@ -609,7 +623,7 @@ void cmFindPackageCommand::SetModuleVariables(const std::string& components)
// Store the list of components.
std::string components_var = this->Name + "_FIND_COMPONENTS";
this->AddFindDefinition(components_var.c_str(), components.c_str());
-
+
if(this->Quiet)
{
// Tell the module that is about to be read that it should find
@@ -712,6 +726,8 @@ bool cmFindPackageCommand::FindModule(bool& found)
//----------------------------------------------------------------------------
bool cmFindPackageCommand::HandlePackageMode()
{
+ this->ConsideredConfigs.clear();
+
// Support old capitalization behavior.
std::string upperDir = cmSystemTools::UpperCase(this->Name);
std::string upperFound = cmSystemTools::UpperCase(this->Name);
@@ -800,36 +816,58 @@ bool cmFindPackageCommand::HandlePackageMode()
{
// The variable is not set.
cmOStringStream e;
- e << "Could not find ";
- if(!this->NoModule)
- {
- e << "module Find" << this->Name << ".cmake or ";
- }
- e << "a configuration file for package " << this->Name << ".\n";
- if(!this->NoModule)
- {
- e << "Adjust CMAKE_MODULE_PATH to find Find"
- << this->Name << ".cmake or set ";
- }
- else
- {
- e << "Set ";
- }
- e << this->Variable << " to the directory containing a CMake "
- << "configuration file for " << this->Name << ". ";
- if(this->Configs.size() == 1)
- {
- e << "The file will be called " << this->Configs[0];
+ // If there are files in ConsideredConfigs, it means that FooConfig.cmake
+ // have been found, but they didn't have appropriate versions.
+ if (this->ConsideredConfigs.size() > 0)
+ {
+ e << "Could not find a configuration file for package \""
+ << this->Name << "\" that "
+ << (this->VersionExact? "exactly matches" : "is compatible with")
+ << " requested version \"" << this->Version << "\".\n"
+ << "The following configuration files were considered but not "
+ "accepted:\n";
+ for(std::vector<ConfigFileInfo>::size_type i=0;
+ i<this->ConsideredConfigs.size(); i++)
+ {
+ e << " " << this->ConsideredConfigs[i].filename
+ << ", version: " << this->ConsideredConfigs[i].version << "\n";
+ }
}
else
{
- e << "The file will have one of the following names:\n";
- for(std::vector<std::string>::const_iterator ci = this->Configs.begin();
- ci != this->Configs.end(); ++ci)
+ e << "Could not find ";
+ if(!this->NoModule)
+ {
+ e << "module Find" << this->Name << ".cmake or ";
+ }
+ e << "a configuration file for package " << this->Name << ".\n";
+ if(!this->NoModule)
{
- e << " " << *ci << "\n";
+ e << "Adjust CMAKE_MODULE_PATH to find Find"
+ << this->Name << ".cmake or set ";
+ }
+ else
+ {
+ e << "Set ";
+ }
+ e << this->Variable << " to the directory containing a CMake "
+ << "configuration file for " << this->Name << ". ";
+ if(this->Configs.size() == 1)
+ {
+ e << "The file will be called " << this->Configs[0];
+ }
+ else
+ {
+ e << "The file will have one of the following names:\n";
+ for(std::vector<std::string>::const_iterator ci=this->Configs.begin();
+ ci != this->Configs.end(); ++ci)
+ {
+ e << " " << *ci << "\n";
+ }
}
}
+
+
this->Makefile->IssueMessage(
this->Required? cmake::FATAL_ERROR : cmake::WARNING, e.str());
}
@@ -888,6 +926,31 @@ bool cmFindPackageCommand::HandlePackageMode()
}
#endif
+ std::string consideredConfigsVar = this->Name;
+ consideredConfigsVar += "_CONSIDERED_CONFIGS";
+ std::string consideredVersionsVar = this->Name;
+ consideredVersionsVar += "_CONSIDERED_VERSIONS";
+
+ std::string consideredConfigFiles;
+ std::string consideredVersions;
+
+ const char* sep = "";
+ for(std::vector<ConfigFileInfo>::size_type i=0;
+ i<this->ConsideredConfigs.size(); i++)
+ {
+ consideredConfigFiles += sep;
+ consideredVersions += sep;
+ consideredConfigFiles += this->ConsideredConfigs[i].filename;
+ consideredVersions += this->ConsideredConfigs[i].version;
+ sep = ";";
+ }
+
+ this->Makefile->AddDefinition(consideredConfigsVar.c_str(),
+ consideredConfigFiles.c_str());
+
+ this->Makefile->AddDefinition(consideredVersionsVar.c_str(),
+ consideredVersions.c_str());
+
return result;
}
@@ -1074,6 +1137,20 @@ void cmFindPackageCommand::AppendSuccessInformation()
}
}
+ // set a global property to record the required version of this package
+ std::string versionInfoPropName = "_CMAKE_";
+ versionInfoPropName += this->Name;
+ versionInfoPropName += "_REQUIRED_VERSION";
+ std::string versionInfo;
+ if(!this->Version.empty())
+ {
+ versionInfo = this->VersionExact ? "==" : ">=";
+ versionInfo += " ";
+ versionInfo += this->Version;
+ }
+ this->Makefile->GetCMakeInstance()->SetProperty(versionInfoPropName.c_str(),
+ versionInfo.c_str());
+
// Restore original state of "_FIND_" variables we set.
this->RestoreFindDefinitions();
}
@@ -1431,6 +1508,11 @@ bool cmFindPackageCommand::CheckDirectory(std::string const& dir)
bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
std::string& file)
{
+ if (this->IgnoredPaths.count(dir))
+ {
+ return false;
+ }
+
for(std::vector<std::string>::const_iterator ci = this->Configs.begin();
ci != this->Configs.end(); ++ci)
{
@@ -1453,6 +1535,10 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
//----------------------------------------------------------------------------
bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
{
+ bool result = false; // by default, assume the version is not ok.
+ bool haveResult = false;
+ std::string version = "unknown";
+
// Get the filename without the .cmake extension.
std::string::size_type pos = config_file.rfind('.');
std::string version_file_base = config_file.substr(0, pos);
@@ -1460,31 +1546,42 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
// Look for foo-config-version.cmake
std::string version_file = version_file_base;
version_file += "-version.cmake";
- if(cmSystemTools::FileExists(version_file.c_str(), true))
+ if ((haveResult == false)
+ && (cmSystemTools::FileExists(version_file.c_str(), true)))
{
- return this->CheckVersionFile(version_file);
+ result = this->CheckVersionFile(version_file, version);
+ haveResult = true;
}
// Look for fooConfigVersion.cmake
version_file = version_file_base;
version_file += "Version.cmake";
- if(cmSystemTools::FileExists(version_file.c_str(), true))
+ if ((haveResult == false)
+ && (cmSystemTools::FileExists(version_file.c_str(), true)))
{
- return this->CheckVersionFile(version_file);
+ result = this->CheckVersionFile(version_file, version);
+ haveResult = true;
}
+
// If no version was requested a versionless package is acceptable.
- if(this->Version.empty())
+ if ((haveResult == false) && (this->Version.empty()))
{
- return true;
+ result = true;
+ haveResult = true;
}
- // No version file found. Assume the version is incompatible.
- return false;
+ ConfigFileInfo configFileInfo;
+ configFileInfo.filename = config_file;
+ configFileInfo.version = version;
+ this->ConsideredConfigs.push_back(configFileInfo);
+
+ return result;
}
//----------------------------------------------------------------------------
-bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file)
+bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
+ std::string& result_version)
{
// The version file will be loaded in an isolated scope.
cmMakefile::ScopePushPop varScope(this->Makefile);
@@ -1557,6 +1654,12 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file)
}
}
+ result_version = this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
+ if (result_version.empty())
+ {
+ result_version = "unknown";
+ }
+
// Succeed if the version is suitable.
return suitable;
}