summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2020-05-28 12:52:57 (GMT)
committerBrad King <brad.king@kitware.com>2020-05-28 16:56:59 (GMT)
commit1eca5993e21eeefa8a0c8d4e41b559c1d32c495a (patch)
tree224acb0649ebc5e8198b311950f7f30da4c606f0 /Source
parent04b9b2b5f363d792719238046a18aac867be3254 (diff)
downloadCMake-1eca5993e21eeefa8a0c8d4e41b559c1d32c495a.zip
CMake-1eca5993e21eeefa8a0c8d4e41b559c1d32c495a.tar.gz
CMake-1eca5993e21eeefa8a0c8d4e41b559c1d32c495a.tar.bz2
ALIAS target: cannot overwrite an existing target
Fixes: #19616
Diffstat (limited to 'Source')
-rw-r--r--Source/cmAddLibraryCommand.cxx11
-rw-r--r--Source/cmPolicies.h4
2 files changed, 14 insertions, 1 deletions
diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx
index f443fc6..d79c04f 100644
--- a/Source/cmAddLibraryCommand.cxx
+++ b/Source/cmAddLibraryCommand.cxx
@@ -9,6 +9,7 @@
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
+#include "cmPolicies.h"
#include "cmState.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
@@ -181,6 +182,16 @@ bool cmAddLibraryCommand(std::vector<std::string> const& args,
return false;
}
+ if (mf.GetPolicyStatus(cmPolicies::CMP0107) == cmPolicies::NEW) {
+ // Make sure the target does not already exist.
+ if (mf.FindTargetToUse(libName)) {
+ status.SetError(cmStrCat(
+ "cannot create ALIAS target \"", libName,
+ "\" because another target with the same name already exists."));
+ return false;
+ }
+ }
+
std::string const& aliasedName = *s;
if (mf.IsAlias(aliasedName)) {
status.SetError(cmStrCat("cannot create ALIAS target \"", libName,
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 4abfa1f..4dff1d8 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -316,7 +316,9 @@ class cmMakefile;
SELECT(POLICY, CMP0105, "Device link step uses the link options.", 3, 18, \
0, cmPolicies::WARN) \
SELECT(POLICY, CMP0106, "The Documentation module is removed.", 3, 18, 0, \
- cmPolicies::WARN)
+ cmPolicies::WARN) \
+ SELECT(POLICY, CMP0107, "An ALIAS target cannot overwrite another target.", \
+ 3, 18, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \