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