From a67231ac114235f0af4673235c4c07fa896c8ab6 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 25 Oct 2015 12:43:00 +0100 Subject: [PATCH] cmTarget: Implement ALIAS in terms of name mapping Remove mapping to cmTarget. --- Source/cmAddExecutableCommand.cxx | 2 +- Source/cmAddLibraryCommand.cxx | 2 +- Source/cmGlobalGenerator.cxx | 10 ++++++---- Source/cmGlobalGenerator.h | 14 ++------------ Source/cmMakefile.cxx | 13 ++++++++----- Source/cmMakefile.h | 4 ++-- 6 files changed, 20 insertions(+), 25 deletions(-) diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx index 47f65926a..a84bb9dee 100644 --- a/Source/cmAddExecutableCommand.cxx +++ b/Source/cmAddExecutableCommand.cxx @@ -192,7 +192,7 @@ bool cmAddExecutableCommand this->SetError(e.str()); return false; } - this->Makefile->AddAlias(exename, aliasedTarget); + this->Makefile->AddAlias(exename, aliasedName); return true; } diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index e0adee39f..5296cbb36 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -314,7 +314,7 @@ bool cmAddLibraryCommand this->SetError(e.str()); return false; } - this->Makefile->AddAlias(libName, aliasedTarget); + this->Makefile->AddAlias(libName, aliasedName); return true; } diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 215d63fc1..47d254e32 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -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) { - TargetMap::const_iterator ai = this->AliasTargets.find(name); + std::map::const_iterator ai = + this->AliasTargets.find(name); if (ai != this->AliasTargets.end()) { - return ai->second; + return this->FindTargetImpl(ai->second); } } if (cmTarget* tgt = this->FindTargetImpl(name)) diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 5d4ce08a3..419cadaa9 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -254,7 +254,7 @@ public: cmTarget* FindTarget(const std::string& name, 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; /** Determine if a name resolves to a framework on disk or a built target @@ -427,17 +427,7 @@ protected: std::map BuildExportSets; std::map BuildExportExportSets; - // All targets in the entire project. -#if defined(CMAKE_BUILD_WITH_CMAKE) -#ifdef CMake_HAVE_CXX11_UNORDERED_MAP - typedef std::unordered_map TargetMap; -#else - typedef cmsys::hash_map TargetMap; -#endif -#else - typedef std::map TargetMap; -#endif - TargetMap AliasTargets; + std::map AliasTargets; cmTarget* FindTargetImpl(std::string const& name) const; cmTarget* FindImportedTargetImpl(std::string const& name) const; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d9d773d4b..8f72f67b5 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -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->GetGlobalGenerator()->AddAlias(lname, tgt); + this->AliasTargets[lname] = tgtName; + this->GetGlobalGenerator()->AddAlias(lname, tgtName); } cmTarget* cmMakefile::AddLibrary(const std::string& lname, @@ -4024,10 +4025,12 @@ cmTarget* cmMakefile::FindTarget(const std::string& name, { if (!excludeAliases) { - TargetMap::const_iterator i = this->AliasTargets.find(name); + std::map::const_iterator i = + this->AliasTargets.find(name); 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 ); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index f3dbb74e2..35dd3c659 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -283,7 +283,7 @@ public: cmTarget* AddLibrary(const std::string& libname, cmState::TargetType type, const std::vector &srcs, 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) /** @@ -790,7 +790,7 @@ protected: #else typedef std::map TargetMap; #endif - TargetMap AliasTargets; + std::map AliasTargets; std::vector SourceFiles; // Tests