cmSourceFilesRemoveCommand.cxx 2.4 KB

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