Imported Upstream version 2.8.12.2
[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       "                                      [<lang2> depend2] ...]\n"
73       "                     [WORKING_DIRECTORY dir]\n"
74       "                     [COMMENT comment] [VERBATIM] [APPEND])\n"
75       "This defines a command to generate specified OUTPUT file(s).  "
76       "A target created in the same directory (CMakeLists.txt file) that "
77       "specifies any output of the custom command as a source file is given "
78       "a rule to generate the file using the command at build time.  "
79       "Do not list the output in more than one independent target that may "
80       "build in parallel or the two instances of the rule may conflict "
81       "(instead use add_custom_target to drive the command and make the "
82       "other targets depend on that one).  "
83       "If an output name is a relative path it will be interpreted "
84       "relative to the build tree directory corresponding to the current "
85       "source directory. "
86       "Note that MAIN_DEPENDENCY is completely optional and is "
87       "used as a suggestion to visual studio about where to hang the "
88       "custom command. In makefile terms this creates a new target in the "
89       "following form:\n"
90       "  OUTPUT: MAIN_DEPENDENCY DEPENDS\n"
91       "          COMMAND\n"
92       "If more than one command is specified they will be executed in order. "
93       "The optional ARGS argument is for backward compatibility and will be "
94       "ignored.\n"
95       "The second signature adds a custom command to a target "
96       "such as a library or executable. This is useful for "
97       "performing an operation before or after building the target. "
98       "The command becomes part of the target and will only execute "
99       "when the target itself is built.  If the target is already built,"
100       " the command will not execute.\n"
101       "  add_custom_command(TARGET target\n"
102       "                     PRE_BUILD | PRE_LINK | POST_BUILD\n"
103       "                     COMMAND command1 [ARGS] [args1...]\n"
104       "                     [COMMAND command2 [ARGS] [args2...] ...]\n"
105       "                     [WORKING_DIRECTORY dir]\n"
106       "                     [COMMENT comment] [VERBATIM])\n"
107       "This defines a new command that will be associated with "
108       "building the specified target. When the command will "
109       "happen is determined by which of the following is specified:\n"
110       "  PRE_BUILD - run before all other dependencies\n"
111       "  PRE_LINK - run after other dependencies\n"
112       "  POST_BUILD - run after the target has been built\n"
113       "Note that the PRE_BUILD option is only supported on Visual "
114       "Studio 7 or later. For all other generators PRE_BUILD "
115       "will be treated as PRE_LINK.\n"
116       "If WORKING_DIRECTORY is specified the command will be executed "
117       "in the directory given. "
118       "If it is a relative path it will be interpreted relative to the "
119       "build tree directory corresponding to the current source directory. "
120       "If COMMENT is set, the value will be displayed as a "
121       "message before the commands are executed at build time. "
122       "If APPEND is specified the COMMAND and DEPENDS option values "
123       "are appended to the custom command for the first output specified. "
124       "There must have already been a previous call to this command with "
125       "the same output. The COMMENT, WORKING_DIRECTORY, and MAIN_DEPENDENCY "
126       "options are currently ignored when APPEND is given, "
127       "but may be used in the future."
128       "\n"
129       "If VERBATIM is given then all arguments to the commands will be "
130       "escaped properly for the build tool so that the invoked command "
131       "receives each argument unchanged.  "
132       "Note that one level of escapes is still used by the CMake language "
133       "processor before add_custom_command even sees the arguments. "
134       "Use of VERBATIM is recommended as it enables correct behavior. "
135       "When VERBATIM is not given the behavior is platform specific because "
136       "there is no protection of tool-specific special characters."
137       "\n"
138       "If the output of the custom command is not actually "
139       "created as a file on disk it should be marked as SYMBOLIC with "
140       "SET_SOURCE_FILES_PROPERTIES.\n"
141
142       "The IMPLICIT_DEPENDS option requests scanning of implicit "
143       "dependencies of an input file.  The language given specifies the "
144       "programming language whose corresponding dependency scanner should "
145       "be used.  Currently only C and CXX language scanners are supported. "
146       "The language has to be specified for every file in the "
147       "IMPLICIT_DEPENDS list. "
148       "Dependencies discovered from the scanning are added to those of "
149       "the custom command at build time.  Note that the IMPLICIT_DEPENDS "
150       "option is currently supported only for Makefile generators and "
151       "will be ignored by other generators."
152       "\n"
153       "If COMMAND specifies an executable target (created by "
154       "ADD_EXECUTABLE) it will automatically be replaced by the location "
155       "of the executable created at build time.  Additionally a "
156       "target-level dependency will be added so that the executable target "
157       "will be built before any target using this custom command.  However "
158       "this does NOT add a file-level dependency that would cause the "
159       "custom command to re-run whenever the executable is recompiled."
160       "\n"
161       "Arguments to COMMAND may use \"generator expressions\" with the "
162       "syntax \"$<...>\".  "
163       CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS
164       "References to target names in generator expressions imply "
165       "target-level dependencies, but NOT file-level dependencies.  "
166       "List target names with the DEPENDS option to add file dependencies."
167       "\n"
168       "The DEPENDS option specifies files on which the command depends.  "
169       "If any dependency is an OUTPUT of another custom command in the "
170       "same directory (CMakeLists.txt file) CMake automatically brings the "
171       "other custom command into the target in which this command is built.  "
172       "If DEPENDS is not specified the command will run whenever the OUTPUT "
173       "is missing; if the command does not actually create the OUTPUT then "
174       "the rule will always run.  "
175       "If DEPENDS specifies any target (created by an ADD_* command) "
176       "a target-level dependency is created to make sure the target is "
177       "built before any target using this custom command.  Additionally, "
178       "if the target is an executable or library a file-level dependency "
179       "is created to cause the custom command to re-run whenever the target "
180       "is recompiled.\n"
181       ;
182     }
183
184   cmTypeMacro(cmAddCustomCommandCommand, cmCommand);
185 protected:
186   bool CheckOutputs(const std::vector<std::string>& outputs);
187 };
188
189
190 #endif