Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmFunctionCommand.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
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
14
15 #include "cmCommand.h"
16 #include "cmFunctionBlocker.h"
17
18 class cmFunctionFunctionBlocker : public cmFunctionBlocker
19 {
20 public:
21   cmFunctionFunctionBlocker() {this->Depth=0;}
22   virtual ~cmFunctionFunctionBlocker() {}
23   virtual bool IsFunctionBlocked(const cmListFileFunction&, 
24                                  cmMakefile &mf,
25                                  cmExecutionStatus &);
26   virtual bool ShouldRemove(const cmListFileFunction&, cmMakefile &mf);
27   
28   std::vector<std::string> Args;
29   std::vector<cmListFileFunction> Functions;
30   int Depth;
31 };
32
33 /// Starts function() ... endfunction() block
34 class cmFunctionCommand : public cmCommand
35 {
36 public:
37   /**
38    * This is a virtual constructor for the command.
39    */
40   virtual cmCommand* Clone()
41     {
42     return new cmFunctionCommand;
43     }
44
45   /**
46    * This is called when the command is first encountered in
47    * the CMakeLists.txt file.
48    */
49   virtual bool InitialPass(std::vector<std::string> const& args,
50                            cmExecutionStatus &status);
51
52   /**
53    * This determines if the command is invoked when in script mode.
54    */
55   virtual bool IsScriptable() const { return true; }
56
57   /**
58    * The name of the command as specified in CMakeList.txt.
59    */
60   virtual const char* GetName() const { return "function";}
61
62   /**
63    * Succinct documentation.
64    */
65   virtual const char* GetTerseDocumentation() const
66     {
67     return "Start recording a function for later invocation as a command.";
68     }
69
70   /**
71    * More documentation.
72    */
73   virtual const char* GetFullDocumentation() const
74     {
75     return
76       "  function(<name> [arg1 [arg2 [arg3 ...]]])\n"
77       "    COMMAND1(ARGS ...)\n"
78       "    COMMAND2(ARGS ...)\n"
79       "    ...\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."
94       "\n"
95       "See the cmake_policy() command documentation for the behavior of "
96       "policies inside functions."
97       ;
98     }
99
100   cmTypeMacro(cmFunctionCommand, cmCommand);
101 };
102
103
104 #endif