cmInstallCommand.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 cmInstallCommand_h
  14. #define cmInstallCommand_h
  15. #include "cmCommand.h"
  16. /** \class cmInstallCommand
  17. * \brief Specifies where to install some files
  18. *
  19. * cmInstallCommand is a general-purpose interface command for
  20. * specifying install rules.
  21. */
  22. class cmInstallCommand : public cmCommand
  23. {
  24. public:
  25. /**
  26. * This is a virtual constructor for the command.
  27. */
  28. virtual cmCommand* Clone()
  29. {
  30. return new cmInstallCommand;
  31. }
  32. /**
  33. * This is called when the command is first encountered in
  34. * the CMakeLists.txt file.
  35. */
  36. virtual bool InitialPass(std::vector<std::string> const& args);
  37. /**
  38. * The name of the command as specified in CMakeList.txt.
  39. */
  40. virtual const char* GetName() { return "install";}
  41. /**
  42. * Succinct documentation.
  43. */
  44. virtual const char* GetTerseDocumentation()
  45. {
  46. return "Specify rules to run at install time.";
  47. }
  48. /**
  49. * More documentation.
  50. */
  51. virtual const char* GetFullDocumentation()
  52. {
  53. return
  54. "This command generates installation rules for a project. "
  55. "Rules specified by calls to this command within a source directory "
  56. "are executed in order during installation. "
  57. "The order across directories is not defined."
  58. "\n"
  59. "There are multiple signatures for this command. Some of them define "
  60. "installation properties for files and targets. Properties common to "
  61. "multiple signatures are covered here but they are valid only for "
  62. "signatures that specify them.\n"
  63. "DESTINATION arguments specify "
  64. "the directory on disk to which a file will be installed. "
  65. "If a full path (with a leading slash or drive letter) is given it "
  66. "is used directly. If a relative path is given it is interpreted "
  67. "relative to the value of CMAKE_INSTALL_PREFIX.\n"
  68. "PERMISSIONS arguments specify permissions for installed files. "
  69. "Valid permissions are "
  70. "OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, "
  71. "GROUP_READ, GROUP_WRITE, GROUP_EXECUTE, "
  72. "WORLD_READ, WORLD_WRITE, WORLD_EXECUTE, "
  73. "SETUID, and SETGID. "
  74. "Permissions that do not make sense on certain platforms are ignored "
  75. "on those platforms.\n"
  76. "The CONFIGURATIONS argument specifies a list of build configurations "
  77. "for which the install rule applies (Debug, Release, etc.).\n"
  78. "The COMPONENT argument specifies an installation component name "
  79. "with which the install rule is associated, such as \"runtime\" or "
  80. "\"development\". During component-specific installation only "
  81. "install rules associated with the given component name will be "
  82. "executed. During a full installation all components are installed.\n"
  83. "The RENAME argument specifies a name for an installed file that "
  84. "may be different from the original file. Renaming is allowed only "
  85. "when a single file is installed by the command.\n"
  86. "The OPTIONAL argument specifies that it is not an error if the "
  87. "file to be installed does not exist. "
  88. "\n"
  89. "The TARGETS signature:\n"
  90. " install(TARGETS targets...\n"
  91. " [[ARCHIVE|LIBRARY|RUNTIME]\n"
  92. " [DESTINATION <dir>]\n"
  93. " [PERMISSIONS permissions...]\n"
  94. " [CONFIGURATIONS [Debug|Release|...]]\n"
  95. " [COMPONENT <component>]\n"
  96. " [OPTIONAL]\n"
  97. " ] [...])\n"
  98. "The TARGETS form specifies rules for installing targets from a "
  99. "project. There are three kinds of target files that may be "
  100. "installed: archive, library, and runtime. "
  101. "Executables are always treated as runtime targets. "
  102. "Static libraries are always treated as archive targets. "
  103. "Module libraries are always treated as library targets. "
  104. "For non-DLL platforms shared libraries are treated as library "
  105. "targets. "
  106. "For DLL platforms the DLL part of a shared library is treated as "
  107. "a runtime target and the corresponding import library is treated as "
  108. "an archive target. "
  109. "All Windows-based systems including Cygwin are DLL platforms. "
  110. "The ARCHIVE, LIBRARY, and RUNTIME "
  111. "arguments change the type of target to which the subsequent "
  112. "properties "
  113. "apply. If none is given the installation properties apply to "
  114. "all target types. If only one is given then only targets of that "
  115. "type will be installed (which can be used to install just a DLL or "
  116. "just an import library)."
  117. "\n"
  118. "One or more groups of properties may be specified in a single call "
  119. "to the TARGETS form of this command. A target may be installed more "
  120. "than once to different locations. Consider hypothetical "
  121. "targets \"myExe\", \"mySharedLib\", and \"myStaticLib\". The code\n"
  122. " install(TARGETS myExe mySharedLib myStaticLib\n"
  123. " RUNTIME DESTINATION bin\n"
  124. " LIBRARY DESTINATION lib\n"
  125. " ARCHIVE DESTINATION lib/static)\n"
  126. " install(TARGETS mySharedLib DESTINATION /some/full/path)\n"
  127. "will install myExe to <prefix>/bin and myStaticLib to "
  128. "<prefix>/lib/static. "
  129. "On non-DLL platforms mySharedLib will be installed to <prefix>/lib "
  130. "and /some/full/path. On DLL platforms the mySharedLib DLL will be "
  131. "installed to <prefix>/bin and /some/full/path and its import library "
  132. "will be installed to <prefix>/lib/static and /some/full/path. "
  133. "On non-DLL platforms mySharedLib will be installed to <prefix>/lib "
  134. "and /some/full/path."
  135. "\n"
  136. "Installing a target with EXCLUDE_FROM_ALL set to true has "
  137. "undefined behavior."
  138. "\n"
  139. "The FILES signature:\n"
  140. " install(FILES files... DESTINATION <dir>\n"
  141. " [PERMISSIONS permissions...]\n"
  142. " [CONFIGURATIONS [Debug|Release|...]]\n"
  143. " [COMPONENT <component>]\n"
  144. " [RENAME <name>] [OPTIONAL])\n"
  145. "The FILES form specifies rules for installing files for a "
  146. "project. File names given as relative paths are interpreted with "
  147. "respect to the current source directory. Files installed by this "
  148. "form are by default given permissions OWNER_WRITE, OWNER_READ, "
  149. "GROUP_READ, and WORLD_READ if no PERMISSIONS argument is given."
  150. "\n"
  151. "The PROGRAMS signature:\n"
  152. " install(PROGRAMS files... DESTINATION <dir>\n"
  153. " [PERMISSIONS permissions...]\n"
  154. " [CONFIGURATIONS [Debug|Release|...]]\n"
  155. " [COMPONENT <component>]\n"
  156. " [RENAME <name>] [OPTIONAL])\n"
  157. "The PROGRAMS form is identical to the FILES form except that the "
  158. "default permissions for the installed file also include "
  159. "OWNER_EXECUTE, GROUP_EXECUTE, and WORLD_EXECUTE. "
  160. "This form is intended to install programs that are not targets, "
  161. "such as shell scripts. Use the TARGETS form to install targets "
  162. "built within the project."
  163. "\n"
  164. "The DIRECTORY signature:\n"
  165. " install(DIRECTORY dirs... DESTINATION <dir>\n"
  166. " [FILE_PERMISSIONS permissions...]\n"
  167. " [DIRECTORY_PERMISSIONS permissions...]\n"
  168. " [USE_SOURCE_PERMISSIONS]\n"
  169. " [CONFIGURATIONS [Debug|Release|...]]\n"
  170. " [COMPONENT <component>] [FILES_MATCHING]\n"
  171. " [[PATTERN <pattern> | REGEX <regex>]\n"
  172. " [EXCLUDE] [PERMISSIONS permissions...]] [...])\n"
  173. "The DIRECTORY form installs contents of one or more directories "
  174. "to a given destination. "
  175. "The directory structure is copied verbatim to the destination. "
  176. "The last component of each directory name is appended to the "
  177. "destination directory but a trailing slash may be used to "
  178. "avoid this because it leaves the last component empty. "
  179. "Directory names given as relative paths are interpreted with "
  180. "respect to the current source directory. "
  181. "If no input directory names are given the destination directory "
  182. "will be created but nothing will be installed into it. "
  183. "The FILE_PERMISSIONS and DIRECTORY_PERMISSIONS options specify "
  184. "permissions given to files and directories in the destination. "
  185. "If USE_SOURCE_PERMISSIONS is specified and FILE_PERMISSIONS is not, "
  186. "file permissions will be copied from the source directory structure. "
  187. "If no permissions are specified files will be given the default "
  188. "permissions specified in the FILES form of the command, and the "
  189. "directories will be given the default permissions specified in the "
  190. "PROGRAMS form of the command.\n"
  191. "Installation of directories may be controlled with fine granularity "
  192. "using the PATTERN or REGEX options. These \"match\" options specify a "
  193. "globbing pattern or regular expression to match directories or files "
  194. "encountered within input directories. They may be used to apply "
  195. "certain options (see below) to a subset of the files and directories "
  196. "encountered. "
  197. "The full path to each input file or directory "
  198. "(with forward slashes) is matched against the expression. "
  199. "A PATTERN will match only complete file names: the portion of the "
  200. "full path matching the pattern must occur at the end of the file name "
  201. "and be preceded by a slash. "
  202. "A REGEX will match any portion of the full path but it may use "
  203. "'/' and '$' to simulate the PATTERN behavior. "
  204. "By default all files and directories are installed whether "
  205. "or not they are matched. "
  206. "The FILES_MATCHING option may be given before the first match option "
  207. "to disable installation of files (but not directories) not matched by "
  208. "any expression. For example, the code\n"
  209. " install(DIRECTORY src/ DESTINATION include/myproj\n"
  210. " FILES_MATCHING PATTERN \"*.h\")\n"
  211. "will extract and install header files from a source tree.\n"
  212. "Some options may follow a PATTERN or REGEX expression and are "
  213. "applied only to files or directories matching them. "
  214. "The EXCLUDE option will skip the matched file or directory. "
  215. "The PERMISSIONS option overrides the permissions setting for the "
  216. "matched file or directory. "
  217. "For example the code\n"
  218. " install(DIRECTORY icons scripts/ DESTINATION share/myproj\n"
  219. " PATTERN \"CVS\" EXCLUDE\n"
  220. " PATTERN \"scripts/*\"\n"
  221. " PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ\n"
  222. " GROUP_EXECUTE GROUP_READ)\n"
  223. "will install the icons directory to share/myproj/icons and the "
  224. "scripts directory to share/myproj. The icons will get default file "
  225. "permissions, the scripts will be given specific permissions, and "
  226. "any CVS directories will be excluded."
  227. "\n"
  228. "The SCRIPT and CODE signature:\n"
  229. " install([[SCRIPT <file>] [CODE <code>]] [...])\n"
  230. "The SCRIPT form will invoke the given CMake script files during "
  231. "installation. If the script file name is a relative path "
  232. "it will be interpreted with respect to the current source directory. "
  233. "The CODE form will invoke the given CMake code during installation. "
  234. "Code is specified as a single argument inside a double-quoted string. "
  235. "For example, the code\n"
  236. " install(CODE \"MESSAGE(\\\"Sample install message.\\\")\")\n"
  237. "will print a message during installation.\n"
  238. "NOTE: This command supercedes the INSTALL_TARGETS command and the "
  239. "target properties PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT. "
  240. "It also replaces the FILES forms of the INSTALL_FILES and "
  241. "INSTALL_PROGRAMS commands. "
  242. "The processing order of these install rules relative to those "
  243. "generated by INSTALL_TARGETS, INSTALL_FILES, and INSTALL_PROGRAMS "
  244. "commands is not defined.\n"
  245. ;
  246. }
  247. cmTypeMacro(cmInstallCommand, cmCommand);
  248. private:
  249. bool HandleScriptMode(std::vector<std::string> const& args);
  250. bool HandleTargetsMode(std::vector<std::string> const& args);
  251. bool HandleFilesMode(std::vector<std::string> const& args);
  252. bool HandleDirectoryMode(std::vector<std::string> const& args);
  253. bool HandleExportMode(std::vector<std::string> const& args);
  254. bool MakeFilesFullPath(const char* modeName,
  255. const std::vector<std::string>& relFiles,
  256. std::vector<std::string>& absFiles);
  257. };
  258. #endif