install.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. install
  2. -------
  3. Specify rules to run at install time.
  4. This command generates installation rules for a project. Rules
  5. specified by calls to this command within a source directory are
  6. executed in order during installation. The order across directories
  7. is not defined.
  8. There are multiple signatures for this command. Some of them define
  9. installation properties for files and targets. Properties common to
  10. multiple signatures are covered here but they are valid only for
  11. signatures that specify them.
  12. DESTINATION arguments specify the directory on disk to which a file
  13. will be installed. If a full path (with a leading slash or drive
  14. letter) is given it is used directly. If a relative path is given it
  15. is interpreted relative to the value of CMAKE_INSTALL_PREFIX. The
  16. prefix can be relocated at install time using DESTDIR mechanism
  17. explained in the CMAKE_INSTALL_PREFIX variable documentation.
  18. PERMISSIONS arguments specify permissions for installed files. Valid
  19. permissions are OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ,
  20. GROUP_WRITE, GROUP_EXECUTE, WORLD_READ, WORLD_WRITE, WORLD_EXECUTE,
  21. SETUID, and SETGID. Permissions that do not make sense on certain
  22. platforms are ignored on those platforms.
  23. The CONFIGURATIONS argument specifies a list of build configurations
  24. for which the install rule applies (Debug, Release, etc.).
  25. The COMPONENT argument specifies an installation component name with
  26. which the install rule is associated, such as "runtime" or
  27. "development". During component-specific installation only install
  28. rules associated with the given component name will be executed.
  29. During a full installation all components are installed. If COMPONENT
  30. is not provided a default component "Unspecified" is created. The
  31. default component name may be controlled with the
  32. CMAKE_INSTALL_DEFAULT_COMPONENT_NAME variable.
  33. The RENAME argument specifies a name for an installed file that may be
  34. different from the original file. Renaming is allowed only when a
  35. single file is installed by the command.
  36. The OPTIONAL argument specifies that it is not an error if the file to
  37. be installed does not exist.
  38. The TARGETS signature:
  39. ::
  40. install(TARGETS targets... [EXPORT <export-name>]
  41. [[ARCHIVE|LIBRARY|RUNTIME|FRAMEWORK|BUNDLE|
  42. PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE]
  43. [DESTINATION <dir>]
  44. [INCLUDES DESTINATION [<dir> ...]]
  45. [PERMISSIONS permissions...]
  46. [CONFIGURATIONS [Debug|Release|...]]
  47. [COMPONENT <component>]
  48. [OPTIONAL] [NAMELINK_ONLY|NAMELINK_SKIP]
  49. ] [...])
  50. The TARGETS form specifies rules for installing targets from a
  51. project. There are five kinds of target files that may be installed:
  52. ARCHIVE, LIBRARY, RUNTIME, FRAMEWORK, and BUNDLE. Executables are
  53. treated as RUNTIME targets, except that those marked with the
  54. MACOSX_BUNDLE property are treated as BUNDLE targets on OS X. Static
  55. libraries are always treated as ARCHIVE targets. Module libraries are
  56. always treated as LIBRARY targets. For non-DLL platforms shared
  57. libraries are treated as LIBRARY targets, except that those marked
  58. with the FRAMEWORK property are treated as FRAMEWORK targets on OS X.
  59. For DLL platforms the DLL part of a shared library is treated as a
  60. RUNTIME target and the corresponding import library is treated as an
  61. ARCHIVE target. All Windows-based systems including Cygwin are DLL
  62. platforms. The ARCHIVE, LIBRARY, RUNTIME, and FRAMEWORK arguments
  63. change the type of target to which the subsequent properties apply.
  64. If none is given the installation properties apply to all target
  65. types. If only one is given then only targets of that type will be
  66. installed (which can be used to install just a DLL or just an import
  67. library).The INCLUDES DESTINATION specifies a list of directories
  68. which will be added to the INTERFACE_INCLUDE_DIRECTORIES of the
  69. <targets> when exported by install(EXPORT). If a relative path is
  70. specified, it is treated as relative to the $<INSTALL_PREFIX>.
  71. The PRIVATE_HEADER, PUBLIC_HEADER, and RESOURCE arguments cause
  72. subsequent properties to be applied to installing a FRAMEWORK shared
  73. library target's associated files on non-Apple platforms. Rules
  74. defined by these arguments are ignored on Apple platforms because the
  75. associated files are installed into the appropriate locations inside
  76. the framework folder. See documentation of the PRIVATE_HEADER,
  77. PUBLIC_HEADER, and RESOURCE target properties for details.
  78. Either NAMELINK_ONLY or NAMELINK_SKIP may be specified as a LIBRARY
  79. option. On some platforms a versioned shared library has a symbolic
  80. link such as
  81. ::
  82. lib<name>.so -> lib<name>.so.1
  83. where "lib<name>.so.1" is the soname of the library and "lib<name>.so"
  84. is a "namelink" allowing linkers to find the library when given
  85. "-l<name>". The NAMELINK_ONLY option causes installation of only the
  86. namelink when a library target is installed. The NAMELINK_SKIP option
  87. causes installation of library files other than the namelink when a
  88. library target is installed. When neither option is given both
  89. portions are installed. On platforms where versioned shared libraries
  90. do not have namelinks or when a library is not versioned the
  91. NAMELINK_SKIP option installs the library and the NAMELINK_ONLY option
  92. installs nothing. See the VERSION and SOVERSION target properties for
  93. details on creating versioned shared libraries.
  94. One or more groups of properties may be specified in a single call to
  95. the TARGETS form of this command. A target may be installed more than
  96. once to different locations. Consider hypothetical targets "myExe",
  97. "mySharedLib", and "myStaticLib". The code
  98. ::
  99. install(TARGETS myExe mySharedLib myStaticLib
  100. RUNTIME DESTINATION bin
  101. LIBRARY DESTINATION lib
  102. ARCHIVE DESTINATION lib/static)
  103. install(TARGETS mySharedLib DESTINATION /some/full/path)
  104. will install myExe to <prefix>/bin and myStaticLib to
  105. <prefix>/lib/static. On non-DLL platforms mySharedLib will be
  106. installed to <prefix>/lib and /some/full/path. On DLL platforms the
  107. mySharedLib DLL will be installed to <prefix>/bin and /some/full/path
  108. and its import library will be installed to <prefix>/lib/static and
  109. /some/full/path.
  110. The EXPORT option associates the installed target files with an export
  111. called <export-name>. It must appear before any RUNTIME, LIBRARY, or
  112. ARCHIVE options. To actually install the export file itself, call
  113. install(EXPORT). See documentation of the install(EXPORT ...)
  114. signature below for details.
  115. Installing a target with EXCLUDE_FROM_ALL set to true has undefined
  116. behavior.
  117. The FILES signature:
  118. ::
  119. install(FILES files... DESTINATION <dir>
  120. [PERMISSIONS permissions...]
  121. [CONFIGURATIONS [Debug|Release|...]]
  122. [COMPONENT <component>]
  123. [RENAME <name>] [OPTIONAL])
  124. The FILES form specifies rules for installing files for a project.
  125. File names given as relative paths are interpreted with respect to the
  126. current source directory. Files installed by this form are by default
  127. given permissions OWNER_WRITE, OWNER_READ, GROUP_READ, and WORLD_READ
  128. if no PERMISSIONS argument is given.
  129. The PROGRAMS signature:
  130. ::
  131. install(PROGRAMS files... DESTINATION <dir>
  132. [PERMISSIONS permissions...]
  133. [CONFIGURATIONS [Debug|Release|...]]
  134. [COMPONENT <component>]
  135. [RENAME <name>] [OPTIONAL])
  136. The PROGRAMS form is identical to the FILES form except that the
  137. default permissions for the installed file also include OWNER_EXECUTE,
  138. GROUP_EXECUTE, and WORLD_EXECUTE. This form is intended to install
  139. programs that are not targets, such as shell scripts. Use the TARGETS
  140. form to install targets built within the project.
  141. The DIRECTORY signature:
  142. ::
  143. install(DIRECTORY dirs... DESTINATION <dir>
  144. [FILE_PERMISSIONS permissions...]
  145. [DIRECTORY_PERMISSIONS permissions...]
  146. [USE_SOURCE_PERMISSIONS] [OPTIONAL]
  147. [CONFIGURATIONS [Debug|Release|...]]
  148. [COMPONENT <component>] [FILES_MATCHING]
  149. [[PATTERN <pattern> | REGEX <regex>]
  150. [EXCLUDE] [PERMISSIONS permissions...]] [...])
  151. The DIRECTORY form installs contents of one or more directories to a
  152. given destination. The directory structure is copied verbatim to the
  153. destination. The last component of each directory name is appended to
  154. the destination directory but a trailing slash may be used to avoid
  155. this because it leaves the last component empty. Directory names
  156. given as relative paths are interpreted with respect to the current
  157. source directory. If no input directory names are given the
  158. destination directory will be created but nothing will be installed
  159. into it. The FILE_PERMISSIONS and DIRECTORY_PERMISSIONS options
  160. specify permissions given to files and directories in the destination.
  161. If USE_SOURCE_PERMISSIONS is specified and FILE_PERMISSIONS is not,
  162. file permissions will be copied from the source directory structure.
  163. If no permissions are specified files will be given the default
  164. permissions specified in the FILES form of the command, and the
  165. directories will be given the default permissions specified in the
  166. PROGRAMS form of the command.
  167. Installation of directories may be controlled with fine granularity
  168. using the PATTERN or REGEX options. These "match" options specify a
  169. globbing pattern or regular expression to match directories or files
  170. encountered within input directories. They may be used to apply
  171. certain options (see below) to a subset of the files and directories
  172. encountered. The full path to each input file or directory (with
  173. forward slashes) is matched against the expression. A PATTERN will
  174. match only complete file names: the portion of the full path matching
  175. the pattern must occur at the end of the file name and be preceded by
  176. a slash. A REGEX will match any portion of the full path but it may
  177. use '/' and '$' to simulate the PATTERN behavior. By default all
  178. files and directories are installed whether or not they are matched.
  179. The FILES_MATCHING option may be given before the first match option
  180. to disable installation of files (but not directories) not matched by
  181. any expression. For example, the code
  182. ::
  183. install(DIRECTORY src/ DESTINATION include/myproj
  184. FILES_MATCHING PATTERN "*.h")
  185. will extract and install header files from a source tree.
  186. Some options may follow a PATTERN or REGEX expression and are applied
  187. only to files or directories matching them. The EXCLUDE option will
  188. skip the matched file or directory. The PERMISSIONS option overrides
  189. the permissions setting for the matched file or directory. For
  190. example the code
  191. ::
  192. install(DIRECTORY icons scripts/ DESTINATION share/myproj
  193. PATTERN "CVS" EXCLUDE
  194. PATTERN "scripts/*"
  195. PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
  196. GROUP_EXECUTE GROUP_READ)
  197. will install the icons directory to share/myproj/icons and the scripts
  198. directory to share/myproj. The icons will get default file
  199. permissions, the scripts will be given specific permissions, and any
  200. CVS directories will be excluded.
  201. The SCRIPT and CODE signature:
  202. ::
  203. install([[SCRIPT <file>] [CODE <code>]] [...])
  204. The SCRIPT form will invoke the given CMake script files during
  205. installation. If the script file name is a relative path it will be
  206. interpreted with respect to the current source directory. The CODE
  207. form will invoke the given CMake code during installation. Code is
  208. specified as a single argument inside a double-quoted string. For
  209. example, the code
  210. ::
  211. install(CODE "MESSAGE(\"Sample install message.\")")
  212. will print a message during installation.
  213. The EXPORT signature:
  214. ::
  215. install(EXPORT <export-name> DESTINATION <dir>
  216. [NAMESPACE <namespace>] [FILE <name>.cmake]
  217. [PERMISSIONS permissions...]
  218. [CONFIGURATIONS [Debug|Release|...]]
  219. [EXPORT_LINK_INTERFACE_LIBRARIES]
  220. [COMPONENT <component>])
  221. The EXPORT form generates and installs a CMake file containing code to
  222. import targets from the installation tree into another project.
  223. Target installations are associated with the export <export-name>
  224. using the EXPORT option of the install(TARGETS ...) signature
  225. documented above. The NAMESPACE option will prepend <namespace> to
  226. the target names as they are written to the import file. By default
  227. the generated file will be called <export-name>.cmake but the FILE
  228. option may be used to specify a different name. The value given to
  229. the FILE option must be a file name with the ".cmake" extension. If a
  230. CONFIGURATIONS option is given then the file will only be installed
  231. when one of the named configurations is installed. Additionally, the
  232. generated import file will reference only the matching target
  233. configurations. The EXPORT_LINK_INTERFACE_LIBRARIES keyword, if
  234. present, causes the contents of the properties matching
  235. ``(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?`` to be exported, when
  236. policy CMP0022 is NEW. If a COMPONENT option is specified that does
  237. not match that given to the targets associated with <export-name> the
  238. behavior is undefined. If a library target is included in the export
  239. but a target to which it links is not included the behavior is
  240. unspecified.
  241. The EXPORT form is useful to help outside projects use targets built
  242. and installed by the current project. For example, the code
  243. ::
  244. install(TARGETS myexe EXPORT myproj DESTINATION bin)
  245. install(EXPORT myproj NAMESPACE mp_ DESTINATION lib/myproj)
  246. will install the executable myexe to <prefix>/bin and code to import
  247. it in the file "<prefix>/lib/myproj/myproj.cmake". An outside project
  248. may load this file with the include command and reference the myexe
  249. executable from the installation tree using the imported target name
  250. mp_myexe as if the target were built in its own tree.
  251. NOTE: This command supercedes the INSTALL_TARGETS command and the
  252. target properties PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT. It also
  253. replaces the FILES forms of the INSTALL_FILES and INSTALL_PROGRAMS
  254. commands. The processing order of these install rules relative to
  255. those generated by INSTALL_TARGETS, INSTALL_FILES, and
  256. INSTALL_PROGRAMS commands is not defined.