cmUnsetCommand.cxx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.empty() || args.size() > 2) {
  16. this->SetError("called with incorrect number of arguments");
  17. return false;
  18. }
  19. const char* variable = args[0].c_str();
  20. // unset(ENV{VAR})
  21. if (cmHasLiteralPrefix(variable, "ENV{") && strlen(variable) > 5) {
  22. // what is the variable name
  23. char* envVarName = new char[strlen(variable)];
  24. strncpy(envVarName, variable + 4, strlen(variable) - 5);
  25. envVarName[strlen(variable) - 5] = '\0';
  26. #ifdef CMAKE_BUILD_WITH_CMAKE
  27. cmSystemTools::UnsetEnv(envVarName);
  28. #endif
  29. delete[] envVarName;
  30. return true;
  31. }
  32. // unset(VAR)
  33. if (args.size() == 1) {
  34. this->Makefile->RemoveDefinition(variable);
  35. return true;
  36. }
  37. // unset(VAR CACHE)
  38. if ((args.size() == 2) && (args[1] == "CACHE")) {
  39. this->Makefile->RemoveCacheDefinition(variable);
  40. return true;
  41. }
  42. // unset(VAR PARENT_SCOPE)
  43. if ((args.size() == 2) && (args[1] == "PARENT_SCOPE")) {
  44. this->Makefile->RaiseScope(variable, CM_NULLPTR);
  45. return true;
  46. }
  47. // ERROR: second argument isn't CACHE or PARENT_SCOPE
  48. this->SetError("called with an invalid second argument");
  49. return false;
  50. }