cmRemoveCommand.cxx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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. = m_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. std::vector<std::string> temp;
  33. temp.push_back(std::string(cacheValue));
  34. cmSystemTools::ExpandListArguments(temp, varArgsExpanded);
  35. // expand the args
  36. // check for REMOVE(VAR v1 v2 ... vn)
  37. std::vector<std::string> argsExpanded;
  38. std::vector<std::string> temp2;
  39. for(unsigned int j = 1; j < args.size(); ++j)
  40. {
  41. temp2.push_back(args[j]);
  42. }
  43. cmSystemTools::ExpandListArguments(temp2, argsExpanded);
  44. // now create the new value
  45. std::string value;
  46. for(unsigned int j = 1; j < varArgsExpanded.size(); ++j)
  47. {
  48. int found = 0;
  49. for(unsigned int k = 1; k < argsExpanded.size(); ++k)
  50. {
  51. if (varArgsExpanded[j] == argsExpanded[k])
  52. {
  53. found = 1;
  54. break;
  55. }
  56. }
  57. if (!found)
  58. {
  59. if (value.size())
  60. {
  61. value += ";";
  62. }
  63. value += varArgsExpanded[j];
  64. }
  65. }
  66. // add the definition
  67. m_Makefile->AddDefinition(variable, value.c_str());
  68. return true;
  69. }