From 1f8f58a0b9a7883aedf7a4bcb185e9784db4f13b Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Sun, 6 May 2012 16:32:10 +0200 Subject: [PATCH] fix #13195: avoid multiple mentions of found packages Now before adding a package to the list of found or not-found packages, the package is remvoed from both lists before. Alex --- Source/cmFindPackageCommand.cxx | 94 +++++++++++++++++++++------------ Source/cmFindPackageCommand.h | 2 +- 2 files changed, 62 insertions(+), 34 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 4f9ba7eb2..be47f95d4 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -1368,41 +1368,73 @@ bool cmFindPackageCommand::ReadListFile(const char* f, PolicyScopeRule psr) } //---------------------------------------------------------------------------- -void cmFindPackageCommand::AppendToProperty(const char* propertyName) +void cmFindPackageCommand::AppendToFoundProperty(bool found) { - std::string propertyValue; - const char *prop = - this->Makefile->GetCMakeInstance()->GetProperty(propertyName); - if (prop && *prop) + std::vector foundContents; + const char *foundProp = + this->Makefile->GetCMakeInstance()->GetProperty("PACKAGES_FOUND"); + if (foundProp && *foundProp) { - propertyValue = prop; + std::string tmp = foundProp; - std::vector contents; - cmSystemTools::ExpandListArgument(propertyValue, contents, false); + cmSystemTools::ExpandListArgument(tmp, foundContents, false); + std::vector::iterator nameIt = std::find( + foundContents.begin(), foundContents.end(), this->Name); + if(nameIt != foundContents.end()) + { + foundContents.erase(nameIt); + } + } - bool alreadyInserted = false; - for(std::vector::const_iterator it = contents.begin(); - it != contents.end(); ++ it ) + std::vector notFoundContents; + const char *notFoundProp = + this->Makefile->GetCMakeInstance()->GetProperty("PACKAGES_NOT_FOUND"); + if (notFoundProp && *notFoundProp) + { + std::string tmp = notFoundProp; + + cmSystemTools::ExpandListArgument(tmp, notFoundContents, false); + std::vector::iterator nameIt = std::find( + notFoundContents.begin(), notFoundContents.end(), this->Name); + if(nameIt != notFoundContents.end()) { - if (*it == this->Name) - { - alreadyInserted = true; - break; - } - } - if (!alreadyInserted) - { - propertyValue += ";"; - propertyValue += this->Name; + notFoundContents.erase(nameIt); } } + + if(found) + { + foundContents.push_back(this->Name); + } 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; iMakefile->GetCMakeInstance()->SetProperty("PACKAGES_FOUND", + tmp.c_str()); + + tmp = ""; + sep = ""; + for(size_t i=0; iMakefile->GetCMakeInstance()->SetProperty("PACKAGES_NOT_FOUND", + tmp.c_str()); +} //---------------------------------------------------------------------------- void cmFindPackageCommand::AppendSuccessInformation() @@ -1413,14 +1445,10 @@ void cmFindPackageCommand::AppendSuccessInformation() const char* upperResult = this->Makefile->GetDefinition(upperFound.c_str()); const char* result = this->Makefile->GetDefinition(found.c_str()); - if ((cmSystemTools::IsOn(result)) || (cmSystemTools::IsOn(upperResult))) - { - this->AppendToProperty("PACKAGES_FOUND"); - } - else - { - this->AppendToProperty("PACKAGES_NOT_FOUND"); - } + bool packageFound = ((cmSystemTools::IsOn(result)) + || (cmSystemTools::IsOn(upperResult))); + + this->AppendToFoundProperty(packageFound); // Record whether the find was quiet or not, so this can be used // e.g. in FeatureSummary.cmake diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index edb70a6a1..c3801220d 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -69,7 +69,7 @@ protected: virtual void GenerateDocumentation(); private: void AppendSuccessInformation(); - void AppendToProperty(const char* propertyName); + void AppendToFoundProperty(bool found); void SetModuleVariables(const std::string& components); bool FindModule(bool& found); void AddFindDefinition(const char* var, const char* val);