cmForEachCommand.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #ifndef cmForEachCommand_h
  14. #define cmForEachCommand_h
  15. #include "cmCommand.h"
  16. #include "cmFunctionBlocker.h"
  17. #include "cmListFileCache.h"
  18. /** \class cmForEachFunctionBlocker
  19. * \brief subclass of function blocker
  20. *
  21. *
  22. */
  23. class cmForEachFunctionBlocker : public cmFunctionBlocker
  24. {
  25. public:
  26. cmForEachFunctionBlocker() {this->Executing = false; Depth = 0;}
  27. virtual ~cmForEachFunctionBlocker() {}
  28. virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
  29. cmMakefile &mf);
  30. virtual bool ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf);
  31. virtual void ScopeEnded(cmMakefile &mf);
  32. std::vector<std::string> Args;
  33. std::vector<cmListFileFunction> Functions;
  34. bool Executing;
  35. private:
  36. int Depth;
  37. };
  38. /** \class cmForEachCommand
  39. * \brief starts an if block
  40. *
  41. * cmForEachCommand starts an if block
  42. */
  43. class cmForEachCommand : public cmCommand
  44. {
  45. public:
  46. /**
  47. * This is a virtual constructor for the command.
  48. */
  49. virtual cmCommand* Clone()
  50. {
  51. return new cmForEachCommand;
  52. }
  53. /**
  54. * This is called when the command is first encountered in
  55. * the CMakeLists.txt file.
  56. */
  57. virtual bool InitialPass(std::vector<std::string> const& args);
  58. /**
  59. * This determines if the command is invoked when in script mode.
  60. */
  61. virtual bool IsScriptable() { return true; }
  62. /**
  63. * The name of the command as specified in CMakeList.txt.
  64. */
  65. virtual const char* GetName() { return "FOREACH";}
  66. /**
  67. * Succinct documentation.
  68. */
  69. virtual const char* GetTerseDocumentation()
  70. {
  71. return "Evaluate a group of commands for each value in a list.";
  72. }
  73. /**
  74. * More documentation.
  75. */
  76. virtual const char* GetFullDocumentation()
  77. {
  78. return
  79. " FOREACH(loop_var arg1 arg2 ...)\n"
  80. " COMMAND1(ARGS ...)\n"
  81. " COMMAND2(ARGS ...)\n"
  82. " ...\n"
  83. " ENDFOREACH(loop_var)\n"
  84. " FOREACH(loop_var RANGE total)\n"
  85. " FOREACH(loop_var RANGE start stop [step])\n"
  86. "All commands between FOREACH and the matching ENDFOREACH are recorded "
  87. "without being invoked. Once the ENDFOREACH is evaluated, the "
  88. "recorded list of commands is invoked once for each argument listed "
  89. "in the original FOREACH command. Before each iteration of the loop "
  90. "\"${loop_var}\" will be set as a variable with "
  91. "the current value in the list.\n"
  92. "Foreach can also iterate over a generated range of numbers. "
  93. "There are three types of this iteration:\n"
  94. "* When specifying single number, the range will have elements "
  95. "0 to \"total\".\n"
  96. "* When specifying two numbers, the range will have elements from "
  97. "the first number to the second number.\n"
  98. "* The third optional number is the increment used to iterate from "
  99. "the first number to the second number.";
  100. }
  101. cmTypeMacro(cmForEachCommand, cmCommand);
  102. };
  103. #endif