cmMacroCommand.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 cmMacroCommand_h
  11. #define cmMacroCommand_h
  12. #include "cmCommand.h"
  13. #include "cmFunctionBlocker.h"
  14. /** \class cmMacroFunctionBlocker
  15. * \brief subclass of function blocker
  16. *
  17. *
  18. */
  19. class cmMacroFunctionBlocker : public cmFunctionBlocker
  20. {
  21. public:
  22. cmMacroFunctionBlocker() {this->Depth=0;}
  23. virtual ~cmMacroFunctionBlocker() {}
  24. virtual bool IsFunctionBlocked(const cmListFileFunction&,
  25. cmMakefile &mf,
  26. cmExecutionStatus &);
  27. virtual bool ShouldRemove(const cmListFileFunction&, cmMakefile &mf);
  28. std::vector<std::string> Args;
  29. std::vector<cmListFileFunction> Functions;
  30. int Depth;
  31. };
  32. /** \class cmMacroCommand
  33. * \brief starts an if block
  34. *
  35. * cmMacroCommand starts an if block
  36. */
  37. class cmMacroCommand : public cmCommand
  38. {
  39. public:
  40. /**
  41. * This is a virtual constructor for the command.
  42. */
  43. virtual cmCommand* Clone()
  44. {
  45. return new cmMacroCommand;
  46. }
  47. /**
  48. * This is called when the command is first encountered in
  49. * the CMakeLists.txt file.
  50. */
  51. virtual bool InitialPass(std::vector<std::string> const& args,
  52. cmExecutionStatus &status);
  53. /**
  54. * This determines if the command is invoked when in script mode.
  55. */
  56. virtual bool IsScriptable() { return true; }
  57. /**
  58. * The name of the command as specified in CMakeList.txt.
  59. */
  60. virtual const char* GetName() { return "macro";}
  61. /**
  62. * Succinct documentation.
  63. */
  64. virtual const char* GetTerseDocumentation()
  65. {
  66. return "Start recording a macro for later invocation as a command.";
  67. }
  68. /**
  69. * More documentation.
  70. */
  71. virtual const char* GetFullDocumentation()
  72. {
  73. return
  74. " macro(<name> [arg1 [arg2 [arg3 ...]]])\n"
  75. " COMMAND1(ARGS ...)\n"
  76. " COMMAND2(ARGS ...)\n"
  77. " ...\n"
  78. " endmacro(<name>)\n"
  79. "Define a macro named <name> that takes arguments named "
  80. "arg1 arg2 arg3 (...). Commands listed after macro, "
  81. "but before the matching endmacro, are not invoked until the macro "
  82. "is invoked. When it is invoked, the commands recorded in the "
  83. "macro are first modified by replacing formal parameters (${arg1}) "
  84. "with the arguments passed, and then invoked as normal commands. In "
  85. "addition to referencing the formal parameters you can reference "
  86. "the values ${ARGC} which will be set to the number of arguments "
  87. "passed into the function as well as ${ARGV0} ${ARGV1} ${ARGV2} "
  88. "... which "
  89. "will have the actual values of the arguments passed in. This "
  90. "facilitates creating macros with optional arguments. Additionally "
  91. "${ARGV} holds the list of all arguments given to the macro and "
  92. "${ARGN} "
  93. "holds the list of argument past the last expected argument. "
  94. "Note that the parameters to a macro and values such as ARGN "
  95. "are not variables in the usual CMake sense. They are string "
  96. "replacements much like the c preprocessor would do with a "
  97. "macro. If you want true CMake variables you should look at "
  98. "the function command."
  99. "\n"
  100. "See the cmake_policy() command documentation for the behavior of "
  101. "policies inside macros."
  102. ;
  103. }
  104. cmTypeMacro(cmMacroCommand, cmCommand);
  105. };
  106. #endif