cmAddCustomCommandCommand.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. "Note that MAIN_DEPENDENCY is completely optional and is "
  71. "used as a suggestion to visual studio about where to hang the "
  72. "custom command. In makefile terms this creates a new target in the "
  73. "following form:\n"
  74. " OUTPUT: MAIN_DEPENDENCY DEPENDS\n"
  75. " COMMAND\n"
  76. "If more than one command is specified they will be executed in order. "
  77. "The optional ARGS argument is for backward compatibility and will be "
  78. "ignored.\n"
  79. "The second signature adds a custom command to a target "
  80. "such as a library or executable. This is useful for "
  81. "performing an operation before or after building the target. "
  82. "The command becomes part of the target and will only execute "
  83. "when the target itself is built. If the target is already built,"
  84. " the command will not execute.\n"
  85. " add_custom_command(TARGET target\n"
  86. " PRE_BUILD | PRE_LINK | POST_BUILD\n"
  87. " COMMAND command1 [ARGS] [args1...]\n"
  88. " [COMMAND command2 [ARGS] [args2...] ...]\n"
  89. " [WORKING_DIRECTORY dir]\n"
  90. " [COMMENT comment] [VERBATIM])\n"
  91. "This defines a new command that will be associated with "
  92. "building the specified target. When the command will "
  93. "happen is determined by which of the following is specified:\n"
  94. " PRE_BUILD - run before all other dependencies\n"
  95. " PRE_LINK - run after other dependencies\n"
  96. " POST_BUILD - run after the target has been built\n"
  97. "Note that the PRE_BUILD option is only supported on Visual "
  98. "Studio 7 or later. For all other generators PRE_BUILD "
  99. "will be treated as PRE_LINK.\n"
  100. "If WORKING_DIRECTORY is specified the command will be executed "
  101. "in the directory given. "
  102. "If COMMENT is set, the value will be displayed as a "
  103. "message before the commands are executed at build time. "
  104. "If APPEND is specified the COMMAND and DEPENDS option values "
  105. "are appended to the custom command for the first output specified. "
  106. "There must have already been a previous call to this command with "
  107. "the same output. The COMMENT, WORKING_DIRECTORY, and MAIN_DEPENDENCY "
  108. "options are currently ignored when APPEND is given, "
  109. "but may be used in the future."
  110. "\n"
  111. "If VERBATIM is given then all the arguments to the commands will be "
  112. "passed exactly as specified no matter the build tool used. "
  113. "Note that one level of escapes is still used by the CMake language "
  114. "processor before ADD_CUSTOM_TARGET even sees the arguments. "
  115. "Use of VERBATIM is recommended as it enables correct behavior. "
  116. "When VERBATIM is not given the behavior is platform specific. "
  117. "In the future VERBATIM may be enabled by default. The only reason "
  118. "it is an option is to preserve compatibility with older CMake code.\n"
  119. "If the output of the custom command is not actually "
  120. "created as a file on disk it should be marked as SYMBOLIC with "
  121. "SET_SOURCE_FILES_PROPERTIES.\n"
  122. "The IMPLICIT_DEPENDS option requests scanning of implicit "
  123. "dependencies of an input file. The language given specifies the "
  124. "programming language whose corresponding dependency scanner should "
  125. "be used. Currently only C and CXX language scanners are supported. "
  126. "Dependencies discovered from the scanning are added to those of "
  127. "the custom command at build time. Note that the IMPLICIT_DEPENDS "
  128. "option is currently supported only for Makefile generators and "
  129. "will be ignored by other generators."
  130. "\n"
  131. "If COMMAND specifies an executable target (created by "
  132. "ADD_EXECUTABLE) it will automatically be replaced by the location "
  133. "of the executable created at build time. Additionally a "
  134. "target-level dependency will be added so that the executable target "
  135. "will be built before any target using this custom command. However "
  136. "this does NOT add a file-level dependency that would cause the "
  137. "custom command to re-run whenever the executable is recompiled.\n"
  138. "If DEPENDS specifies any target (created by an ADD_* command) "
  139. "a target-level dependency is created to make sure the target is "
  140. "built before any target using this custom command. Additionally, "
  141. "if the target is an executable or library a file-level dependency "
  142. "is created to cause the custom command to re-run whenever the target "
  143. "is recompiled.\n"
  144. ;
  145. }
  146. cmTypeMacro(cmAddCustomCommandCommand, cmCommand);
  147. protected:
  148. bool CheckOutputs(const std::vector<std::string>& outputs);
  149. };
  150. #endif