cmRemoveCommand.cxx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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() < 2 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. const char* variable = args[0].c_str(); // VAR is always first
  23. // get the old value
  24. const char* cacheValue
  25. = m_Makefile->GetDefinition(variable);
  26. // expand the variable
  27. std::vector<std::string> varArgsExpanded;
  28. std::vector<std::string> temp;
  29. temp.push_back(std::string(cacheValue));
  30. cmSystemTools::ExpandListArguments(temp, varArgsExpanded);
  31. // expand the args
  32. // check for REMOVE(VAR v1 v2 ... vn)
  33. std::vector<std::string> argsExpanded;
  34. std::vector<std::string> temp2;
  35. for(unsigned int j = 1; j < args.size(); ++j)
  36. {
  37. temp2.push_back(args[j]);
  38. }
  39. cmSystemTools::ExpandListArguments(temp2, argsExpanded);
  40. // now create the new value
  41. std::string value;
  42. for(unsigned int j = 1; j < varArgsExpanded.size(); ++j)
  43. {
  44. int found = 0;
  45. for(unsigned int k = 1; 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. m_Makefile->AddDefinition(variable, value.c_str());
  64. return true;
  65. }