cmRemoveCommand.cxx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. for(unsigned int j = 1; j < args.size(); ++j)
  36. {
  37. temp.push_back(args[j]);
  38. }
  39. cmSystemTools::ExpandList(temp, argsExpanded);
  40. // now create the new value
  41. std::string value;
  42. for(unsigned int j = 0; j < varArgsExpanded.size(); ++j)
  43. {
  44. int found = 0;
  45. for(unsigned int k = 0; k < argsExpanded.size(); ++k)
  46. {
  47. if (varArgsExpanded[j] == argsExpanded[k])
  48. {
  49. found = 1;
  50. break;
  51. }
  52. }
  53. if (!found)
  54. {
  55. if (value.size())
  56. {
  57. value += ";";
  58. }
  59. value += varArgsExpanded[j];
  60. }
  61. }
  62. // add the definition
  63. this->Makefile->AddDefinition(variable, value.c_str());
  64. return true;
  65. }