diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2020-03-20 14:21:32 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2020-03-26 12:20:45 (GMT) |
commit | 0cd20e8f62328b6e3ae750dc253473cf00e05adb (patch) | |
tree | aafff71c6dbaab8a05a0ab84459117142b557b18 /Source | |
parent | 66e0b312c0985493adeeda63d1dc7815cc0fe364 (diff) | |
download | CMake-0cd20e8f62328b6e3ae750dc253473cf00e05adb.zip CMake-0cd20e8f62328b6e3ae750dc253473cf00e05adb.tar.gz CMake-0cd20e8f62328b6e3ae750dc253473cf00e05adb.tar.bz2 |
export(): raise an error on multiple calls with same FILE
Fixes: 20472
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmExportCommand.cxx | 23 | ||||
-rw-r--r-- | Source/cmPolicies.h | 5 |
2 files changed, 27 insertions, 1 deletions
diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index e49c174..f31759d 100644 --- a/Source/cmExportCommand.cxx +++ b/Source/cmExportCommand.cxx @@ -24,6 +24,7 @@ #include "cmMessageType.h" #include "cmPolicies.h" #include "cmStateTypes.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmTarget.h" @@ -183,6 +184,28 @@ bool cmExportCommand(std::vector<std::string> const& args, return false; } + // if cmExportBuildFileGenerator is already defined for the file + // and APPEND is not specified, if CMP0103 is OLD ignore previous definition + // else raise an error + if (gg->GetExportedTargetsFile(fname) != nullptr) { + switch (mf.GetPolicyStatus(cmPolicies::CMP0103)) { + case cmPolicies::WARN: + mf.IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0103), '\n', + "export() command already specified for the file\n ", + arguments.Filename, "\nDid you miss 'APPEND' keyword?")); + CM_FALLTHROUGH; + case cmPolicies::OLD: + break; + default: + status.SetError(cmStrCat("command already specified for the file\n ", + arguments.Filename, + "\nDid you miss 'APPEND' keyword?")); + return false; + } + } + // Setup export file generation. std::unique_ptr<cmExportBuildFileGenerator> ebfg = nullptr; if (android) { diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 1366ff0..d3daad8 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -305,7 +305,10 @@ class cmMakefile; 17, 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0102, \ "mark_as_advanced() does nothing if a cache entry does not exist.", \ - 3, 17, 0, cmPolicies::WARN) + 3, 17, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0103, \ + "multiple export() with same FILE without APPEND is not allowed.", \ + 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) \ |