/src/CMake/Source/cmRemoveCommand.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmRemoveCommand.h" |
4 | | |
5 | | #include "cmDiagnostics.h" |
6 | | #include "cmExecutionStatus.h" |
7 | | #include "cmList.h" |
8 | | #include "cmMakefile.h" |
9 | | #include "cmValue.h" |
10 | | |
11 | | // cmRemoveCommand |
12 | | bool cmRemoveCommand(std::vector<std::string> const& args, |
13 | | cmExecutionStatus& status) |
14 | 0 | { |
15 | 0 | cmMakefile& mf = status.GetMakefile(); |
16 | |
|
17 | 0 | mf.IssueDiagnostic(cmDiagnostics::CMD_DEPRECATED, |
18 | 0 | "The 'remove' command has been superseded. " |
19 | 0 | "Use 'list(REMOVE_ITEM)' instead."); |
20 | |
|
21 | 0 | if (args.empty()) { |
22 | 0 | return true; |
23 | 0 | } |
24 | | |
25 | 0 | std::string const& variable = args[0]; // VAR is always first |
26 | | // get the old value |
27 | 0 | cmValue cacheValue = mf.GetDefinition(variable); |
28 | | |
29 | | // if there is no old value then return |
30 | 0 | if (!cacheValue) { |
31 | 0 | return true; |
32 | 0 | } |
33 | | |
34 | | // expand the variable |
35 | 0 | cmList const varArgsExpanded{ *cacheValue }; |
36 | | |
37 | | // expand the args |
38 | | // check for REMOVE(VAR v1 v2 ... vn) |
39 | 0 | cmList const argsExpanded{ args.begin() + 1, args.end() }; |
40 | | |
41 | | // now create the new value |
42 | 0 | std::string value; |
43 | 0 | for (std::string const& varArgExpanded : varArgsExpanded) { |
44 | 0 | int found = 0; |
45 | 0 | for (std::string const& argExpanded : argsExpanded) { |
46 | 0 | if (varArgExpanded == argExpanded) { |
47 | 0 | found = 1; |
48 | 0 | break; |
49 | 0 | } |
50 | 0 | } |
51 | 0 | if (!found) { |
52 | 0 | if (!value.empty()) { |
53 | 0 | value += ";"; |
54 | 0 | } |
55 | 0 | value += varArgExpanded; |
56 | 0 | } |
57 | 0 | } |
58 | | |
59 | | // add the definition |
60 | 0 | mf.AddDefinition(variable, value); |
61 | |
|
62 | 0 | return true; |
63 | 0 | } |