Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmUnsetCommand.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 "cmUnsetCommand.h"
13
14 // cmUnsetCommand
15 bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
16                                  cmExecutionStatus &)
17 {
18   if(args.size() < 1 || args.size() > 2)
19     {
20     this->SetError("called with incorrect number of arguments");
21     return false;
22     }
23
24   const char* variable = args[0].c_str();
25
26   // unset(ENV{VAR})
27   if (!strncmp(variable,"ENV{",4) && strlen(variable) > 5)
28     {
29     // what is the variable name
30     char *envVarName = new char [strlen(variable)];
31     strncpy(envVarName,variable+4,strlen(variable)-5);
32     envVarName[strlen(variable)-5] = '\0';
33
34 #ifdef CMAKE_BUILD_WITH_CMAKE
35     cmSystemTools::UnsetEnv(envVarName);
36 #endif
37     delete[] envVarName;
38     return true;
39     }
40   // unset(VAR)
41   else if (args.size() == 1)
42     {
43     this->Makefile->RemoveDefinition(variable);
44     return true;
45     }
46   // unset(VAR CACHE)
47   else if ((args.size() == 2) && (args[1] == "CACHE"))
48     {
49     this->Makefile->RemoveCacheDefinition(variable);
50     return true;
51     }
52   // ERROR: second argument isn't CACHE
53   else
54     {
55     this->SetError("called with an invalid second argument");
56     return false;
57     }
58 }
59