Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmAddCustomCommandCommand.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 cmAddCustomCommandCommand_h
13 #define cmAddCustomCommandCommand_h
14
15 #include "cmCommand.h"
16 #include "cmDocumentGeneratorExpressions.h"
17
18 /** \class cmAddCustomCommandCommand
19  * \brief 
20  *
21  *  cmAddCustomCommandCommand defines a new command (rule) that can
22  *  be executed within the build process
23  *
24  */
25
26 class cmAddCustomCommandCommand : public cmCommand
27 {
28 public:
29   /**
30    * This is a virtual constructor for the command.
31    */
32   virtual cmCommand* Clone() 
33     {
34     return new cmAddCustomCommandCommand;
35     }
36
37   /**
38    * This is called when the command is first encountered in
39    * the CMakeLists.txt file.
40    */
41   virtual bool InitialPass(std::vector<std::string> const& args,
42                            cmExecutionStatus &status);
43
44   /**
45    * The name of the command as specified in CMakeList.txt.
46    */
47   virtual const char* GetName() const {return "add_custom_command";}
48   
49   /**
50    * Succinct documentation.
51    */
52   virtual const char* GetTerseDocumentation() const
53     {
54     return "Add a custom build rule to the generated build system.";
55     }
56   
57   /**
58    * More documentation.
59    */
60   virtual const char* GetFullDocumentation() const
61     {
62     return
63       "There are two main signatures for add_custom_command "
64       "The first signature is for adding a custom command "
65       "to produce an output.\n"
66       "  add_custom_command(OUTPUT output1 [output2 ...]\n"
67       "                     COMMAND command1 [ARGS] [args1...]\n"
68       "                     [COMMAND command2 [ARGS] [args2...] ...]\n"
69       "                     [MAIN_DEPENDENCY depend]\n"
70       "                     [DEPENDS [depends...]]\n"
71       "                     [IMPLICIT_DEPENDS <lang1> depend1 ...]\n"
72       "                     [WORKING_DIRECTORY dir]\n"
73       "                     [COMMENT comment] [VERBATIM] [APPEND])\n"
74       "This defines a command to generate specified OUTPUT file(s).  "
75       "A target created in the same directory (CMakeLists.txt file) that "
76       "specifies any output of the custom command as a source file is given "
77       "a rule to generate the file using the command at build time.  "
78       "Do not list the output in more than one independent target that may "
79       "build in parallel or the two instances of the rule may conflict "
80       "(instead use add_custom_target to drive the command and make the "
81       "other targets depend on that one).  "
82       "If an output name is a relative path it will be interpreted "
83       "relative to the build tree directory corresponding to the current "
84       "source directory. "
85       "Note that MAIN_DEPENDENCY is completely optional and is "
86       "used as a suggestion to visual studio about where to hang the "
87       "custom command. In makefile terms this creates a new target in the "
88       "following form:\n"
89       "  OUTPUT: MAIN_DEPENDENCY DEPENDS\n"
90       "          COMMAND\n"
91       "If more than one command is specified they will be executed in order. "
92       "The optional ARGS argument is for backward compatibility and will be "
93       "ignored.\n"
94       "The second signature adds a custom command to a target "
95       "such as a library or executable. This is useful for "
96       "performing an operation before or after building the target. "
97       "The command becomes part of the target and will only execute "
98       "when the target itself is built.  If the target is already built,"
99       " the command will not execute.\n"
100       "  add_custom_command(TARGET target\n"
101       "                     PRE_BUILD | PRE_LINK | POST_BUILD\n"
102       "                     COMMAND command1 [ARGS] [args1...]\n"
103       "                     [COMMAND command2 [ARGS] [args2...] ...]\n"
104       "                     [WORKING_DIRECTORY dir]\n"
105       "                     [COMMENT comment] [VERBATIM])\n"
106       "This defines a new command that will be associated with "
107       "building the specified target. When the command will "
108       "happen is determined by which of the following is specified:\n"
109       "  PRE_BUILD - run before all other dependencies\n"
110       "  PRE_LINK - run after other dependencies\n"
111       "  POST_BUILD - run after the target has been built\n"
112       "Note that the PRE_BUILD option is only supported on Visual "
113       "Studio 7 or later. For all other generators PRE_BUILD "
114       "will be treated as PRE_LINK.\n"
115       "If WORKING_DIRECTORY is specified the command will be executed "
116       "in the directory given. "
117       "If it is a relative path it will be interpreted relative to the "
118       "build tree directory corresponding to the current source directory. "
119       "If COMMENT is set, the value will be displayed as a "
120       "message before the commands are executed at build time. "
121       "If APPEND is specified the COMMAND and DEPENDS option values "
122       "are appended to the custom command for the first output specified. "
123       "There must have already been a previous call to this command with "
124       "the same output. The COMMENT, WORKING_DIRECTORY, and MAIN_DEPENDENCY "
125       "options are currently ignored when APPEND is given, "
126       "but may be used in the future."
127       "\n"
128       "If VERBATIM is given then all arguments to the commands will be "
129       "escaped properly for the build tool so that the invoked command "
130       "receives each argument unchanged.  "
131       "Note that one level of escapes is still used by the CMake language "
132       "processor before add_custom_command even sees the arguments. "
133       "Use of VERBATIM is recommended as it enables correct behavior. "
134       "When VERBATIM is not given the behavior is platform specific because "
135       "there is no protection of tool-specific special characters."
136       "\n"
137       "If the output of the custom command is not actually "
138       "created as a file on disk it should be marked as SYMBOLIC with "
139       "SET_SOURCE_FILES_PROPERTIES.\n"
140
141       "The IMPLICIT_DEPENDS option requests scanning of implicit "
142       "dependencies of an input file.  The language given specifies the "
143       "programming language whose corresponding dependency scanner should "
144       "be used.  Currently only C and CXX language scanners are supported. "
145       "Dependencies discovered from the scanning are added to those of "
146       "the custom command at build time.  Note that the IMPLICIT_DEPENDS "
147       "option is currently supported only for Makefile generators and "
148       "will be ignored by other generators."
149       "\n"
150       "If COMMAND specifies an executable target (created by "
151       "ADD_EXECUTABLE) it will automatically be replaced by the location "
152       "of the executable created at build time.  Additionally a "
153       "target-level dependency will be added so that the executable target "
154       "will be built before any target using this custom command.  However "
155       "this does NOT add a file-level dependency that would cause the "
156       "custom command to re-run whenever the executable is recompiled."
157       "\n"
158       "Arguments to COMMAND may use \"generator expressions\" with the "
159       "syntax \"$<...>\".  "
160       CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS
161       "References to target names in generator expressions imply "
162       "target-level dependencies, but NOT file-level dependencies.  "
163       "List target names with the DEPENDS option to add file dependencies."
164       "\n"
165       "The DEPENDS option specifies files on which the command depends.  "
166       "If any dependency is an OUTPUT of another custom command in the "
167       "same directory (CMakeLists.txt file) CMake automatically brings the "
168       "other custom command into the target in which this command is built.  "
169       "If DEPENDS is not specified the command will run whenever the OUTPUT "
170       "is missing; if the command does not actually create the OUTPUT then "
171       "the rule will always run.  "
172       "If DEPENDS specifies any target (created by an ADD_* command) "
173       "a target-level dependency is created to make sure the target is "
174       "built before any target using this custom command.  Additionally, "
175       "if the target is an executable or library a file-level dependency "
176       "is created to cause the custom command to re-run whenever the target "
177       "is recompiled.\n"
178       ;
179     }
180   
181   cmTypeMacro(cmAddCustomCommandCommand, cmCommand);
182 protected:
183   bool CheckOutputs(const std::vector<std::string>& outputs);
184 };
185
186
187 #endif