1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddCustomCommandCommand.h,v $
6 Date: $Date: 2008/01/30 16:22:10 $
7 Version: $Revision: 1.33 $
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 cmAddCustomCommandCommand_h
18 #define cmAddCustomCommandCommand_h
20 #include "cmCommand.h"
22 /** \class cmAddCustomCommandCommand
25 * cmAddCustomCommandCommand defines a new command (rule) that can
26 * be executed within the build process
30 class cmAddCustomCommandCommand
: public cmCommand
34 * This is a virtual constructor for the command.
36 virtual cmCommand
* Clone()
38 return new cmAddCustomCommandCommand
;
42 * This is called when the command is first encountered in
43 * the CMakeLists.txt file.
45 virtual bool InitialPass(std::vector
<std::string
> const& args
,
46 cmExecutionStatus
&status
);
49 * The name of the command as specified in CMakeList.txt.
51 virtual const char* GetName() {return "add_custom_command";}
54 * Succinct documentation.
56 virtual const char* GetTerseDocumentation()
58 return "Add a custom build rule to the generated build system.";
64 virtual const char* GetFullDocumentation()
67 "There are two main signatures for add_custom_command "
68 "The first signature is for adding a custom command "
69 "to produce an output.\n"
70 " add_custom_command(OUTPUT output1 [output2 ...]\n"
71 " COMMAND command1 [ARGS] [args1...]\n"
72 " [COMMAND command2 [ARGS] [args2...] ...]\n"
73 " [MAIN_DEPENDENCY depend]\n"
74 " [DEPENDS [depends...]]\n"
75 " [IMPLICIT_DEPENDS <lang1> depend1 ...]\n"
76 " [WORKING_DIRECTORY dir]\n"
77 " [COMMENT comment] [VERBATIM] [APPEND])\n"
78 "This defines a new command that can be executed during the build "
79 "process. The outputs named should be listed as source files in the "
80 "target for which they are to be generated. "
81 "If an output name is a relative path it will be interpreted "
82 "relative to the build tree directory corresponding to the current "
84 "Note that MAIN_DEPENDENCY is completely optional and is "
85 "used as a suggestion to visual studio about where to hang the "
86 "custom command. In makefile terms this creates a new target in the "
88 " OUTPUT: MAIN_DEPENDENCY DEPENDS\n"
90 "If more than one command is specified they will be executed in order. "
91 "The optional ARGS argument is for backward compatibility and will be "
93 "The second signature adds a custom command to a target "
94 "such as a library or executable. This is useful for "
95 "performing an operation before or after building the target. "
96 "The command becomes part of the target and will only execute "
97 "when the target itself is built. If the target is already built,"
98 " the command will not execute.\n"
99 " add_custom_command(TARGET target\n"
100 " PRE_BUILD | PRE_LINK | POST_BUILD\n"
101 " COMMAND command1 [ARGS] [args1...]\n"
102 " [COMMAND command2 [ARGS] [args2...] ...]\n"
103 " [WORKING_DIRECTORY dir]\n"
104 " [COMMENT comment] [VERBATIM])\n"
105 "This defines a new command that will be associated with "
106 "building the specified target. When the command will "
107 "happen is determined by which of the following is specified:\n"
108 " PRE_BUILD - run before all other dependencies\n"
109 " PRE_LINK - run after other dependencies\n"
110 " POST_BUILD - run after the target has been built\n"
111 "Note that the PRE_BUILD option is only supported on Visual "
112 "Studio 7 or later. For all other generators PRE_BUILD "
113 "will be treated as PRE_LINK.\n"
114 "If WORKING_DIRECTORY is specified the command will be executed "
115 "in the directory given. "
116 "If COMMENT is set, the value will be displayed as a "
117 "message before the commands are executed at build time. "
118 "If APPEND is specified the COMMAND and DEPENDS option values "
119 "are appended to the custom command for the first output specified. "
120 "There must have already been a previous call to this command with "
121 "the same output. The COMMENT, WORKING_DIRECTORY, and MAIN_DEPENDENCY "
122 "options are currently ignored when APPEND is given, "
123 "but may be used in the future."
125 "If VERBATIM is given then all the arguments to the commands will be "
126 "passed exactly as specified no matter the build tool used. "
127 "Note that one level of escapes is still used by the CMake language "
128 "processor before ADD_CUSTOM_TARGET even sees the arguments. "
129 "Use of VERBATIM is recommended as it enables correct behavior. "
130 "When VERBATIM is not given the behavior is platform specific. "
131 "In the future VERBATIM may be enabled by default. The only reason "
132 "it is an option is to preserve compatibility with older CMake code.\n"
133 "If the output of the custom command is not actually "
134 "created as a file on disk it should be marked as SYMBOLIC with "
135 "SET_SOURCE_FILES_PROPERTIES.\n"
137 "The IMPLICIT_DEPENDS option requests scanning of implicit "
138 "dependencies of an input file. The language given specifies the "
139 "programming language whose corresponding dependency scanner should "
140 "be used. Currently only C and CXX language scanners are supported. "
141 "Dependencies discovered from the scanning are added to those of "
142 "the custom command at build time. Note that the IMPLICIT_DEPENDS "
143 "option is currently supported only for Makefile generators and "
144 "will be ignored by other generators."
146 "If COMMAND specifies an executable target (created by "
147 "ADD_EXECUTABLE) it will automatically be replaced by the location "
148 "of the executable created at build time. Additionally a "
149 "target-level dependency will be added so that the executable target "
150 "will be built before any target using this custom command. However "
151 "this does NOT add a file-level dependency that would cause the "
152 "custom command to re-run whenever the executable is recompiled.\n"
154 "If DEPENDS specifies any target (created by an ADD_* command) "
155 "a target-level dependency is created to make sure the target is "
156 "built before any target using this custom command. Additionally, "
157 "if the target is an executable or library a file-level dependency "
158 "is created to cause the custom command to re-run whenever the target "
163 cmTypeMacro(cmAddCustomCommandCommand
, cmCommand
);
165 bool CheckOutputs(const std::vector
<std::string
>& outputs
);