cmAddCustomCommandCommand.h 6.6 KB

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