1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmFunctionCommand.h,v $
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.3 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmFunctionCommand_h
18 #define cmFunctionCommand_h
20 #include "cmCommand.h"
21 #include "cmFunctionBlocker.h"
23 /** \class cmFunctionFunctionBlocker
24 * \brief subclass of function blocker
28 class cmFunctionFunctionBlocker
: public cmFunctionBlocker
31 cmFunctionFunctionBlocker() {this->Depth
=0;}
32 virtual ~cmFunctionFunctionBlocker() {}
33 virtual bool IsFunctionBlocked(const cmListFileFunction
&,
36 virtual bool ShouldRemove(const cmListFileFunction
&, cmMakefile
&mf
);
37 virtual void ScopeEnded(cmMakefile
&mf
);
39 std::vector
<std::string
> Args
;
40 std::vector
<cmListFileFunction
> Functions
;
44 /** \class cmFunctionCommand
45 * \brief starts an if block
47 * cmFunctionCommand starts an if block
49 class cmFunctionCommand
: public cmCommand
53 * This is a virtual constructor for the command.
55 virtual cmCommand
* Clone()
57 return new cmFunctionCommand
;
61 * This is called when the command is first encountered in
62 * the CMakeLists.txt file.
64 virtual bool InitialPass(std::vector
<std::string
> const& args
,
65 cmExecutionStatus
&status
);
68 * This determines if the command is invoked when in script mode.
70 virtual bool IsScriptable() { return true; }
73 * The name of the command as specified in CMakeList.txt.
75 virtual const char* GetName() { return "function";}
78 * Succinct documentation.
80 virtual const char* GetTerseDocumentation()
82 return "Start recording a function for later invocation as a command.";
88 virtual const char* GetFullDocumentation()
91 " function(<name> [arg1 [arg2 [arg3 ...]]])\n"
92 " COMMAND1(ARGS ...)\n"
93 " COMMAND2(ARGS ...)\n"
95 " endfunction(<name>)\n"
96 "Define a function named <name> that takes arguments named "
97 "arg1 arg2 arg3 (...). Commands listed after function, but before "
98 "the matching endfunction, are not invoked until the function "
99 "is invoked. When it is invoked, the commands recorded in the "
100 "function are first modified by replacing formal parameters (${arg1}) "
101 "with the arguments passed, and then invoked as normal commands. In "
102 "addition to referencing the formal parameters you can reference "
103 "the variable ARGC which will be set to the number of arguments "
104 "passed into the function as well as ARGV0 ARGV1 ARGV2 ... which "
105 "will have the actual values of the arguments passed in. This "
106 "facilitates creating functions with optional arguments. Additionally "
107 "ARGV holds the list of all arguments given to the function and ARGN "
108 "holds the list of argument pass the last expected argument.";
111 cmTypeMacro(cmFunctionCommand
, cmCommand
);