1
0

cmAddCustomCommandCommand.h 7.9 KB

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