cmInstallCommand.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. cmExecutionStatus &status);
  38. /**
  39. * The name of the command as specified in CMakeList.txt.
  40. */
  41. virtual const char* GetName() { return "install";}
  42. /**
  43. * Succinct documentation.
  44. */
  45. virtual const char* GetTerseDocumentation()
  46. {
  47. return "Specify rules to run at install time.";
  48. }
  49. /**
  50. * More documentation.
  51. */
  52. virtual const char* GetFullDocumentation()
  53. {
  54. return
  55. "This command generates installation rules for a project. "
  56. "Rules specified by calls to this command within a source directory "
  57. "are executed in order during installation. "
  58. "The order across directories is not defined."
  59. "\n"
  60. "There are multiple signatures for this command. Some of them define "
  61. "installation properties for files and targets. Properties common to "
  62. "multiple signatures are covered here but they are valid only for "
  63. "signatures that specify them.\n"
  64. "DESTINATION arguments specify "
  65. "the directory on disk to which a file will be installed. "
  66. "If a full path (with a leading slash or drive letter) is given it "
  67. "is used directly. If a relative path is given it is interpreted "
  68. "relative to the value of CMAKE_INSTALL_PREFIX.\n"
  69. "PERMISSIONS arguments specify permissions for installed files. "
  70. "Valid permissions are "
  71. "OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, "
  72. "GROUP_READ, GROUP_WRITE, GROUP_EXECUTE, "
  73. "WORLD_READ, WORLD_WRITE, WORLD_EXECUTE, "
  74. "SETUID, and SETGID. "
  75. "Permissions that do not make sense on certain platforms are ignored "
  76. "on those platforms.\n"
  77. "The CONFIGURATIONS argument specifies a list of build configurations "
  78. "for which the install rule applies (Debug, Release, etc.).\n"
  79. "The COMPONENT argument specifies an installation component name "
  80. "with which the install rule is associated, such as \"runtime\" or "
  81. "\"development\". During component-specific installation only "
  82. "install rules associated with the given component name will be "
  83. "executed. During a full installation all components are installed.\n"
  84. "The RENAME argument specifies a name for an installed file that "
  85. "may be different from the original file. Renaming is allowed only "
  86. "when a single file is installed by the command.\n"
  87. "The OPTIONAL argument specifies that it is not an error if the "
  88. "file to be installed does not exist. "
  89. "\n"
  90. "The TARGETS signature:\n"
  91. " install(TARGETS targets... [EXPORT <export-name>]\n"
  92. " [[ARCHIVE|LIBRARY|RUNTIME|FRAMEWORK|BUNDLE|\n"
  93. " PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE]\n"
  94. " [DESTINATION <dir>]\n"
  95. " [PERMISSIONS permissions...]\n"
  96. " [CONFIGURATIONS [Debug|Release|...]]\n"
  97. " [COMPONENT <component>]\n"
  98. " [OPTIONAL] [NAMELINK_ONLY|NAMELINK_SKIP]\n"
  99. " ] [...])\n"
  100. "The TARGETS form specifies rules for installing targets from a "
  101. "project. There are five kinds of target files that may be "
  102. "installed: archive, library, runtime, framework, and bundle. "
  103. "Executables are treated as runtime targets, except that those "
  104. "marked with the MACOSX_BUNDLE property are treated as bundle "
  105. "targets on OS X. "
  106. "Static libraries are always treated as archive targets. "
  107. "Module libraries are always treated as library targets. "
  108. "For non-DLL platforms shared libraries are treated as library "
  109. "targets, except that those marked with the FRAMEWORK property "
  110. "are treated as framework targets on OS X. "
  111. "For DLL platforms the DLL part of a shared library is treated as "
  112. "a runtime target and the corresponding import library is treated as "
  113. "an archive target. "
  114. "All Windows-based systems including Cygwin are DLL platforms. "
  115. "The ARCHIVE, LIBRARY, RUNTIME, and FRAMEWORK "
  116. "arguments change the type of target to which the subsequent "
  117. "properties "
  118. "apply. If none is given the installation properties apply to "
  119. "all target types. If only one is given then only targets of that "
  120. "type will be installed (which can be used to install just a DLL or "
  121. "just an import library)."
  122. "\n"
  123. "The PRIVATE_HEADER, PUBLIC_HEADER, and RESOURCE arguments cause "
  124. "subsequent properties to be applied to installing a FRAMEWORK "
  125. "shared library target's associated files on non-Apple platforms. "
  126. "Rules defined by these arguments are ignored on Apple platforms "
  127. "because the associated files are installed into the appropriate "
  128. "locations inside the framework folder. "
  129. "See documentation of the PRIVATE_HEADER, PUBLIC_HEADER, and RESOURCE "
  130. "target properties for details."
  131. "\n"
  132. "Either NAMELINK_ONLY or NAMELINK_SKIP may be specified as a LIBRARY "
  133. "option. "
  134. "On some platforms a versioned shared library has a symbolic link "
  135. "such as\n"
  136. " lib<name>.so -> lib<name>.so.1\n"
  137. "where \"lib<name>.so.1\" is the soname of the library and "
  138. "\"lib<name>.so\" is a \"namelink\" allowing linkers to find the "
  139. "library when given \"-l<name>\". "
  140. "The NAMELINK_ONLY option causes installation of only the namelink "
  141. "when a library target is installed. "
  142. "The NAMELINK_SKIP option causes installation of library files other "
  143. "than the namelink when a library target is installed. "
  144. "When neither option is given both portions are installed. "
  145. "On platforms where versioned shared libraries do not have namelinks "
  146. "or when a library is not versioned the NAMELINK_SKIP option installs "
  147. "the library and the NAMELINK_ONLY option installs nothing. "
  148. "See the VERSION and SOVERSION target properties for details on "
  149. "creating versioned shared libraries."
  150. "\n"
  151. "One or more groups of properties may be specified in a single call "
  152. "to the TARGETS form of this command. A target may be installed more "
  153. "than once to different locations. Consider hypothetical "
  154. "targets \"myExe\", \"mySharedLib\", and \"myStaticLib\". The code\n"
  155. " install(TARGETS myExe mySharedLib myStaticLib\n"
  156. " RUNTIME DESTINATION bin\n"
  157. " LIBRARY DESTINATION lib\n"
  158. " ARCHIVE DESTINATION lib/static)\n"
  159. " install(TARGETS mySharedLib DESTINATION /some/full/path)\n"
  160. "will install myExe to <prefix>/bin and myStaticLib to "
  161. "<prefix>/lib/static. "
  162. "On non-DLL platforms mySharedLib will be installed to <prefix>/lib "
  163. "and /some/full/path. On DLL platforms the mySharedLib DLL will be "
  164. "installed to <prefix>/bin and /some/full/path and its import library "
  165. "will be installed to <prefix>/lib/static and /some/full/path. "
  166. "On non-DLL platforms mySharedLib will be installed to <prefix>/lib "
  167. "and /some/full/path."
  168. "\n"
  169. "The EXPORT option associates the installed target files with an "
  170. "export called <export-name>. "
  171. "It must appear before any RUNTIME, LIBRARY, or ARCHIVE options. "
  172. "See documentation of the install(EXPORT ...) signature below for "
  173. "details."
  174. "\n"
  175. "Installing a target with EXCLUDE_FROM_ALL set to true has "
  176. "undefined behavior."
  177. "\n"
  178. "The FILES signature:\n"
  179. " install(FILES files... DESTINATION <dir>\n"
  180. " [PERMISSIONS permissions...]\n"
  181. " [CONFIGURATIONS [Debug|Release|...]]\n"
  182. " [COMPONENT <component>]\n"
  183. " [RENAME <name>] [OPTIONAL])\n"
  184. "The FILES form specifies rules for installing files for a "
  185. "project. File names given as relative paths are interpreted with "
  186. "respect to the current source directory. Files installed by this "
  187. "form are by default given permissions OWNER_WRITE, OWNER_READ, "
  188. "GROUP_READ, and WORLD_READ if no PERMISSIONS argument is given."
  189. "\n"
  190. "The PROGRAMS signature:\n"
  191. " install(PROGRAMS files... DESTINATION <dir>\n"
  192. " [PERMISSIONS permissions...]\n"
  193. " [CONFIGURATIONS [Debug|Release|...]]\n"
  194. " [COMPONENT <component>]\n"
  195. " [RENAME <name>] [OPTIONAL])\n"
  196. "The PROGRAMS form is identical to the FILES form except that the "
  197. "default permissions for the installed file also include "
  198. "OWNER_EXECUTE, GROUP_EXECUTE, and WORLD_EXECUTE. "
  199. "This form is intended to install programs that are not targets, "
  200. "such as shell scripts. Use the TARGETS form to install targets "
  201. "built within the project."
  202. "\n"
  203. "The DIRECTORY signature:\n"
  204. " install(DIRECTORY dirs... DESTINATION <dir>\n"
  205. " [FILE_PERMISSIONS permissions...]\n"
  206. " [DIRECTORY_PERMISSIONS permissions...]\n"
  207. " [USE_SOURCE_PERMISSIONS]\n"
  208. " [CONFIGURATIONS [Debug|Release|...]]\n"
  209. " [COMPONENT <component>] [FILES_MATCHING]\n"
  210. " [[PATTERN <pattern> | REGEX <regex>]\n"
  211. " [EXCLUDE] [PERMISSIONS permissions...]] [...])\n"
  212. "The DIRECTORY form installs contents of one or more directories "
  213. "to a given destination. "
  214. "The directory structure is copied verbatim to the destination. "
  215. "The last component of each directory name is appended to the "
  216. "destination directory but a trailing slash may be used to "
  217. "avoid this because it leaves the last component empty. "
  218. "Directory names given as relative paths are interpreted with "
  219. "respect to the current source directory. "
  220. "If no input directory names are given the destination directory "
  221. "will be created but nothing will be installed into it. "
  222. "The FILE_PERMISSIONS and DIRECTORY_PERMISSIONS options specify "
  223. "permissions given to files and directories in the destination. "
  224. "If USE_SOURCE_PERMISSIONS is specified and FILE_PERMISSIONS is not, "
  225. "file permissions will be copied from the source directory structure. "
  226. "If no permissions are specified files will be given the default "
  227. "permissions specified in the FILES form of the command, and the "
  228. "directories will be given the default permissions specified in the "
  229. "PROGRAMS form of the command.\n"
  230. "Installation of directories may be controlled with fine granularity "
  231. "using the PATTERN or REGEX options. These \"match\" options specify a "
  232. "globbing pattern or regular expression to match directories or files "
  233. "encountered within input directories. They may be used to apply "
  234. "certain options (see below) to a subset of the files and directories "
  235. "encountered. "
  236. "The full path to each input file or directory "
  237. "(with forward slashes) is matched against the expression. "
  238. "A PATTERN will match only complete file names: the portion of the "
  239. "full path matching the pattern must occur at the end of the file name "
  240. "and be preceded by a slash. "
  241. "A REGEX will match any portion of the full path but it may use "
  242. "'/' and '$' to simulate the PATTERN behavior. "
  243. "By default all files and directories are installed whether "
  244. "or not they are matched. "
  245. "The FILES_MATCHING option may be given before the first match option "
  246. "to disable installation of files (but not directories) not matched by "
  247. "any expression. For example, the code\n"
  248. " install(DIRECTORY src/ DESTINATION include/myproj\n"
  249. " FILES_MATCHING PATTERN \"*.h\")\n"
  250. "will extract and install header files from a source tree.\n"
  251. "Some options may follow a PATTERN or REGEX expression and are "
  252. "applied only to files or directories matching them. "
  253. "The EXCLUDE option will skip the matched file or directory. "
  254. "The PERMISSIONS option overrides the permissions setting for the "
  255. "matched file or directory. "
  256. "For example the code\n"
  257. " install(DIRECTORY icons scripts/ DESTINATION share/myproj\n"
  258. " PATTERN \"CVS\" EXCLUDE\n"
  259. " PATTERN \"scripts/*\"\n"
  260. " PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ\n"
  261. " GROUP_EXECUTE GROUP_READ)\n"
  262. "will install the icons directory to share/myproj/icons and the "
  263. "scripts directory to share/myproj. The icons will get default file "
  264. "permissions, the scripts will be given specific permissions, and "
  265. "any CVS directories will be excluded."
  266. "\n"
  267. "The SCRIPT and CODE signature:\n"
  268. " install([[SCRIPT <file>] [CODE <code>]] [...])\n"
  269. "The SCRIPT form will invoke the given CMake script files during "
  270. "installation. If the script file name is a relative path "
  271. "it will be interpreted with respect to the current source directory. "
  272. "The CODE form will invoke the given CMake code during installation. "
  273. "Code is specified as a single argument inside a double-quoted string. "
  274. "For example, the code\n"
  275. " install(CODE \"MESSAGE(\\\"Sample install message.\\\")\")\n"
  276. "will print a message during installation.\n"
  277. ""
  278. "The EXPORT signature:\n"
  279. " install(EXPORT <export-name> DESTINATION <dir>\n"
  280. " [NAMESPACE <namespace>] [FILE <name>.cmake]\n"
  281. " [PERMISSIONS permissions...]\n"
  282. " [CONFIGURATIONS [Debug|Release|...]]\n"
  283. " [COMPONENT <component>])\n"
  284. "The EXPORT form generates and installs a CMake file containing code "
  285. "to import targets from the installation tree into another project. "
  286. "Target installations are associated with the export <export-name> "
  287. "using the EXPORT option of the install(TARGETS ...) signature "
  288. "documented above. The NAMESPACE option will prepend <namespace> to "
  289. "the target names as they are written to the import file. "
  290. "By default the generated file will be called <export-name>.cmake but "
  291. "the FILE option may be used to specify a different name. The value "
  292. "given to the FILE option must be a file name with the \".cmake\" "
  293. "extension. "
  294. "If a CONFIGURATIONS option is given then the file will only be "
  295. "installed when one of the named configurations is installed. "
  296. "Additionally, the generated import file will reference only the "
  297. "matching target configurations. "
  298. "If a COMPONENT option is specified that does not match that given "
  299. "to the targets associated with <export-name> the behavior is "
  300. "undefined. "
  301. "If a library target is included in the export but "
  302. "a target to which it links is not included the behavior is "
  303. "unspecified."
  304. "\n"
  305. "The EXPORT form is useful to help outside projects use targets built "
  306. "and installed by the current project. For example, the code\n"
  307. " install(TARGETS myexe EXPORT myproj DESTINATION bin)\n"
  308. " install(EXPORT myproj NAMESPACE mp_ DESTINATION lib/myproj)\n"
  309. "will install the executable myexe to <prefix>/bin and code to import "
  310. "it in the file \"<prefix>/lib/myproj/myproj.cmake\". "
  311. "An outside project may load this file with the include command "
  312. "and reference the myexe executable from the installation tree using "
  313. "the imported target name mp_myexe as if the target were built "
  314. "in its own tree."
  315. "\n"
  316. "NOTE: This command supercedes the INSTALL_TARGETS command and the "
  317. "target properties PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT. "
  318. "It also replaces the FILES forms of the INSTALL_FILES and "
  319. "INSTALL_PROGRAMS commands. "
  320. "The processing order of these install rules relative to those "
  321. "generated by INSTALL_TARGETS, INSTALL_FILES, and INSTALL_PROGRAMS "
  322. "commands is not defined.\n"
  323. ;
  324. }
  325. cmTypeMacro(cmInstallCommand, cmCommand);
  326. private:
  327. bool HandleScriptMode(std::vector<std::string> const& args);
  328. bool HandleTargetsMode(std::vector<std::string> const& args);
  329. bool HandleFilesMode(std::vector<std::string> const& args);
  330. bool HandleDirectoryMode(std::vector<std::string> const& args);
  331. bool HandleExportMode(std::vector<std::string> const& args);
  332. bool MakeFilesFullPath(const char* modeName,
  333. const std::vector<std::string>& relFiles,
  334. std::vector<std::string>& absFiles);
  335. };
  336. #endif