cmAddCustomCommandCommand.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 COMMENT is set, the value will be displayed as a "
  105. "message before the commands are executed at build time. "
  106. "If APPEND is specified the COMMAND and DEPENDS option values "
  107. "are appended to the custom command for the first output specified. "
  108. "There must have already been a previous call to this command with "
  109. "the same output. The COMMENT, WORKING_DIRECTORY, and MAIN_DEPENDENCY "
  110. "options are currently ignored when APPEND is given, "
  111. "but may be used in the future."
  112. "\n"
  113. "If VERBATIM is given then all arguments to the commands will be "
  114. "escaped properly for the build tool so that the invoked command "
  115. "receives each argument unchanged. "
  116. "Note that one level of escapes is still used by the CMake language "
  117. "processor before add_custom_command even sees the arguments. "
  118. "Use of VERBATIM is recommended as it enables correct behavior. "
  119. "When VERBATIM is not given the behavior is platform specific because "
  120. "there is no protection of tool-specific special characters."
  121. "\n"
  122. "If the output of the custom command is not actually "
  123. "created as a file on disk it should be marked as SYMBOLIC with "
  124. "SET_SOURCE_FILES_PROPERTIES.\n"
  125. "The IMPLICIT_DEPENDS option requests scanning of implicit "
  126. "dependencies of an input file. The language given specifies the "
  127. "programming language whose corresponding dependency scanner should "
  128. "be used. Currently only C and CXX language scanners are supported. "
  129. "Dependencies discovered from the scanning are added to those of "
  130. "the custom command at build time. Note that the IMPLICIT_DEPENDS "
  131. "option is currently supported only for Makefile generators and "
  132. "will be ignored by other generators."
  133. "\n"
  134. "If COMMAND specifies an executable target (created by "
  135. "ADD_EXECUTABLE) it will automatically be replaced by the location "
  136. "of the executable created at build time. Additionally a "
  137. "target-level dependency will be added so that the executable target "
  138. "will be built before any target using this custom command. However "
  139. "this does NOT add a file-level dependency that would cause the "
  140. "custom command to re-run whenever the executable is recompiled."
  141. "\n"
  142. "Arguments to COMMAND may use \"generator expressions\" with the "
  143. "syntax \"$<...>\". "
  144. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS
  145. "References to target names in generator expressions imply "
  146. "target-level dependencies, but NOT file-level dependencies. "
  147. "List target names with the DEPENDS option to add file dependencies."
  148. "\n"
  149. "The DEPENDS option specifies files on which the command depends. "
  150. "If any dependency is an OUTPUT of another custom command in the "
  151. "same directory (CMakeLists.txt file) CMake automatically brings the "
  152. "other custom command into the target in which this command is built. "
  153. "If DEPENDS is not specified the command will run whenever the OUTPUT "
  154. "is missing; if the command does not actually create the OUTPUT then "
  155. "the rule will always run. "
  156. "If DEPENDS specifies any target (created by an ADD_* command) "
  157. "a target-level dependency is created to make sure the target is "
  158. "built before any target using this custom command. Additionally, "
  159. "if the target is an executable or library a file-level dependency "
  160. "is created to cause the custom command to re-run whenever the target "
  161. "is recompiled.\n"
  162. ;
  163. }
  164. cmTypeMacro(cmAddCustomCommandCommand, cmCommand);
  165. protected:
  166. bool CheckOutputs(const std::vector<std::string>& outputs);
  167. };
  168. #endif