cmInstallCommand.h 18 KB

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