cmRemoveCommand.cxx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmRemoveCommand.h"
  14. // cmRemoveCommand
  15. bool cmRemoveCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 1)
  18. {
  19. return true;
  20. }
  21. const char* variable = args[0].c_str(); // VAR is always first
  22. // get the old value
  23. const char* cacheValue
  24. = this->Makefile->GetDefinition(variable);
  25. // if there is no old value then return
  26. if (!cacheValue)
  27. {
  28. return true;
  29. }
  30. // expand the variable
  31. std::vector<std::string> varArgsExpanded;
  32. cmSystemTools::ExpandListArgument(cacheValue, varArgsExpanded);
  33. // expand the args
  34. // check for REMOVE(VAR v1 v2 ... vn)
  35. std::vector<std::string> argsExpanded;
  36. std::vector<std::string> temp;
  37. for(unsigned int j = 1; j < args.size(); ++j)
  38. {
  39. temp.push_back(args[j]);
  40. }
  41. cmSystemTools::ExpandList(temp, argsExpanded);
  42. // now create the new value
  43. std::string value;
  44. for(unsigned int j = 0; j < varArgsExpanded.size(); ++j)
  45. {
  46. int found = 0;
  47. for(unsigned int k = 0; k < argsExpanded.size(); ++k)
  48. {
  49. if (varArgsExpanded[j] == argsExpanded[k])
  50. {
  51. found = 1;
  52. break;
  53. }
  54. }
  55. if (!found)
  56. {
  57. if (value.size())
  58. {
  59. value += ";";
  60. }
  61. value += varArgsExpanded[j];
  62. }
  63. }
  64. // add the definition
  65. this->Makefile->AddDefinition(variable, value.c_str());
  66. return true;
  67. }