From 0c97d32f7a592a768d614c19b3fd48eab245a2c4 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 25 Oct 2015 12:22:51 +0100 Subject: cmGlobalGenerator: Remove direct storage of targets Find the target by looping when needed. --- Source/cmGlobalGenerator.cxx | 80 +++++++++++++++++++------------ Source/cmGlobalGenerator.h | 7 ++- Source/cmGlobalVisualStudio8Generator.cxx | 16 ++++--- Source/cmGlobalXCodeGenerator.cxx | 15 ++++-- Source/cmMakefile.cxx | 7 +-- Source/cmTarget.cxx | 4 +- Source/cmTarget.h | 5 +- 7 files changed, 80 insertions(+), 54 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index d26cc34..e33e942 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1637,8 +1637,6 @@ void cmGlobalGenerator::ClearGeneratorMembers() this->ExportSets.clear(); this->TargetDependencies.clear(); - this->TotalTargets.clear(); - this->ImportedTargets.clear(); this->ProjectMap.clear(); this->RuleHashes.clear(); this->DirectoryContentMap.clear(); @@ -2180,6 +2178,41 @@ bool cmGlobalGenerator::IsAlias(const std::string& name) const return this->AliasTargets.find(name) != this->AliasTargets.end(); } +cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const +{ + for (unsigned int i = 0; i < this->Makefiles.size(); ++i) + { + cmTargets& tgts = this->Makefiles[i]->GetTargets(); + for (cmTargets::iterator it = tgts.begin(); it != tgts.end(); ++it) + { + if (it->second.GetName() == name) + { + return &it->second; + } + } + } + return 0; +} + +cmTarget* +cmGlobalGenerator::FindImportedTargetImpl(std::string const& name) const +{ + for (unsigned int i = 0; i < this->Makefiles.size(); ++i) + { + std::vector tgts = + this->Makefiles[i]->GetOwnedImportedTargets(); + for (std::vector::iterator it = tgts.begin(); + it != tgts.end(); ++it) + { + if ((*it)->GetName() == name && (*it)->IsImportedGloballyVisible()) + { + return *it; + } + } + } + return 0; +} + //---------------------------------------------------------------------------- cmTarget* cmGlobalGenerator::FindTarget(const std::string& name, @@ -2193,17 +2226,11 @@ cmGlobalGenerator::FindTarget(const std::string& name, return ai->second; } } - TargetMap::const_iterator i = this->TotalTargets.find ( name ); - if ( i != this->TotalTargets.end() ) - { - return i->second; - } - i = this->ImportedTargets.find(name); - if ( i != this->ImportedTargets.end() ) + if (cmTarget* tgt = this->FindTargetImpl(name)) { - return i->second; + return tgt; } - return 0; + return this->FindImportedTargetImpl(name); } //---------------------------------------------------------------------------- @@ -2622,18 +2649,6 @@ cmGlobalGenerator::GetTargetDirectDepends(cmGeneratorTarget const* target) return this->TargetDependencies[target]; } -void cmGlobalGenerator::AddTarget(cmTarget* t) -{ - if(t->IsImported()) - { - this->ImportedTargets[t->GetName()] = t; - } - else - { - this->TotalTargets[t->GetName()] = t; - } -} - bool cmGlobalGenerator::IsReservedTarget(std::string const& name) { // The following is a list of targets reserved @@ -2939,17 +2954,20 @@ void cmGlobalGenerator::WriteSummary() fname += "/TargetDirectories.txt"; cmGeneratedFileStream fout(fname.c_str()); - // Generate summary information files for each target. - for(TargetMap::const_iterator ti = - this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti) + for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - if ((ti->second)->GetType() == cmState::INTERFACE_LIBRARY) + std::vector tgts = + this->LocalGenerators[i]->GetGeneratorTargets(); + for (std::vector::iterator it = tgts.begin(); + it != tgts.end(); ++it) { - continue; + if ((*it)->GetType() == cmState::INTERFACE_LIBRARY) + { + continue; + } + this->WriteSummary(*it); + fout << (*it)->GetSupportDirectory() << "\n"; } - cmGeneratorTarget* gt = this->GetGeneratorTarget(ti->second); - this->WriteSummary(gt); - fout << gt->GetSupportDirectory() << "\n"; } } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 18f5329..5d4ce08 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -280,8 +280,6 @@ public: std::set const& GetDirectoryContent(std::string const& dir, bool needDisk = true); - void AddTarget(cmTarget* t); - static bool IsReservedTarget(std::string const& name); virtual const char* GetAllTargetName() const { return "ALL_BUILD"; } @@ -439,9 +437,10 @@ protected: #else typedef std::map TargetMap; #endif - TargetMap TotalTargets; TargetMap AliasTargets; - TargetMap ImportedTargets; + + cmTarget* FindTargetImpl(std::string const& name) const; + cmTarget* FindImportedTargetImpl(std::string const& name) const; const char* GetPredefinedTargetsFolder(); virtual bool UseFolderProperty(); diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index b771f11..f08ab5a 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -354,14 +354,18 @@ void cmGlobalVisualStudio8Generator::AddExtraIDETargets() cmGlobalVisualStudio7Generator::AddExtraIDETargets(); if(this->AddCheckTarget()) { - // All targets depend on the build-system check target. - for(TargetMap::const_iterator - ti = this->TotalTargets.begin(); - ti != this->TotalTargets.end(); ++ti) + for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - if(ti->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET) + std::vector tgts = + this->LocalGenerators[i]->GetGeneratorTargets(); + // All targets depend on the build-system check target. + for(std::vector::iterator ti = tgts.begin(); + ti != tgts.end(); ++ti) { - ti->second->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET); + if((*ti)->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) + { + (*ti)->Target->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET); + } } } } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 42f9758..6d4fc1f 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1362,12 +1362,17 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen, //---------------------------------------------------------------------------- void cmGlobalXCodeGenerator::ForceLinkerLanguages() { - // This makes sure all targets link using the proper language. - for(TargetMap::const_iterator - ti = this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti) + for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - cmGeneratorTarget* gt = this->GetGeneratorTarget(ti->second); - this->ForceLinkerLanguage(gt); + std::vector tgts = + this->LocalGenerators[i]->GetGeneratorTargets(); + // All targets depend on the build-system check target. + for(std::vector::const_iterator ti = tgts.begin(); + ti != tgts.end(); ++ti) + { + // This makes sure all targets link using the proper language. + this->ForceLinkerLanguage(*ti); + } } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 3bf34e2..d9d773d 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2096,7 +2096,6 @@ cmMakefile::AddNewTarget(cmState::TargetType type, const std::string& name) cmTarget& target = it->second; target.SetType(type, name); target.SetMakefile(this); - this->GetGlobalGenerator()->AddTarget(&it->second); return &it->second; } @@ -4183,15 +4182,11 @@ cmMakefile::AddImportedTarget(const std::string& name, // Create the target. cmsys::auto_ptr target(new cmTarget); target->SetType(type, name); - target->MarkAsImported(); + target->MarkAsImported(global); target->SetMakefile(this); // Add to the set of available imported targets. this->ImportedTargets[name] = target.get(); - if(global) - { - this->GetGlobalGenerator()->AddTarget(target.get()); - } // Transfer ownership to this cmMakefile object. this->ImportedTargetsOwned.push_back(target.get()); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index c887fc8..f0f404c 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -63,6 +63,7 @@ cmTarget::cmTarget() this->IsAndroid = false; this->IsApple = false; this->IsImportedTarget = false; + this->ImportedGloballyVisible = false; this->BuildInterfaceIncludesAppended = false; } @@ -1505,9 +1506,10 @@ void cmTarget::CheckProperty(const std::string& prop, } //---------------------------------------------------------------------------- -void cmTarget::MarkAsImported() +void cmTarget::MarkAsImported(bool global) { this->IsImportedTarget = true; + this->ImportedGloballyVisible = global; } //---------------------------------------------------------------------------- diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 541e850..62e10f4 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -75,7 +75,7 @@ public: */ void SetType(cmState::TargetType f, const std::string& name); - void MarkAsImported(); + void MarkAsImported(bool global = false); ///! Set/Get the name of the target const std::string& GetName() const {return this->Name;} @@ -186,6 +186,8 @@ public: void CheckProperty(const std::string& prop, cmMakefile* context) const; bool IsImported() const {return this->IsImportedTarget;} + bool IsImportedGloballyVisible() const + { return this->ImportedGloballyVisible; } // Get the properties cmPropertyMap &GetProperties() const { return this->Properties; } @@ -349,6 +351,7 @@ private: bool IsAndroid; bool IsApple; bool IsImportedTarget; + bool ImportedGloballyVisible; bool BuildInterfaceIncludesAppended; #if defined(_WIN32) && !defined(__CYGWIN__) bool LinkLibrariesForVS6Analyzed; -- cgit v0.12