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 cmFunctionCommand_h
13 #define cmFunctionCommand_h
15 #include "cmCommand.h"
16 #include "cmFunctionBlocker.h"
18 class cmFunctionFunctionBlocker : public cmFunctionBlocker
21 cmFunctionFunctionBlocker() {this->Depth=0;}
22 virtual ~cmFunctionFunctionBlocker() {}
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 function() ... endfunction() block
34 class cmFunctionCommand : public cmCommand
38 * This is a virtual constructor for the command.
40 virtual cmCommand* Clone()
42 return new cmFunctionCommand;
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 "function";}
63 * Succinct documentation.
65 virtual const char* GetTerseDocumentation() const
67 return "Start recording a function for later invocation as a command.";
73 virtual const char* GetFullDocumentation() const
76 " function(<name> [arg1 [arg2 [arg3 ...]]])\n"
77 " COMMAND1(ARGS ...)\n"
78 " COMMAND2(ARGS ...)\n"
80 " endfunction(<name>)\n"
81 "Define a function named <name> that takes arguments named "
82 "arg1 arg2 arg3 (...). Commands listed after function, but before "
83 "the matching endfunction, are not invoked until the function "
84 "is invoked. When it is invoked, the commands recorded in the "
85 "function 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 variable ARGC which will be set to the number of arguments "
89 "passed into the function as well as ARGV0 ARGV1 ARGV2 ... which "
90 "will have the actual values of the arguments passed in. This "
91 "facilitates creating functions with optional arguments. Additionally "
92 "ARGV holds the list of all arguments given to the function and ARGN "
93 "holds the list of argument past the last expected argument."
95 "See the cmake_policy() command documentation for the behavior of "
96 "policies inside functions."
100 cmTypeMacro(cmFunctionCommand, cmCommand);