cmAddCustomCommandCommand.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmAddCustomCommandCommand_h
  14. #define cmAddCustomCommandCommand_h
  15. #include "cmCommand.h"
  16. /** \class cmAddCustomCommandCommand
  17. * \brief
  18. *
  19. * cmAddCustomCommandCommand defines a new command (rule) that can
  20. * be executed within the build process
  21. *
  22. */
  23. class cmAddCustomCommandCommand : public cmCommand
  24. {
  25. public:
  26. /**
  27. * This is a virtual constructor for the command.
  28. */
  29. virtual cmCommand* Clone()
  30. {
  31. return new cmAddCustomCommandCommand;
  32. }
  33. /**
  34. * This is called when the command is first encountered in
  35. * the CMakeLists.txt file.
  36. */
  37. virtual bool InitialPass(std::vector<std::string> const& args,
  38. cmExecutionStatus &status);
  39. /**
  40. * The name of the command as specified in CMakeList.txt.
  41. */
  42. virtual const char* GetName() {return "add_custom_command";}
  43. /**
  44. * Succinct documentation.
  45. */
  46. virtual const char* GetTerseDocumentation()
  47. {
  48. return "Add a custom build rule to the generated build system.";
  49. }
  50. /**
  51. * More documentation.
  52. */
  53. virtual const char* GetFullDocumentation()
  54. {
  55. return
  56. "There are two main signatures for add_custom_command "
  57. "The first signature is for adding a custom command "
  58. "to produce an output.\n"
  59. " add_custom_command(OUTPUT output1 [output2 ...]\n"
  60. " COMMAND command1 [ARGS] [args1...]\n"
  61. " [COMMAND command2 [ARGS] [args2...] ...]\n"
  62. " [MAIN_DEPENDENCY depend]\n"
  63. " [DEPENDS [depends...]]\n"
  64. " [IMPLICIT_DEPENDS <lang1> depend1 ...]\n"
  65. " [WORKING_DIRECTORY dir]\n"
  66. " [COMMENT comment] [VERBATIM] [APPEND])\n"
  67. "This defines a new command that can be executed during the build "
  68. "process. The outputs named should be listed as source files in the "
  69. "target for which they are to be generated. "
  70. "If an output name is a relative path it will be interpreted "
  71. "relative to the build tree directory corresponding to the current "
  72. "source directory. "
  73. "Note that MAIN_DEPENDENCY is completely optional and is "
  74. "used as a suggestion to visual studio about where to hang the "
  75. "custom command. In makefile terms this creates a new target in the "
  76. "following form:\n"
  77. " OUTPUT: MAIN_DEPENDENCY DEPENDS\n"
  78. " COMMAND\n"
  79. "If more than one command is specified they will be executed in order. "
  80. "The optional ARGS argument is for backward compatibility and will be "
  81. "ignored.\n"
  82. "The second signature adds a custom command to a target "
  83. "such as a library or executable. This is useful for "
  84. "performing an operation before or after building the target. "
  85. "The command becomes part of the target and will only execute "
  86. "when the target itself is built. If the target is already built,"
  87. " the command will not execute.\n"
  88. " add_custom_command(TARGET target\n"
  89. " PRE_BUILD | PRE_LINK | POST_BUILD\n"
  90. " COMMAND command1 [ARGS] [args1...]\n"
  91. " [COMMAND command2 [ARGS] [args2...] ...]\n"
  92. " [WORKING_DIRECTORY dir]\n"
  93. " [COMMENT comment] [VERBATIM])\n"
  94. "This defines a new command that will be associated with "
  95. "building the specified target. When the command will "
  96. "happen is determined by which of the following is specified:\n"
  97. " PRE_BUILD - run before all other dependencies\n"
  98. " PRE_LINK - run after other dependencies\n"
  99. " POST_BUILD - run after the target has been built\n"
  100. "Note that the PRE_BUILD option is only supported on Visual "
  101. "Studio 7 or later. For all other generators PRE_BUILD "
  102. "will be treated as PRE_LINK.\n"
  103. "If WORKING_DIRECTORY is specified the command will be executed "
  104. "in the directory given. "
  105. "If COMMENT is set, the value will be displayed as a "
  106. "message before the commands are executed at build time. "
  107. "If APPEND is specified the COMMAND and DEPENDS option values "
  108. "are appended to the custom command for the first output specified. "
  109. "There must have already been a previous call to this command with "
  110. "the same output. The COMMENT, WORKING_DIRECTORY, and MAIN_DEPENDENCY "
  111. "options are currently ignored when APPEND is given, "
  112. "but may be used in the future."
  113. "\n"
  114. "If VERBATIM is given then all the arguments to the commands will be "
  115. "passed exactly as specified no matter the build tool used. "
  116. "Note that one level of escapes is still used by the CMake language "
  117. "processor before ADD_CUSTOM_TARGET 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. "
  120. "In the future VERBATIM may be enabled by default. The only reason "
  121. "it is an option is to preserve compatibility with older CMake code.\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.\n"
  141. "If DEPENDS specifies any target (created by an ADD_* command) "
  142. "a target-level dependency is created to make sure the target is "
  143. "built before any target using this custom command. Additionally, "
  144. "if the target is an executable or library a file-level dependency "
  145. "is created to cause the custom command to re-run whenever the target "
  146. "is recompiled.\n"
  147. ;
  148. }
  149. cmTypeMacro(cmAddCustomCommandCommand, cmCommand);
  150. protected:
  151. bool CheckOutputs(const std::vector<std::string>& outputs);
  152. };
  153. #endif