diff options
author | Brad King <brad.king@kitware.com> | 2008-02-11 18:35:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2008-02-11 18:35:39 (GMT) |
commit | ac0e58dcfbf17dec84b7bd848f6df0175f7d516b (patch) | |
tree | fd1cbb7b8fb4d6cec4fa467ea1e174b2b8535146 /Source/cmMakefile.cxx | |
parent | 739a463539946323b09e4c22f5fdd38395add1e1 (diff) | |
download | CMake-ac0e58dcfbf17dec84b7bd848f6df0175f7d516b.zip CMake-ac0e58dcfbf17dec84b7bd848f6df0175f7d516b.tar.gz CMake-ac0e58dcfbf17dec84b7bd848f6df0175f7d516b.tar.bz2 |
ENH: Enforce global target name uniqueness.
- Error if imported target is involved in conflict
- Error for non-imported target conflict unless
CMAKE_BACKWARDS_COMPATIBILITY <= 2.4
- Include OUTPUT_NAME property in error message
- Update add_executable and add_library command documentation
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r-- | Source/cmMakefile.cxx | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5e22b15..1f8c602 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3138,3 +3138,42 @@ cmTarget* cmMakefile::FindTargetToUse(const char* name) // Look for a target built in this project. return this->LocalGenerator->GetGlobalGenerator()->FindTarget(0, name); } + +//---------------------------------------------------------------------------- +bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg) +{ + if(cmTarget* existing = this->FindTargetToUse(name.c_str())) + { + // The name given conflicts with an existing target. Produce an + // error in a compatible way. + if(existing->IsImported()) + { + // Imported targets were not supported in previous versions. + // This is new code, so we can make it an error. + cmOStringStream e; + e << "cannot create target \"" << name + << "\" because an imported target with the same name already exists."; + msg = e.str(); + return false; + } + else if(!this->NeedBackwardsCompatibility(2, 4)) + { + // The conflict is with a non-imported target. Produce an error + // that tells the user how to work around the problem. + cmOStringStream e; + e << "cannot create target \"" << name + << "\" because another target with the same name already exists. " + << "Logical target names must be globally unique. " + << "Consider using the OUTPUT_NAME target property to create " + << "two targets with the same physical name while keeping logical " + << "names distinct.\n" + << "If you are building an older project it is possible that " + << "it violated this rule but was working accidentally. " + << "Set CMAKE_BACKWARDS_COMPATIBILITY to 2.4 or lower to disable " + << "this error."; + msg = e.str(); + return false; + } + } + return true; +} |