cmForEachCommand.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 "cmForEachCommand.h"
  14. #include "cmCacheManager.h"
  15. bool cmForEachFunctionBlocker::
  16. IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
  17. cmMakefile &mf)
  18. {
  19. // at end of for each execute recorded commands
  20. if (!strcmp(name,"ENDFOREACH") && args[0] == m_Args[0])
  21. {
  22. std::string variable = "${";
  23. variable += m_Args[0];
  24. variable += "}";
  25. std::vector<std::string>::const_iterator j = m_Args.begin();
  26. ++j;
  27. for( ; j != m_Args.end(); ++j)
  28. {
  29. // perform string replace
  30. for(unsigned int c = 0; c < m_Commands.size(); ++c)
  31. {
  32. std::vector<std::string> newArgs;
  33. for (std::vector<std::string>::const_iterator k =
  34. m_CommandArguments[c].begin();
  35. k != m_CommandArguments[c].end(); ++k)
  36. {
  37. std::string tmps = *k;
  38. cmSystemTools::ReplaceString(tmps, variable.c_str(),
  39. j->c_str());
  40. newArgs.push_back(tmps);
  41. }
  42. // execute command
  43. mf.ExecuteCommand(m_Commands[c],newArgs);
  44. }
  45. }
  46. return false;
  47. }
  48. // record the command
  49. m_Commands.push_back(name);
  50. std::vector<std::string> newArgs;
  51. for(std::vector<std::string>::const_iterator j = args.begin();
  52. j != args.end(); ++j)
  53. {
  54. newArgs.push_back(*j);
  55. }
  56. m_CommandArguments.push_back(newArgs);
  57. // always return true
  58. return true;
  59. }
  60. bool cmForEachFunctionBlocker::
  61. ShouldRemove(const char *name, const std::vector<std::string> &args,
  62. cmMakefile &)
  63. {
  64. if (!strcmp(name,"ENDFOREACH") && args[0] == m_Args[0])
  65. {
  66. return true;
  67. }
  68. return false;
  69. }
  70. void cmForEachFunctionBlocker::
  71. ScopeEnded(cmMakefile &mf)
  72. {
  73. cmSystemTools::Error("The end of a CMakeLists file was reached with a FOREACH statement that was not closed properly. Within the directory: ",
  74. mf.GetCurrentDirectory());
  75. }
  76. bool cmForEachCommand::InitialPass(std::vector<std::string> const& argsIn)
  77. {
  78. std::vector<std::string> args;
  79. cmSystemTools::ExpandListArguments(argsIn, args);
  80. if(args.size() < 2 )
  81. {
  82. this->SetError("called with incorrect number of arguments");
  83. return false;
  84. }
  85. // create a function blocker
  86. cmForEachFunctionBlocker *f = new cmForEachFunctionBlocker();
  87. for(std::vector<std::string>::const_iterator j = args.begin();
  88. j != args.end(); ++j)
  89. {
  90. f->m_Args.push_back(*j);
  91. }
  92. m_Makefile->AddFunctionBlocker(f);
  93. return true;
  94. }