cmAddCustomCommandCommand.h 8.4 KB

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