diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-07-12 07:14:31 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2013-08-02 13:21:00 (GMT) |
commit | 370bf554151a1b272baf62a0ce9823cf9995116e (patch) | |
tree | 8f0a75a9894691c2b56588c3be4b090bf07a1558 /Source/cmMakefile.cxx | |
parent | b341bf2178e3923636735ae1df53a33e5857df7d (diff) | |
download | CMake-370bf554151a1b272baf62a0ce9823cf9995116e.zip CMake-370bf554151a1b272baf62a0ce9823cf9995116e.tar.gz CMake-370bf554151a1b272baf62a0ce9823cf9995116e.tar.bz2 |
Add the ALIAS target concept for libraries and executables.
* The ALIAS name must match a validity regex.
* Executables and libraries may be aliased.
* An ALIAS acts immutable. It can not be used as the lhs
of target_link_libraries or other commands.
* An ALIAS can be used with add_custom_command, add_custom_target,
and add_test in the same way regular targets can.
* The target of an ALIAS can be retrieved with the ALIASED_TARGET
target property.
* An ALIAS does not appear in the generated buildsystem. It
is kept separate from cmMakefile::Targets for that reason.
* A target may have multiple aliases.
* An ALIAS target may not itself have an alias.
* An IMPORTED target may not have an alias.
* An ALIAS may not be exported or imported.
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r-- | Source/cmMakefile.cxx | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 1920cc0..aae92dd 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -41,6 +41,7 @@ #include <stack> #include <ctype.h> // for isspace +#include <assert.h> class cmMakefile::Internals { @@ -1437,6 +1438,14 @@ void cmMakefile::AddLinkDirectoryForTarget(const char *target, cmTargets::iterator i = this->Targets.find(target); if ( i != this->Targets.end()) { + if(this->IsAlias(target)) + { + cmOStringStream e; + e << "ALIAS target \"" << target << "\" " + << "may not be linked into another target."; + this->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); + return; + } i->second.AddLinkDirectory( d ); } else @@ -1923,6 +1932,12 @@ void cmMakefile::AddGlobalLinkInformation(const char* name, cmTarget& target) } +void cmMakefile::AddAlias(const char* lname, cmTarget *tgt) +{ + this->AliasTargets[lname] = tgt; + this->LocalGenerator->GetGlobalGenerator()->AddAlias(lname, tgt); +} + cmTarget* cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type, const std::vector<std::string> &srcs, bool excludeFromAll) @@ -3758,8 +3773,17 @@ const char* cmMakefile::GetFeature(const char* feature, const char* config) return 0; } -cmTarget* cmMakefile::FindTarget(const char* name) +cmTarget* cmMakefile::FindTarget(const char* name, bool excludeAliases) { + if (!excludeAliases) + { + std::map<std::string, cmTarget*>::iterator i + = this->AliasTargets.find(name); + if (i != this->AliasTargets.end()) + { + return i->second; + } + } cmTargets& tgts = this->GetTargets(); cmTargets::iterator i = tgts.find ( name ); @@ -4184,7 +4208,7 @@ cmMakefile::AddImportedTarget(const char* name, cmTarget::TargetType type, } //---------------------------------------------------------------------------- -cmTarget* cmMakefile::FindTargetToUse(const char* name) +cmTarget* cmMakefile::FindTargetToUse(const char* name, bool excludeAliases) { // Look for an imported target. These take priority because they // are more local in scope and do not have to be globally unique. @@ -4196,15 +4220,25 @@ cmTarget* cmMakefile::FindTargetToUse(const char* name) } // Look for a target built in this directory. - if(cmTarget* t = this->FindTarget(name)) + if(cmTarget* t = this->FindTarget(name, excludeAliases)) { return t; } // Look for a target built in this project. - return this->LocalGenerator->GetGlobalGenerator()->FindTarget(0, name); + return this->LocalGenerator->GetGlobalGenerator()->FindTarget(0, name, + excludeAliases); } +//---------------------------------------------------------------------------- +bool cmMakefile::IsAlias(const char *name) +{ + if (this->AliasTargets.find(name) != this->AliasTargets.end()) + return true; + return this->GetLocalGenerator()->GetGlobalGenerator()->IsAlias(name); +} + +//---------------------------------------------------------------------------- cmGeneratorTarget* cmMakefile::FindGeneratorTargetToUse(const char* name) { cmTarget *t = this->FindTargetToUse(name); @@ -4215,6 +4249,14 @@ cmGeneratorTarget* cmMakefile::FindGeneratorTargetToUse(const char* name) bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg, bool isCustom) { + if(this->IsAlias(name.c_str())) + { + cmOStringStream e; + e << "cannot create target \"" << name + << "\" because an alias with the same name already exists."; + msg = e.str(); + return false; + } if(cmTarget* existing = this->FindTargetToUse(name.c_str())) { // The name given conflicts with an existing target. Produce an |