Merge topic 'FixMultipleResultsInFeatureSummary'

1f8f58a fix #13195: avoid multiple mentions of found packages
This commit is contained in:
David Cole 2012-05-08 14:33:13 -04:00 committed by CMake Topic Stage
commit 41d3dfc1ef
2 changed files with 62 additions and 34 deletions

View File

@ -1368,42 +1368,74 @@ bool cmFindPackageCommand::ReadListFile(const char* f, PolicyScopeRule psr)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmFindPackageCommand::AppendToProperty(const char* propertyName) void cmFindPackageCommand::AppendToFoundProperty(bool found)
{ {
std::string propertyValue; std::vector<std::string> foundContents;
const char *prop = const char *foundProp =
this->Makefile->GetCMakeInstance()->GetProperty(propertyName); this->Makefile->GetCMakeInstance()->GetProperty("PACKAGES_FOUND");
if (prop && *prop) if (foundProp && *foundProp)
{ {
propertyValue = prop; std::string tmp = foundProp;
std::vector<std::string> contents; cmSystemTools::ExpandListArgument(tmp, foundContents, false);
cmSystemTools::ExpandListArgument(propertyValue, contents, false); std::vector<std::string>::iterator nameIt = std::find(
foundContents.begin(), foundContents.end(), this->Name);
if(nameIt != foundContents.end())
{
foundContents.erase(nameIt);
}
}
bool alreadyInserted = false; std::vector<std::string> notFoundContents;
for(std::vector<std::string>::const_iterator it = contents.begin(); const char *notFoundProp =
it != contents.end(); ++ it ) this->Makefile->GetCMakeInstance()->GetProperty("PACKAGES_NOT_FOUND");
if (notFoundProp && *notFoundProp)
{ {
if (*it == this->Name) std::string tmp = notFoundProp;
cmSystemTools::ExpandListArgument(tmp, notFoundContents, false);
std::vector<std::string>::iterator nameIt = std::find(
notFoundContents.begin(), notFoundContents.end(), this->Name);
if(nameIt != notFoundContents.end())
{ {
alreadyInserted = true; notFoundContents.erase(nameIt);
break;
} }
} }
if (!alreadyInserted)
if(found)
{ {
propertyValue += ";"; foundContents.push_back(this->Name);
propertyValue += this->Name;
}
} }
else else
{ {
propertyValue = this->Name; notFoundContents.push_back(this->Name);
} }
this->Makefile->GetCMakeInstance()->SetProperty(propertyName,
propertyValue.c_str());
std::string tmp;
const char* sep ="";
for(size_t i=0; i<foundContents.size(); i++)
{
tmp += sep;
tmp += foundContents[i];
sep = ";";
} }
this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_FOUND",
tmp.c_str());
tmp = "";
sep = "";
for(size_t i=0; i<notFoundContents.size(); i++)
{
tmp += sep;
tmp += notFoundContents[i];
sep = ";";
}
this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_NOT_FOUND",
tmp.c_str());
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmFindPackageCommand::AppendSuccessInformation() void cmFindPackageCommand::AppendSuccessInformation()
{ {
@ -1413,14 +1445,10 @@ void cmFindPackageCommand::AppendSuccessInformation()
const char* upperResult = this->Makefile->GetDefinition(upperFound.c_str()); const char* upperResult = this->Makefile->GetDefinition(upperFound.c_str());
const char* result = this->Makefile->GetDefinition(found.c_str()); const char* result = this->Makefile->GetDefinition(found.c_str());
if ((cmSystemTools::IsOn(result)) || (cmSystemTools::IsOn(upperResult))) bool packageFound = ((cmSystemTools::IsOn(result))
{ || (cmSystemTools::IsOn(upperResult)));
this->AppendToProperty("PACKAGES_FOUND");
} this->AppendToFoundProperty(packageFound);
else
{
this->AppendToProperty("PACKAGES_NOT_FOUND");
}
// Record whether the find was quiet or not, so this can be used // Record whether the find was quiet or not, so this can be used
// e.g. in FeatureSummary.cmake // e.g. in FeatureSummary.cmake

View File

@ -69,7 +69,7 @@ protected:
virtual void GenerateDocumentation(); virtual void GenerateDocumentation();
private: private:
void AppendSuccessInformation(); void AppendSuccessInformation();
void AppendToProperty(const char* propertyName); void AppendToFoundProperty(bool found);
void SetModuleVariables(const std::string& components); void SetModuleVariables(const std::string& components);
bool FindModule(bool& found); bool FindModule(bool& found);
void AddFindDefinition(const char* var, const char* val); void AddFindDefinition(const char* var, const char* val);