1
0

cmForEachCommand.h 3.5 KB

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