cmForEachCommand.h 3.6 KB

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