cmAddCustomCommandCommand.h 6.4 KB

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