packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmRemoveCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmRemoveCommand.h"
13
14 // cmRemoveCommand
15 bool cmRemoveCommand
16 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
17 {
18   if(args.size() < 1)
19     {
20     return true;
21     }
22
23   const char* variable = args[0].c_str(); // VAR is always first
24   // get the old value
25   const char* cacheValue
26     = this->Makefile->GetDefinition(variable);
27
28   // if there is no old value then return
29   if (!cacheValue)
30     {
31     return true;
32     }
33
34   // expand the variable
35   std::vector<std::string> varArgsExpanded;
36   cmSystemTools::ExpandListArgument(cacheValue, varArgsExpanded);
37
38   // expand the args
39   // check for REMOVE(VAR v1 v2 ... vn)
40   std::vector<std::string> argsExpanded;
41   std::vector<std::string> temp;
42   for(unsigned int j = 1; j < args.size(); ++j)
43     {
44     temp.push_back(args[j]);
45     }
46   cmSystemTools::ExpandList(temp, argsExpanded);
47
48   // now create the new value
49   std::string value;
50   for(unsigned int j = 0; j < varArgsExpanded.size(); ++j)
51     {
52     int found = 0;
53     for(unsigned int k = 0; k < argsExpanded.size(); ++k)
54       {
55       if (varArgsExpanded[j] == argsExpanded[k])
56         {
57         found = 1;
58         break;
59         }
60       }
61     if (!found)
62       {
63       if (value.size())
64         {
65         value += ";";
66         }
67       value += varArgsExpanded[j];
68       }
69     }
70
71   // add the definition
72   this->Makefile->AddDefinition(variable, value.c_str());
73
74   return true;
75 }
76