Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmUnsetCommand.cxx
blob0bc906b1c62a6b6a28fa4dc47c55c812d7e12fc7
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmUnsetCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-08-25 14:31:28 $
7 Version: $Revision: 1.1 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmUnsetCommand.h"
19 // cmUnsetCommand
20 bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
21 cmExecutionStatus &)
23 if(args.size() < 1 || args.size() > 2)
25 this->SetError("called with incorrect number of arguments");
26 return false;
29 const char* variable = args[0].c_str();
31 // unset(ENV{VAR})
32 if (!strncmp(variable,"ENV{",4) && strlen(variable) > 5)
34 // what is the variable name
35 char *envVarName = new char [strlen(variable)];
36 strncpy(envVarName,variable+4,strlen(variable)-5);
37 envVarName[strlen(variable)-5] = '\0';
39 #ifdef CMAKE_BUILD_WITH_CMAKE
40 cmSystemTools::UnsetEnv(envVarName);
41 #endif
42 delete[] envVarName;
43 return true;
45 // unset(VAR)
46 else if (args.size() == 1)
48 this->Makefile->RemoveDefinition(variable);
49 return true;
51 // unset(VAR CACHE)
52 else if ((args.size() == 2) && (args[1] == "CACHE"))
54 this->Makefile->RemoveCacheDefinition(variable);
55 return true;
57 // ERROR: second argument isn't CACHE
58 else
60 this->SetError("called with an invalid second argument");
61 return false;