From c389f8bb07e900d805ca3163f47b06e3dbe4303b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 25 Oct 2015 13:14:44 +0100 Subject: cmLocalGenerator: Port Find method away from GetGeneratorTarget Mirror the cmMakefile::FindTarget method. --- Source/cmGlobalGenerator.cxx | 39 ++++++++++++++++++++++++++++----------- Source/cmGlobalGenerator.h | 4 +++- Source/cmLocalGenerator.cxx | 16 +++++++++++++--- Source/cmLocalGenerator.h | 5 +++++ 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 5928fb5..d53f0e3 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1583,10 +1583,12 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo() } //---------------------------------------------------------------------------- -void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes, - cmLocalGenerator *lg) +void cmGlobalGenerator::CreateGeneratorTargets( + TargetTypes targetTypes, + cmMakefile *mf, + cmLocalGenerator *lg, + std::map const& importedMap) { - cmMakefile* mf = lg->GetMakefile(); if (targetTypes == AllTargets) { cmTargets& targets = mf->GetTargets(); @@ -1600,23 +1602,38 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes, } } + std::vector itgts = mf->GetImportedTargets(); + for(std::vector::const_iterator - j = mf->GetOwnedImportedTargets().begin(); - j != mf->GetOwnedImportedTargets().end(); ++j) + j = itgts.begin(); j != itgts.end(); ++j) { - cmGeneratorTarget* gt = new cmGeneratorTarget(*j, lg); - this->GeneratorTargets[*j] = gt; - lg->AddImportedGeneratorTarget(gt); + lg->AddImportedGeneratorTarget(importedMap.find(*j)->second); } } //---------------------------------------------------------------------------- void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes) { + std::map importedMap; + for(unsigned int i=0; i < this->Makefiles.size(); ++i) + { + cmMakefile* mf = this->Makefiles[i]; + for(std::vector::const_iterator + j = mf->GetOwnedImportedTargets().begin(); + j != mf->GetOwnedImportedTargets().end(); ++j) + { + cmGeneratorTarget* gt = + new cmGeneratorTarget(*j, this->LocalGenerators[i]); + this->GeneratorTargets[*j] = gt; + importedMap[*j] = gt; + } + } + // Construct per-target generator information. for(unsigned int i=0; i < this->LocalGenerators.size(); ++i) { - this->CreateGeneratorTargets(targetTypes, this->LocalGenerators[i]); + this->CreateGeneratorTargets(targetTypes, this->Makefiles[i], + this->LocalGenerators[i], importedMap); } } @@ -2240,11 +2257,11 @@ cmGeneratorTarget* cmGlobalGenerator::FindImportedGeneratorTargetImpl( for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { std::vector tgts = - this->LocalGenerators[i]->GetGeneratorTargets(); + this->LocalGenerators[i]->GetImportedGeneratorTargets(); for (std::vector::iterator it = tgts.begin(); it != tgts.end(); ++it) { - if ((*it)->GetName() == name && (*it)->IsImportedGloballyVisible()) + if ((*it)->IsImportedGloballyVisible() && (*it)->GetName() == name) { return *it; } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index c52b209..0057d61 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -485,7 +485,9 @@ private: // Per-target generator information. cmGeneratorTargetsType GeneratorTargets; friend class cmake; - void CreateGeneratorTargets(TargetTypes targetTypes, cmLocalGenerator* lg); + void CreateGeneratorTargets(TargetTypes targetTypes, cmMakefile* mf, + cmLocalGenerator* lg, + std::map const& importedMap); void CreateGeneratorTargets(TargetTypes targetTypes); void ClearGeneratorMembers(); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 1bc7f81..ec7c29f 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1821,11 +1821,21 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse(const std::string& name) const { - if (cmTarget *t = this->Makefile->FindTargetToUse(name)) + std::vector::const_iterator + imported = std::find_if(this->ImportedGeneratorTargets.begin(), + this->ImportedGeneratorTargets.end(), + NamedGeneratorTargetFinder(name)); + if(imported != this->ImportedGeneratorTargets.end()) { - return this->GetGlobalGenerator()->GetGeneratorTarget(t); + return *imported; } - return 0; + + if(cmGeneratorTarget* t = this->FindGeneratorTarget(name)) + { + return t; + } + + return this->GetGlobalGenerator()->FindGeneratorTarget(name); } //---------------------------------------------------------------------------- diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 7841d05..67383d7 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -120,6 +120,11 @@ public: return this->GeneratorTargets; } + const std::vector &GetImportedGeneratorTargets() const + { + return this->ImportedGeneratorTargets; + } + void AddGeneratorTarget(cmGeneratorTarget* gt); void AddImportedGeneratorTarget(cmGeneratorTarget* gt); -- cgit v0.12