cmRemoveCommand.cxx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "cmRemoveCommand.h"
  11. // cmRemoveCommand
  12. bool cmRemoveCommand
  13. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  14. {
  15. if(args.size() < 1)
  16. {
  17. return true;
  18. }
  19. const char* variable = args[0].c_str(); // VAR is always first
  20. // get the old value
  21. const char* cacheValue
  22. = this->Makefile->GetDefinition(variable);
  23. // if there is no old value then return
  24. if (!cacheValue)
  25. {
  26. return true;
  27. }
  28. // expand the variable
  29. std::vector<std::string> varArgsExpanded;
  30. cmSystemTools::ExpandListArgument(cacheValue, varArgsExpanded);
  31. // expand the args
  32. // check for REMOVE(VAR v1 v2 ... vn)
  33. std::vector<std::string> argsExpanded;
  34. std::vector<std::string> temp;
  35. temp.insert(temp.end(), args.begin() + 1, args.end());
  36. cmSystemTools::ExpandList(temp, argsExpanded);
  37. // now create the new value
  38. std::string value;
  39. for(unsigned int j = 0; j < varArgsExpanded.size(); ++j)
  40. {
  41. int found = 0;
  42. for(unsigned int k = 0; k < argsExpanded.size(); ++k)
  43. {
  44. if (varArgsExpanded[j] == argsExpanded[k])
  45. {
  46. found = 1;
  47. break;
  48. }
  49. }
  50. if (!found)
  51. {
  52. if (value.size())
  53. {
  54. value += ";";
  55. }
  56. value += varArgsExpanded[j];
  57. }
  58. }
  59. // add the definition
  60. this->Makefile->AddDefinition(variable, value.c_str());
  61. return true;
  62. }