cmInstallCommand.h 18 KB

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