cmForEachCommand.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmForEachCommand_h
  11. #define cmForEachCommand_h
  12. #include "cmCommand.h"
  13. #include "cmFunctionBlocker.h"
  14. #include "cmListFileCache.h"
  15. /** \class cmForEachFunctionBlocker
  16. * \brief subclass of function blocker
  17. *
  18. *
  19. */
  20. class cmForEachFunctionBlocker : public cmFunctionBlocker
  21. {
  22. public:
  23. cmForEachFunctionBlocker() {this->Depth = 0;}
  24. virtual ~cmForEachFunctionBlocker() {}
  25. virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
  26. cmMakefile &mf,
  27. cmExecutionStatus &);
  28. virtual bool ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf);
  29. std::vector<std::string> Args;
  30. std::vector<cmListFileFunction> Functions;
  31. private:
  32. int Depth;
  33. };
  34. /** \class cmForEachCommand
  35. * \brief starts an if block
  36. *
  37. * cmForEachCommand starts an if block
  38. */
  39. class cmForEachCommand : public cmCommand
  40. {
  41. public:
  42. /**
  43. * This is a virtual constructor for the command.
  44. */
  45. virtual cmCommand* Clone()
  46. {
  47. return new cmForEachCommand;
  48. }
  49. /**
  50. * This is called when the command is first encountered in
  51. * the CMakeLists.txt file.
  52. */
  53. virtual bool InitialPass(std::vector<std::string> const& args,
  54. cmExecutionStatus &status);
  55. /**
  56. * This determines if the command is invoked when in script mode.
  57. */
  58. virtual bool IsScriptable() { return true; }
  59. /**
  60. * The name of the command as specified in CMakeList.txt.
  61. */
  62. virtual const char* GetName() { return "foreach";}
  63. /**
  64. * Succinct documentation.
  65. */
  66. virtual const char* GetTerseDocumentation()
  67. {
  68. return "Evaluate a group of commands for each value in a list.";
  69. }
  70. /**
  71. * More documentation.
  72. */
  73. virtual const char* GetFullDocumentation()
  74. {
  75. return
  76. " foreach(loop_var arg1 arg2 ...)\n"
  77. " COMMAND1(ARGS ...)\n"
  78. " COMMAND2(ARGS ...)\n"
  79. " ...\n"
  80. " endforeach(loop_var)\n"
  81. "All commands between foreach and the matching endforeach are recorded "
  82. "without being invoked. Once the endforeach is evaluated, the "
  83. "recorded list of commands is invoked once for each argument listed "
  84. "in the original foreach command. Before each iteration of the loop "
  85. "\"${loop_var}\" will be set as a variable with "
  86. "the current value in the list.\n"
  87. " foreach(loop_var RANGE total)\n"
  88. " foreach(loop_var RANGE start stop [step])\n"
  89. "Foreach can also iterate over a generated range of numbers. "
  90. "There are three types of this iteration:\n"
  91. "* When specifying single number, the range will have elements "
  92. "0 to \"total\".\n"
  93. "* When specifying two numbers, the range will have elements from "
  94. "the first number to the second number.\n"
  95. "* The third optional number is the increment used to iterate from "
  96. "the first number to the second number."
  97. "\n"
  98. " foreach(loop_var IN [LISTS [list1 [...]]]\n"
  99. " [ITEMS [item1 [...]]])\n"
  100. "Iterates over a precise list of items. "
  101. "The LISTS option names list-valued variables to be traversed, "
  102. "including empty elements (an empty string is a zero-length list). "
  103. "The ITEMS option ends argument parsing and includes all arguments "
  104. "following it in the iteration."
  105. ;
  106. }
  107. cmTypeMacro(cmForEachCommand, cmCommand);
  108. private:
  109. bool HandleInMode(std::vector<std::string> const& args);
  110. };
  111. #endif