cmForEachCommand.h 3.8 KB

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