cmMacroCommand.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 cmMacroCommand_h
  14. #define cmMacroCommand_h
  15. #include "cmCommand.h"
  16. #include "cmFunctionBlocker.h"
  17. /** \class cmMacroFunctionBlocker
  18. * \brief subclass of function blocker
  19. *
  20. *
  21. */
  22. class cmMacroFunctionBlocker : public cmFunctionBlocker
  23. {
  24. public:
  25. cmMacroFunctionBlocker() {}
  26. virtual ~cmMacroFunctionBlocker() {}
  27. virtual bool IsFunctionBlocked(const cmListFileFunction&, cmMakefile &mf);
  28. virtual bool ShouldRemove(const cmListFileFunction&, cmMakefile &mf);
  29. virtual void ScopeEnded(cmMakefile &mf);
  30. std::vector<std::string> Args;
  31. std::vector<cmListFileFunction> Functions;
  32. };
  33. /** \class cmMacroCommand
  34. * \brief starts an if block
  35. *
  36. * cmMacroCommand starts an if block
  37. */
  38. class cmMacroCommand : public cmCommand
  39. {
  40. public:
  41. /**
  42. * This is a virtual constructor for the command.
  43. */
  44. virtual cmCommand* Clone()
  45. {
  46. return new cmMacroCommand;
  47. }
  48. /**
  49. * This is called when the command is first encountered in
  50. * the CMakeLists.txt file.
  51. */
  52. virtual bool InitialPass(std::vector<std::string> const& args);
  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 variable ARGC which will be set to the number of arguments "
  87. "passed into the function as well as ARGV0 ARGV1 ARGV2 ... which "
  88. "will have the actual values of the arguments passed in. This "
  89. "facilitates creating macros with optional arguments. Additionally "
  90. "ARGV holds the list of all arguments given to the macro and ARGN "
  91. "holds the list of argument pass the last expected argument.";
  92. }
  93. cmTypeMacro(cmMacroCommand, cmCommand);
  94. };
  95. #endif