cmRemoveCommand.cxx 1.54 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
Ken Martin's avatar
Ken Martin committed
3 4
#include "cmRemoveCommand.h"

5 6 7 8 9
#include "cmMakefile.h"
#include "cmSystemTools.h"

class cmExecutionStatus;

Ken Martin's avatar
Ken Martin committed
10
// cmRemoveCommand
11 12
bool cmRemoveCommand::InitialPass(std::vector<std::string> const& args,
                                  cmExecutionStatus&)
Ken Martin's avatar
Ken Martin committed
13
{
14
  if (args.empty()) {
Ken Martin's avatar
Ken Martin committed
15
    return true;
16
  }
Ken Martin's avatar
Ken Martin committed
17 18 19

  const char* variable = args[0].c_str(); // VAR is always first
  // get the old value
20
  const char* cacheValue = this->Makefile->GetDefinition(variable);
Ken Martin's avatar
Ken Martin committed
21

Ken Martin's avatar
Ken Martin committed
22
  // if there is no old value then return
23
  if (!cacheValue) {
Ken Martin's avatar
Ken Martin committed
24
    return true;
25
  }
26

Ken Martin's avatar
Ken Martin committed
27 28
  // expand the variable
  std::vector<std::string> varArgsExpanded;
29
  cmSystemTools::ExpandListArgument(cacheValue, varArgsExpanded);
30

Ken Martin's avatar
Ken Martin committed
31
  // expand the args
32
  // check for REMOVE(VAR v1 v2 ... vn)
Ken Martin's avatar
Ken Martin committed
33
  std::vector<std::string> argsExpanded;
34
  std::vector<std::string> temp;
35
  temp.insert(temp.end(), args.begin() + 1, args.end());
36
  cmSystemTools::ExpandList(temp, argsExpanded);
37

Ken Martin's avatar
Ken Martin committed
38 39
  // now create the new value
  std::string value;
40
  for (unsigned int j = 0; j < varArgsExpanded.size(); ++j) {
Ken Martin's avatar
Ken Martin committed
41
    int found = 0;
42 43
    for (unsigned int k = 0; k < argsExpanded.size(); ++k) {
      if (varArgsExpanded[j] == argsExpanded[k]) {
Ken Martin's avatar
Ken Martin committed
44 45 46
        found = 1;
        break;
      }
47 48 49
    }
    if (!found) {
      if (!value.empty()) {
Ken Martin's avatar
Ken Martin committed
50 51
        value += ";";
      }
52
      value += varArgsExpanded[j];
Ken Martin's avatar
Ken Martin committed
53
    }
54
  }
55

Ken Martin's avatar
Ken Martin committed
56
  // add the definition
57
  this->Makefile->AddDefinition(variable, value.c_str());
Ken Martin's avatar
Ken Martin committed
58 59 60

  return true;
}