cmMacroCommand.h 3.7 KB

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