Record all considered Config files and their versions.

As suggested on cmake-devel, find_package in Config-mode now records
all considered config-files and their versions in
<package>_CONSIDERED_CONFIGS and <package>_CONSIDERED_VERSIONS respectively.

Alex
This commit is contained in:
Alex Neundorf 2010-08-29 17:07:39 +02:00
parent 737261785a
commit dfe9c95129
2 changed files with 70 additions and 11 deletions

View File

@ -156,6 +156,11 @@ cmFindPackageCommand::cmFindPackageCommand()
"The full path to the configuration file is stored in the cmake " "The full path to the configuration file is stored in the cmake "
"variable <package>_CONFIG." "variable <package>_CONFIG."
"\n" "\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 " "If the package configuration file cannot be found CMake "
"will generate an error describing the problem unless the QUIET " "will generate an error describing the problem unless the QUIET "
"argument is specified. If REQUIRED is specified and the package " "argument is specified. If REQUIRED is specified and the package "
@ -721,6 +726,9 @@ bool cmFindPackageCommand::FindModule(bool& found)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmFindPackageCommand::HandlePackageMode() bool cmFindPackageCommand::HandlePackageMode()
{ {
this->ConsideredConfigFiles.clear();
this->ConsideredVersions.clear();
// Support old capitalization behavior. // Support old capitalization behavior.
std::string upperDir = cmSystemTools::UpperCase(this->Name); std::string upperDir = cmSystemTools::UpperCase(this->Name);
std::string upperFound = cmSystemTools::UpperCase(this->Name); std::string upperFound = cmSystemTools::UpperCase(this->Name);
@ -897,6 +905,35 @@ bool cmFindPackageCommand::HandlePackageMode()
} }
#endif #endif
std::string consideredConfigsVar = this->Name;
consideredConfigsVar += "_CONSIDERED_CONFIGS";
std::string consideredVersionsVar = this->Name;
consideredVersionsVar += "_CONSIDERED_VERSIONS";
std::string consideredConfigFiles;
for(std::vector<std::string>::const_iterator
it = this->ConsideredConfigFiles.begin();
it != this->ConsideredConfigFiles.end(); ++it)
{
consideredConfigFiles += *it;
consideredConfigFiles += ";";
}
std::string consideredVersions;
for(std::vector<std::string>::const_iterator
it = this->ConsideredVersions.begin();
it != this->ConsideredVersions.end(); ++it)
{
consideredVersions += *it;
consideredVersions += ";";
}
this->Makefile->AddDefinition(consideredConfigsVar.c_str(),
consideredConfigFiles.c_str());
this->Makefile->AddDefinition(consideredVersionsVar.c_str(),
consideredVersions.c_str());
return result; return result;
} }
@ -1467,6 +1504,10 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmFindPackageCommand::CheckVersion(std::string const& config_file) 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. // Get the filename without the .cmake extension.
std::string::size_type pos = config_file.rfind('.'); std::string::size_type pos = config_file.rfind('.');
std::string version_file_base = config_file.substr(0, pos); std::string version_file_base = config_file.substr(0, pos);
@ -1474,31 +1515,40 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
// Look for foo-config-version.cmake // Look for foo-config-version.cmake
std::string version_file = version_file_base; std::string version_file = version_file_base;
version_file += "-version.cmake"; 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 // Look for fooConfigVersion.cmake
version_file = version_file_base; version_file = version_file_base;
version_file += "Version.cmake"; 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 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. this->ConsideredConfigFiles.push_back(config_file);
return false; this->ConsideredVersions.push_back(version);
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. // The version file will be loaded in an isolated scope.
cmMakefile::ScopePushPop varScope(this->Makefile); cmMakefile::ScopePushPop varScope(this->Makefile);
@ -1571,6 +1621,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. // Succeed if the version is suitable.
return suitable; return suitable;
} }

View File

@ -98,7 +98,8 @@ private:
bool CheckDirectory(std::string const& dir); bool CheckDirectory(std::string const& dir);
bool FindConfigFile(std::string const& dir, std::string& file); bool FindConfigFile(std::string const& dir, std::string& file);
bool CheckVersion(std::string const& config_file); bool CheckVersion(std::string const& config_file);
bool CheckVersionFile(std::string const& version_file); bool CheckVersionFile(std::string const& version_file,
std::string& result_version);
bool SearchPrefix(std::string const& prefix); bool SearchPrefix(std::string const& prefix);
bool SearchFrameworkPrefix(std::string const& prefix_in); bool SearchFrameworkPrefix(std::string const& prefix_in);
bool SearchAppBundlePrefix(std::string const& prefix_in); bool SearchAppBundlePrefix(std::string const& prefix_in);
@ -137,6 +138,8 @@ private:
std::vector<std::string> Names; std::vector<std::string> Names;
std::vector<std::string> Configs; std::vector<std::string> Configs;
std::set<std::string> IgnoredPaths; std::set<std::string> IgnoredPaths;
std::vector<std::string> ConsideredConfigFiles;
std::vector<std::string> ConsideredVersions;
}; };
#endif #endif