Merge topic 'find_package-duplicate-search-paths'

919db25c cmFindPackageCommand: remove duplicate paths from error message
ebf18df5 cmFindPackageCommand: use iterators to loop over configurations
This commit is contained in:
Brad King 2016-06-16 09:46:42 -04:00 committed by CMake Topic Stage
commit ce62454019
2 changed files with 26 additions and 8 deletions

View File

@ -672,16 +672,18 @@ bool cmFindPackageCommand::HandlePackageMode()
// If there are files in ConsideredConfigs, it means that FooConfig.cmake // If there are files in ConsideredConfigs, it means that FooConfig.cmake
// have been found, but they didn't have appropriate versions. // have been found, but they didn't have appropriate versions.
else if (!this->ConsideredConfigs.empty()) { else if (!this->ConsideredConfigs.empty()) {
std::vector<ConfigFileInfo>::const_iterator duplicate_end =
cmRemoveDuplicates(this->ConsideredConfigs);
e << "Could not find a configuration file for package \"" << this->Name e << "Could not find a configuration file for package \"" << this->Name
<< "\" that " << "\" that "
<< (this->VersionExact ? "exactly matches" : "is compatible with") << (this->VersionExact ? "exactly matches" : "is compatible with")
<< " requested version \"" << this->Version << "\".\n" << " requested version \"" << this->Version << "\".\n"
<< "The following configuration files were considered but not " << "The following configuration files were considered but not "
"accepted:\n"; "accepted:\n";
for (std::vector<ConfigFileInfo>::size_type i = 0; for (std::vector<ConfigFileInfo>::const_iterator i =
i < this->ConsideredConfigs.size(); i++) { this->ConsideredConfigs.begin();
e << " " << this->ConsideredConfigs[i].filename i != duplicate_end; ++i) {
<< ", version: " << this->ConsideredConfigs[i].version << "\n"; e << " " << i->filename << ", version: " << i->version << "\n";
} }
} else { } else {
std::string requestedVersionString; std::string requestedVersionString;
@ -774,12 +776,13 @@ bool cmFindPackageCommand::HandlePackageMode()
std::string consideredVersions; std::string consideredVersions;
const char* sep = ""; const char* sep = "";
for (std::vector<ConfigFileInfo>::size_type i = 0; for (std::vector<ConfigFileInfo>::const_iterator i =
i < this->ConsideredConfigs.size(); i++) { this->ConsideredConfigs.begin();
i != this->ConsideredConfigs.end(); ++i) {
consideredConfigFiles += sep; consideredConfigFiles += sep;
consideredVersions += sep; consideredVersions += sep;
consideredConfigFiles += this->ConsideredConfigs[i].filename; consideredConfigFiles += i->filename;
consideredVersions += this->ConsideredConfigs[i].version; consideredVersions += i->version;
sep = ";"; sep = ";";
} }

View File

@ -160,6 +160,21 @@ private:
{ {
std::string filename; std::string filename;
std::string version; std::string version;
bool operator<(ConfigFileInfo const& rhs) const
{
return this->filename < rhs.filename;
}
bool operator==(ConfigFileInfo const& rhs) const
{
return this->filename == rhs.filename;
}
bool operator!=(ConfigFileInfo const& rhs) const
{
return !(*this == rhs);
}
}; };
std::vector<ConfigFileInfo> ConsideredConfigs; std::vector<ConfigFileInfo> ConsideredConfigs;
}; };