resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmRemoveCommand.cxx
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #include "cmRemoveCommand.h"
4
5 #include "cmExecutionStatus.h"
6 #include "cmMakefile.h"
7 #include "cmStringAlgorithms.h"
8 #include "cmValue.h"
9
10 // cmRemoveCommand
11 bool cmRemoveCommand(std::vector<std::string> const& args,
12                      cmExecutionStatus& status)
13 {
14   if (args.empty()) {
15     return true;
16   }
17
18   std::string const& variable = args[0]; // VAR is always first
19   // get the old value
20   cmValue cacheValue = status.GetMakefile().GetDefinition(variable);
21
22   // if there is no old value then return
23   if (!cacheValue) {
24     return true;
25   }
26
27   // expand the variable
28   std::vector<std::string> const varArgsExpanded = cmExpandedList(*cacheValue);
29
30   // expand the args
31   // check for REMOVE(VAR v1 v2 ... vn)
32   std::vector<std::string> const argsExpanded =
33     cmExpandedLists(args.begin() + 1, args.end());
34
35   // now create the new value
36   std::string value;
37   for (std::string const& varArgExpanded : varArgsExpanded) {
38     int found = 0;
39     for (std::string const& argExpanded : argsExpanded) {
40       if (varArgExpanded == argExpanded) {
41         found = 1;
42         break;
43       }
44     }
45     if (!found) {
46       if (!value.empty()) {
47         value += ";";
48       }
49       value += varArgExpanded;
50     }
51   }
52
53   // add the definition
54   status.GetMakefile().AddDefinition(variable, value);
55
56   return true;
57 }