cmUnsetCommand.cxx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmUnsetCommand.h"
  11. // cmUnsetCommand
  12. bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
  13. cmExecutionStatus &)
  14. {
  15. if(args.size() < 1 || args.size() > 2)
  16. {
  17. this->SetError("called with incorrect number of arguments");
  18. return false;
  19. }
  20. const char* variable = args[0].c_str();
  21. // unset(ENV{VAR})
  22. if (!strncmp(variable,"ENV{",4) && strlen(variable) > 5)
  23. {
  24. // what is the variable name
  25. char *envVarName = new char [strlen(variable)];
  26. strncpy(envVarName,variable+4,strlen(variable)-5);
  27. envVarName[strlen(variable)-5] = '\0';
  28. #ifdef CMAKE_BUILD_WITH_CMAKE
  29. cmSystemTools::UnsetEnv(envVarName);
  30. #endif
  31. delete[] envVarName;
  32. return true;
  33. }
  34. // unset(VAR)
  35. else if (args.size() == 1)
  36. {
  37. this->Makefile->RemoveDefinition(variable);
  38. return true;
  39. }
  40. // unset(VAR CACHE)
  41. else if ((args.size() == 2) && (args[1] == "CACHE"))
  42. {
  43. this->Makefile->RemoveCacheDefinition(variable);
  44. return true;
  45. }
  46. // ERROR: second argument isn't CACHE
  47. else
  48. {
  49. this->SetError("called with an invalid second argument");
  50. return false;
  51. }
  52. }