cmInstallCommand.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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.\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."
  81. " If COMPONENT is not provided a default component \"Unspecified\" is"
  82. " created. The default component name may be controlled with the "
  83. "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME variable.\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. "\n"
  167. "The EXPORT option associates the installed target files with an "
  168. "export called <export-name>. "
  169. "It must appear before any RUNTIME, LIBRARY, or ARCHIVE options. "
  170. "To actually install the export file itself, call install(EXPORT). "
  171. "See documentation of the install(EXPORT ...) signature below for "
  172. "details."
  173. "\n"
  174. "Installing a target with EXCLUDE_FROM_ALL set to true has "
  175. "undefined behavior."
  176. "\n"
  177. "The FILES signature:\n"
  178. " install(FILES files... DESTINATION <dir>\n"
  179. " [PERMISSIONS permissions...]\n"
  180. " [CONFIGURATIONS [Debug|Release|...]]\n"
  181. " [COMPONENT <component>]\n"
  182. " [RENAME <name>] [OPTIONAL])\n"
  183. "The FILES form specifies rules for installing files for a "
  184. "project. File names given as relative paths are interpreted with "
  185. "respect to the current source directory. Files installed by this "
  186. "form are by default given permissions OWNER_WRITE, OWNER_READ, "
  187. "GROUP_READ, and WORLD_READ if no PERMISSIONS argument is given."
  188. "\n"
  189. "The PROGRAMS signature:\n"
  190. " install(PROGRAMS files... DESTINATION <dir>\n"
  191. " [PERMISSIONS permissions...]\n"
  192. " [CONFIGURATIONS [Debug|Release|...]]\n"
  193. " [COMPONENT <component>]\n"
  194. " [RENAME <name>] [OPTIONAL])\n"
  195. "The PROGRAMS form is identical to the FILES form except that the "
  196. "default permissions for the installed file also include "
  197. "OWNER_EXECUTE, GROUP_EXECUTE, and WORLD_EXECUTE. "
  198. "This form is intended to install programs that are not targets, "
  199. "such as shell scripts. Use the TARGETS form to install targets "
  200. "built within the project."
  201. "\n"
  202. "The DIRECTORY signature:\n"
  203. " install(DIRECTORY dirs... DESTINATION <dir>\n"
  204. " [FILE_PERMISSIONS permissions...]\n"
  205. " [DIRECTORY_PERMISSIONS permissions...]\n"
  206. " [USE_SOURCE_PERMISSIONS] [OPTIONAL]\n"
  207. " [CONFIGURATIONS [Debug|Release|...]]\n"
  208. " [COMPONENT <component>] [FILES_MATCHING]\n"
  209. " [[PATTERN <pattern> | REGEX <regex>]\n"
  210. " [EXCLUDE] [PERMISSIONS permissions...]] [...])\n"
  211. "The DIRECTORY form installs contents of one or more directories "
  212. "to a given destination. "
  213. "The directory structure is copied verbatim to the destination. "
  214. "The last component of each directory name is appended to the "
  215. "destination directory but a trailing slash may be used to "
  216. "avoid this because it leaves the last component empty. "
  217. "Directory names given as relative paths are interpreted with "
  218. "respect to the current source directory. "
  219. "If no input directory names are given the destination directory "
  220. "will be created but nothing will be installed into it. "
  221. "The FILE_PERMISSIONS and DIRECTORY_PERMISSIONS options specify "
  222. "permissions given to files and directories in the destination. "
  223. "If USE_SOURCE_PERMISSIONS is specified and FILE_PERMISSIONS is not, "
  224. "file permissions will be copied from the source directory structure. "
  225. "If no permissions are specified files will be given the default "
  226. "permissions specified in the FILES form of the command, and the "
  227. "directories will be given the default permissions specified in the "
  228. "PROGRAMS form of the command.\n"
  229. "Installation of directories may be controlled with fine granularity "
  230. "using the PATTERN or REGEX options. These \"match\" options specify a "
  231. "globbing pattern or regular expression to match directories or files "
  232. "encountered within input directories. They may be used to apply "
  233. "certain options (see below) to a subset of the files and directories "
  234. "encountered. "
  235. "The full path to each input file or directory "
  236. "(with forward slashes) is matched against the expression. "
  237. "A PATTERN will match only complete file names: the portion of the "
  238. "full path matching the pattern must occur at the end of the file name "
  239. "and be preceded by a slash. "
  240. "A REGEX will match any portion of the full path but it may use "
  241. "'/' and '$' to simulate the PATTERN behavior. "
  242. "By default all files and directories are installed whether "
  243. "or not they are matched. "
  244. "The FILES_MATCHING option may be given before the first match option "
  245. "to disable installation of files (but not directories) not matched by "
  246. "any expression. For example, the code\n"
  247. " install(DIRECTORY src/ DESTINATION include/myproj\n"
  248. " FILES_MATCHING PATTERN \"*.h\")\n"
  249. "will extract and install header files from a source tree.\n"
  250. "Some options may follow a PATTERN or REGEX expression and are "
  251. "applied only to files or directories matching them. "
  252. "The EXCLUDE option will skip the matched file or directory. "
  253. "The PERMISSIONS option overrides the permissions setting for the "
  254. "matched file or directory. "
  255. "For example the code\n"
  256. " install(DIRECTORY icons scripts/ DESTINATION share/myproj\n"
  257. " PATTERN \"CVS\" EXCLUDE\n"
  258. " PATTERN \"scripts/*\"\n"
  259. " PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ\n"
  260. " GROUP_EXECUTE GROUP_READ)\n"
  261. "will install the icons directory to share/myproj/icons and the "
  262. "scripts directory to share/myproj. The icons will get default file "
  263. "permissions, the scripts will be given specific permissions, and "
  264. "any CVS directories will be excluded."
  265. "\n"
  266. "The SCRIPT and CODE signature:\n"
  267. " install([[SCRIPT <file>] [CODE <code>]] [...])\n"
  268. "The SCRIPT form will invoke the given CMake script files during "
  269. "installation. If the script file name is a relative path "
  270. "it will be interpreted with respect to the current source directory. "
  271. "The CODE form will invoke the given CMake code during installation. "
  272. "Code is specified as a single argument inside a double-quoted string. "
  273. "For example, the code\n"
  274. " install(CODE \"MESSAGE(\\\"Sample install message.\\\")\")\n"
  275. "will print a message during installation.\n"
  276. ""
  277. "The EXPORT signature:\n"
  278. " install(EXPORT <export-name> DESTINATION <dir>\n"
  279. " [NAMESPACE <namespace>] [FILE <name>.cmake]\n"
  280. " [PERMISSIONS permissions...]\n"
  281. " [CONFIGURATIONS [Debug|Release|...]]\n"
  282. " [COMPONENT <component>])\n"
  283. "The EXPORT form generates and installs a CMake file containing code "
  284. "to import targets from the installation tree into another project. "
  285. "Target installations are associated with the export <export-name> "
  286. "using the EXPORT option of the install(TARGETS ...) signature "
  287. "documented above. The NAMESPACE option will prepend <namespace> to "
  288. "the target names as they are written to the import file. "
  289. "By default the generated file will be called <export-name>.cmake but "
  290. "the FILE option may be used to specify a different name. The value "
  291. "given to the FILE option must be a file name with the \".cmake\" "
  292. "extension. "
  293. "If a CONFIGURATIONS option is given then the file will only be "
  294. "installed when one of the named configurations is installed. "
  295. "Additionally, the generated import file will reference only the "
  296. "matching target configurations. "
  297. "If a COMPONENT option is specified that does not match that given "
  298. "to the targets associated with <export-name> the behavior is "
  299. "undefined. "
  300. "If a library target is included in the export but "
  301. "a target to which it links is not included the behavior is "
  302. "unspecified."
  303. "\n"
  304. "The EXPORT form is useful to help outside projects use targets built "
  305. "and installed by the current project. For example, the code\n"
  306. " install(TARGETS myexe EXPORT myproj DESTINATION bin)\n"
  307. " install(EXPORT myproj NAMESPACE mp_ DESTINATION lib/myproj)\n"
  308. "will install the executable myexe to <prefix>/bin and code to import "
  309. "it in the file \"<prefix>/lib/myproj/myproj.cmake\". "
  310. "An outside project may load this file with the include command "
  311. "and reference the myexe executable from the installation tree using "
  312. "the imported target name mp_myexe as if the target were built "
  313. "in its own tree."
  314. "\n"
  315. "NOTE: This command supercedes the INSTALL_TARGETS command and the "
  316. "target properties PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT. "
  317. "It also replaces the FILES forms of the INSTALL_FILES and "
  318. "INSTALL_PROGRAMS commands. "
  319. "The processing order of these install rules relative to those "
  320. "generated by INSTALL_TARGETS, INSTALL_FILES, and INSTALL_PROGRAMS "
  321. "commands is not defined.\n"
  322. ;
  323. }
  324. cmTypeMacro(cmInstallCommand, cmCommand);
  325. private:
  326. bool HandleScriptMode(std::vector<std::string> const& args);
  327. bool HandleTargetsMode(std::vector<std::string> const& args);
  328. bool HandleFilesMode(std::vector<std::string> const& args);
  329. bool HandleDirectoryMode(std::vector<std::string> const& args);
  330. bool HandleExportMode(std::vector<std::string> const& args);
  331. bool MakeFilesFullPath(const char* modeName,
  332. const std::vector<std::string>& relFiles,
  333. std::vector<std::string>& absFiles);
  334. bool CheckCMP0006(bool& failure);
  335. std::string DefaultComponentName;
  336. };
  337. #endif