cmTarget: Implement ALIAS in terms of name mapping

Remove mapping to cmTarget.
This commit is contained in:
Stephen Kelly 2015-10-25 12:43:00 +01:00
parent d566f39a64
commit a67231ac11
6 changed files with 20 additions and 25 deletions

View File

@ -192,7 +192,7 @@ bool cmAddExecutableCommand
this->SetError(e.str()); this->SetError(e.str());
return false; return false;
} }
this->Makefile->AddAlias(exename, aliasedTarget); this->Makefile->AddAlias(exename, aliasedName);
return true; return true;
} }

View File

@ -314,7 +314,7 @@ bool cmAddLibraryCommand
this->SetError(e.str()); this->SetError(e.str());
return false; return false;
} }
this->Makefile->AddAlias(libName, aliasedTarget); this->Makefile->AddAlias(libName, aliasedName);
return true; return true;
} }

View File

@ -2167,9 +2167,10 @@ cmGlobalGenerator::FindLocalGenerator(const std::string& start_dir) const
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmGlobalGenerator::AddAlias(const std::string& name, cmTarget *tgt) void cmGlobalGenerator::AddAlias(const std::string& name,
std::string const& tgtName)
{ {
this->AliasTargets[name] = tgt; this->AliasTargets[name] = tgtName;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -2220,10 +2221,11 @@ cmGlobalGenerator::FindTarget(const std::string& name,
{ {
if (!excludeAliases) if (!excludeAliases)
{ {
TargetMap::const_iterator ai = this->AliasTargets.find(name); std::map<std::string, std::string>::const_iterator ai =
this->AliasTargets.find(name);
if (ai != this->AliasTargets.end()) if (ai != this->AliasTargets.end())
{ {
return ai->second; return this->FindTargetImpl(ai->second);
} }
} }
if (cmTarget* tgt = this->FindTargetImpl(name)) if (cmTarget* tgt = this->FindTargetImpl(name))

View File

@ -254,7 +254,7 @@ public:
cmTarget* FindTarget(const std::string& name, cmTarget* FindTarget(const std::string& name,
bool excludeAliases = false) const; bool excludeAliases = false) const;
void AddAlias(const std::string& name, cmTarget *tgt); void AddAlias(const std::string& name, const std::string& tgtName);
bool IsAlias(const std::string& name) const; bool IsAlias(const std::string& name) const;
/** Determine if a name resolves to a framework on disk or a built target /** Determine if a name resolves to a framework on disk or a built target
@ -427,17 +427,7 @@ protected:
std::map<std::string, cmExportBuildFileGenerator*> BuildExportSets; std::map<std::string, cmExportBuildFileGenerator*> BuildExportSets;
std::map<std::string, cmExportBuildFileGenerator*> BuildExportExportSets; std::map<std::string, cmExportBuildFileGenerator*> BuildExportExportSets;
// All targets in the entire project. std::map<std::string, std::string> AliasTargets;
#if defined(CMAKE_BUILD_WITH_CMAKE)
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
typedef std::unordered_map<std::string, cmTarget*> TargetMap;
#else
typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
#endif
#else
typedef std::map<std::string,cmTarget *> TargetMap;
#endif
TargetMap AliasTargets;
cmTarget* FindTargetImpl(std::string const& name) const; cmTarget* FindTargetImpl(std::string const& name) const;
cmTarget* FindImportedTargetImpl(std::string const& name) const; cmTarget* FindImportedTargetImpl(std::string const& name) const;

View File

@ -2036,10 +2036,11 @@ void cmMakefile::AddGlobalLinkInformation(const std::string& name,
} }
void cmMakefile::AddAlias(const std::string& lname, cmTarget *tgt) void cmMakefile::AddAlias(const std::string& lname,
std::string const& tgtName)
{ {
this->AliasTargets[lname] = tgt; this->AliasTargets[lname] = tgtName;
this->GetGlobalGenerator()->AddAlias(lname, tgt); this->GetGlobalGenerator()->AddAlias(lname, tgtName);
} }
cmTarget* cmMakefile::AddLibrary(const std::string& lname, cmTarget* cmMakefile::AddLibrary(const std::string& lname,
@ -4024,10 +4025,12 @@ cmTarget* cmMakefile::FindTarget(const std::string& name,
{ {
if (!excludeAliases) if (!excludeAliases)
{ {
TargetMap::const_iterator i = this->AliasTargets.find(name); std::map<std::string, std::string>::const_iterator i =
this->AliasTargets.find(name);
if (i != this->AliasTargets.end()) if (i != this->AliasTargets.end())
{ {
return i->second; cmTargets::iterator ai = this->Targets.find(i->second);
return &ai->second;
} }
} }
cmTargets::iterator i = this->Targets.find( name ); cmTargets::iterator i = this->Targets.find( name );

View File

@ -283,7 +283,7 @@ public:
cmTarget* AddLibrary(const std::string& libname, cmState::TargetType type, cmTarget* AddLibrary(const std::string& libname, cmState::TargetType type,
const std::vector<std::string> &srcs, const std::vector<std::string> &srcs,
bool excludeFromAll = false); bool excludeFromAll = false);
void AddAlias(const std::string& libname, cmTarget *tgt); void AddAlias(const std::string& libname, const std::string& tgt);
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
/** /**
@ -790,7 +790,7 @@ protected:
#else #else
typedef std::map<std::string, cmTarget*> TargetMap; typedef std::map<std::string, cmTarget*> TargetMap;
#endif #endif
TargetMap AliasTargets; std::map<std::string, std::string> AliasTargets;
std::vector<cmSourceFile*> SourceFiles; std::vector<cmSourceFile*> SourceFiles;
// Tests // Tests