cmSourceFilesRemoveCommand.cxx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "cmSourceFilesRemoveCommand.h"
  14. // cmSourceFilesRemoveCommand
  15. bool cmSourceFilesRemoveCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. const char* versionValue
  18. = m_Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
  19. if (versionValue && atof(versionValue) > 1.2)
  20. {
  21. this->SetError("The SOURCE_FILES_REMOVE command has been deprecated in CMake version 1.4. You should use the REMOVE command instead.\n");
  22. return false;
  23. }
  24. if(args.size() < 2 )
  25. {
  26. this->SetError("called with incorrect number of arguments");
  27. return false;
  28. }
  29. const char* variable = args[0].c_str(); // VAR is always first
  30. // get the old value
  31. const char* cacheValue
  32. = m_Makefile->GetDefinition(variable);
  33. // expand the variable
  34. std::vector<std::string> varArgsExpanded;
  35. std::vector<std::string> temp;
  36. temp.push_back(std::string(cacheValue));
  37. cmSystemTools::ExpandListArguments(temp, varArgsExpanded);
  38. // expand the args
  39. // check for REMOVE(VAR v1 v2 ... vn)
  40. std::vector<std::string> argsExpanded;
  41. std::vector<std::string> temp2;
  42. for(unsigned int j = 1; j < args.size(); ++j)
  43. {
  44. temp2.push_back(args[j]);
  45. }
  46. cmSystemTools::ExpandListArguments(temp2, argsExpanded);
  47. // now create the new value
  48. std::string value;
  49. for(unsigned int j = 0; j < varArgsExpanded.size(); ++j)
  50. {
  51. int found = 0;
  52. for(unsigned int k = 0; k < argsExpanded.size(); ++k)
  53. {
  54. if (varArgsExpanded[j] == argsExpanded[k])
  55. {
  56. found = 1;
  57. break;
  58. }
  59. }
  60. if (!found)
  61. {
  62. if (value.size())
  63. {
  64. value += ";";
  65. }
  66. value += varArgsExpanded[j];
  67. }
  68. }
  69. // add the definition
  70. m_Makefile->AddDefinition(variable, value.c_str());
  71. return true;
  72. }