You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
7.2 KiB

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