cmGlobalGenerator: Remove direct storage of targets

Find the target by looping when needed.
This commit is contained in:
Stephen Kelly 2015-10-25 12:22:51 +01:00
parent 383bfd9543
commit 0c97d32f7a
7 changed files with 80 additions and 54 deletions

View File

@ -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<cmTarget*> tgts =
this->Makefiles[i]->GetOwnedImportedTargets();
for (std::vector<cmTarget*>::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() )
if (cmTarget* tgt = this->FindTargetImpl(name))
{
return i->second;
return tgt;
}
i = this->ImportedTargets.find(name);
if ( i != this->ImportedTargets.end() )
{
return i->second;
}
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<cmGeneratorTarget*> tgts =
this->LocalGenerators[i]->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::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";
}
}

View File

@ -280,8 +280,6 @@ public:
std::set<std::string> 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<std::string,cmTarget *> 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();

View File

@ -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<cmGeneratorTarget*> tgts =
this->LocalGenerators[i]->GetGeneratorTargets();
// All targets depend on the build-system check target.
for(std::vector<cmGeneratorTarget*>::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);
}
}
}
}

View File

@ -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<cmGeneratorTarget*> tgts =
this->LocalGenerators[i]->GetGeneratorTargets();
// All targets depend on the build-system check target.
for(std::vector<cmGeneratorTarget*>::const_iterator ti = tgts.begin();
ti != tgts.end(); ++ti)
{
// This makes sure all targets link using the proper language.
this->ForceLinkerLanguage(*ti);
}
}
}

View File

@ -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<cmTarget> 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());

View File

@ -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;
}
//----------------------------------------------------------------------------

View File

@ -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;