1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #ifndef cmMacroCommand_h
13 #define cmMacroCommand_h
15 #include "cmCommand.h"
16 #include "cmFunctionBlocker.h"
18 class cmMacroFunctionBlocker : public cmFunctionBlocker
21 cmMacroFunctionBlocker() {this->Depth=0;}
22 virtual ~cmMacroFunctionBlocker() {}
23 virtual bool IsFunctionBlocked(const cmListFileFunction&,
26 virtual bool ShouldRemove(const cmListFileFunction&, cmMakefile &mf);
28 std::vector<std::string> Args;
29 std::vector<cmListFileFunction> Functions;
33 /// Starts macro() ... endmacro() block
34 class cmMacroCommand : public cmCommand
38 * This is a virtual constructor for the command.
40 virtual cmCommand* Clone()
42 return new cmMacroCommand;
46 * This is called when the command is first encountered in
47 * the CMakeLists.txt file.
49 virtual bool InitialPass(std::vector<std::string> const& args,
50 cmExecutionStatus &status);
53 * This determines if the command is invoked when in script mode.
55 virtual bool IsScriptable() const { return true; }
58 * The name of the command as specified in CMakeList.txt.
60 virtual const char* GetName() const { return "macro";}
63 * Succinct documentation.
65 virtual const char* GetTerseDocumentation() const
67 return "Start recording a macro for later invocation as a command.";
73 virtual const char* GetFullDocumentation() const
76 " macro(<name> [arg1 [arg2 [arg3 ...]]])\n"
77 " COMMAND1(ARGS ...)\n"
78 " COMMAND2(ARGS ...)\n"
81 "Define a macro named <name> that takes arguments named "
82 "arg1 arg2 arg3 (...). Commands listed after macro, "
83 "but before the matching endmacro, are not invoked until the macro "
84 "is invoked. When it is invoked, the commands recorded in the "
85 "macro are first modified by replacing formal parameters (${arg1}) "
86 "with the arguments passed, and then invoked as normal commands. In "
87 "addition to referencing the formal parameters you can reference "
88 "the values ${ARGC} which will be set to the number of arguments "
89 "passed into the function as well as ${ARGV0} ${ARGV1} ${ARGV2} "
91 "will have the actual values of the arguments passed in. This "
92 "facilitates creating macros with optional arguments. Additionally "
93 "${ARGV} holds the list of all arguments given to the macro and "
95 "holds the list of arguments past the last expected argument. "
96 "Note that the parameters to a macro and values such as ARGN "
97 "are not variables in the usual CMake sense. They are string "
98 "replacements much like the C preprocessor would do with a macro. "
99 "If you want true CMake variables and/or better CMake scope control "
100 "you should look at the function command."
102 "See the cmake_policy() command documentation for the behavior of "
103 "policies inside macros."
106 cmTypeMacro(cmMacroCommand, cmCommand);