install.rst 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. install
  2. -------
  3. Specify rules to run at install time.
  4. Synopsis
  5. ^^^^^^^^
  6. .. parsed-literal::
  7. install(`TARGETS`_ <target>... [...])
  8. install({`FILES`_ | `PROGRAMS`_} <file>... [...])
  9. install(`DIRECTORY`_ <dir>... [...])
  10. install(`SCRIPT`_ <file> [...])
  11. install(`CODE`_ <code> [...])
  12. install(`EXPORT`_ <export-name> [...])
  13. Introduction
  14. ^^^^^^^^^^^^
  15. This command generates installation rules for a project. Install rules
  16. specified by calls to the ``install()`` command within a source directory
  17. are executed in order during installation. Install rules in subdirectories
  18. added by calls to the :command:`add_subdirectory` command are interleaved
  19. with those in the parent directory to run in the order declared (see
  20. policy :policy:`CMP0082`).
  21. There are multiple signatures for this command. Some of them define
  22. installation options for files and targets. Options common to
  23. multiple signatures are covered here but they are valid only for
  24. signatures that specify them. The common options are:
  25. ``DESTINATION``
  26. Specify the directory on disk to which a file will be installed.
  27. Arguments can be relative or absolute paths.
  28. If a relative path is given it is interpreted relative to the value
  29. of the :variable:`CMAKE_INSTALL_PREFIX` variable.
  30. The prefix can be relocated at install time using the ``DESTDIR``
  31. mechanism explained in the :variable:`CMAKE_INSTALL_PREFIX` variable
  32. documentation.
  33. If an absolute path (with a leading slash or drive letter) is given
  34. it is used verbatim.
  35. As absolute paths are not supported by :manual:`cpack <cpack(1)>` installer
  36. generators, it is preferable to use relative paths throughout.
  37. In particular, there is no need to make paths absolute by prepending
  38. :variable:`CMAKE_INSTALL_PREFIX`; this prefix is used by default if
  39. the DESTINATION is a relative path.
  40. ``PERMISSIONS``
  41. Specify permissions for installed files. Valid permissions are
  42. ``OWNER_READ``, ``OWNER_WRITE``, ``OWNER_EXECUTE``, ``GROUP_READ``,
  43. ``GROUP_WRITE``, ``GROUP_EXECUTE``, ``WORLD_READ``, ``WORLD_WRITE``,
  44. ``WORLD_EXECUTE``, ``SETUID``, and ``SETGID``. Permissions that do
  45. not make sense on certain platforms are ignored on those platforms.
  46. ``CONFIGURATIONS``
  47. Specify a list of build configurations for which the install rule
  48. applies (Debug, Release, etc.). Note that the values specified for
  49. this option only apply to options listed AFTER the ``CONFIGURATIONS``
  50. option. For example, to set separate install paths for the Debug and
  51. Release configurations, do the following:
  52. .. code-block:: cmake
  53. install(TARGETS target
  54. CONFIGURATIONS Debug
  55. RUNTIME DESTINATION Debug/bin)
  56. install(TARGETS target
  57. CONFIGURATIONS Release
  58. RUNTIME DESTINATION Release/bin)
  59. Note that ``CONFIGURATIONS`` appears BEFORE ``RUNTIME DESTINATION``.
  60. ``COMPONENT``
  61. Specify an installation component name with which the install rule
  62. is associated, such as "runtime" or "development". During
  63. component-specific installation only install rules associated with
  64. the given component name will be executed. During a full installation
  65. all components are installed unless marked with ``EXCLUDE_FROM_ALL``.
  66. If ``COMPONENT`` is not provided a default component "Unspecified" is
  67. created. The default component name may be controlled with the
  68. :variable:`CMAKE_INSTALL_DEFAULT_COMPONENT_NAME` variable.
  69. ``EXCLUDE_FROM_ALL``
  70. Specify that the file is excluded from a full installation and only
  71. installed as part of a component-specific installation
  72. ``RENAME``
  73. Specify a name for an installed file that may be different from the
  74. original file. Renaming is allowed only when a single file is
  75. installed by the command.
  76. ``OPTIONAL``
  77. Specify that it is not an error if the file to be installed does
  78. not exist.
  79. Command signatures that install files may print messages during
  80. installation. Use the :variable:`CMAKE_INSTALL_MESSAGE` variable
  81. to control which messages are printed.
  82. Many of the ``install()`` variants implicitly create the directories
  83. containing the installed files. If
  84. :variable:`CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS` is set, these
  85. directories will be created with the permissions specified. Otherwise,
  86. they will be created according to the uname rules on Unix-like platforms.
  87. Windows platforms are unaffected.
  88. Installing Targets
  89. ^^^^^^^^^^^^^^^^^^
  90. .. _`install(TARGETS)`:
  91. .. _TARGETS:
  92. .. code-block:: cmake
  93. install(TARGETS targets... [EXPORT <export-name>]
  94. [[ARCHIVE|LIBRARY|RUNTIME|OBJECTS|FRAMEWORK|BUNDLE|
  95. PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE]
  96. [DESTINATION <dir>]
  97. [PERMISSIONS permissions...]
  98. [CONFIGURATIONS [Debug|Release|...]]
  99. [COMPONENT <component>]
  100. [NAMELINK_COMPONENT <component>]
  101. [OPTIONAL] [EXCLUDE_FROM_ALL]
  102. [NAMELINK_ONLY|NAMELINK_SKIP]
  103. ] [...]
  104. [INCLUDES DESTINATION [<dir> ...]]
  105. )
  106. The ``TARGETS`` form specifies rules for installing targets from a
  107. project. There are several kinds of target :ref:`Output Artifacts`
  108. that may be installed:
  109. ``ARCHIVE``
  110. Target artifacts of this kind include:
  111. * *Static libraries*
  112. (except on macOS when marked as ``FRAMEWORK``, see below);
  113. * *DLL import libraries*
  114. (on all Windows-based systems including Cygwin; they have extension
  115. ``.lib``, in contrast to the ``.dll`` libraries that go to ``RUNTIME``);
  116. * On AIX, the *linker import file* created for executables with
  117. :prop_tgt:`ENABLE_EXPORTS` enabled.
  118. ``LIBRARY``
  119. Target artifacts of this kind include:
  120. * *Shared libraries*, except
  121. - DLLs (these go to ``RUNTIME``, see below),
  122. - on macOS when marked as ``FRAMEWORK`` (see below).
  123. ``RUNTIME``
  124. Target artifacts of this kind include:
  125. * *Executables*
  126. (except on macOS when marked as ``MACOSX_BUNDLE``, see ``BUNDLE`` below);
  127. * DLLs (on all Windows-based systems including Cygwin; note that the
  128. accompanying import libraries are of kind ``ARCHIVE``).
  129. ``OBJECTS``
  130. Object files associated with *object libraries*.
  131. ``FRAMEWORK``
  132. Both static and shared libraries marked with the ``FRAMEWORK``
  133. property are treated as ``FRAMEWORK`` targets on macOS.
  134. ``BUNDLE``
  135. Executables marked with the :prop_tgt:`MACOSX_BUNDLE` property are treated as
  136. ``BUNDLE`` targets on macOS.
  137. ``PUBLIC_HEADER``
  138. Any :prop_tgt:`PUBLIC_HEADER` files associated with a library are installed in
  139. the destination specified by the ``PUBLIC_HEADER`` argument on non-Apple
  140. platforms. Rules defined by this argument are ignored for :prop_tgt:`FRAMEWORK`
  141. libraries on Apple platforms because the associated files are installed
  142. into the appropriate locations inside the framework folder. See
  143. :prop_tgt:`PUBLIC_HEADER` for details.
  144. ``PRIVATE_HEADER``
  145. Similar to ``PUBLIC_HEADER``, but for ``PRIVATE_HEADER`` files. See
  146. :prop_tgt:`PRIVATE_HEADER` for details.
  147. ``RESOURCE``
  148. Similar to ``PUBLIC_HEADER`` and ``PRIVATE_HEADER``, but for
  149. ``RESOURCE`` files. See :prop_tgt:`RESOURCE` for details.
  150. For each of these arguments given, the arguments following them only apply
  151. to the target or file type specified in the argument. If none is given, the
  152. installation properties apply to all target types. If only one is given then
  153. only targets of that type will be installed (which can be used to install
  154. just a DLL or just an import library.)
  155. For regular executables, static libraries and shared libraries, the
  156. ``DESTINATION`` argument is not required. For these target types, when
  157. ``DESTINATION`` is omitted, a default destination will be taken from the
  158. appropriate variable from :module:`GNUInstallDirs`, or set to a built-in
  159. default value if that variable is not defined. The same is true for the
  160. public and private headers associated with the installed targets through the
  161. :prop_tgt:`PUBLIC_HEADER` and :prop_tgt:`PRIVATE_HEADER` target properties.
  162. A destination must always be provided for module libraries, Apple bundles and
  163. frameworks. A destination can be omitted for interface and object libraries,
  164. but they are handled differently (see the discussion of this topic toward the
  165. end of this section).
  166. The following table shows the target types with their associated variables and
  167. built-in defaults that apply when no destination is given:
  168. ================== =============================== ======================
  169. Target Type GNUInstallDirs Variable Built-In Default
  170. ================== =============================== ======================
  171. ``RUNTIME`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
  172. ``LIBRARY`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
  173. ``ARCHIVE`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
  174. ``PRIVATE_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
  175. ``PUBLIC_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
  176. ================== =============================== ======================
  177. Projects wishing to follow the common practice of installing headers into a
  178. project-specific subdirectory will need to provide a destination rather than
  179. rely on the above.
  180. To make packages compliant with distribution filesystem layout policies, if
  181. projects must specify a ``DESTINATION``, it is recommended that they use a
  182. path that begins with the appropriate :module:`GNUInstallDirs` variable.
  183. This allows package maintainers to control the install destination by setting
  184. the appropriate cache variables. The following example shows a static library
  185. being installed to the default destination provided by
  186. :module:`GNUInstallDirs`, but with its headers installed to a project-specific
  187. subdirectory that follows the above recommendation:
  188. .. code-block:: cmake
  189. add_library(mylib STATIC ...)
  190. set_target_properties(mylib PROPERTIES PUBLIC_HEADER mylib.h)
  191. include(GNUInstallDirs)
  192. install(TARGETS mylib
  193. PUBLIC_HEADER
  194. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/myproj
  195. )
  196. In addition to the common options listed above, each target can accept
  197. the following additional arguments:
  198. ``NAMELINK_COMPONENT``
  199. On some platforms a versioned shared library has a symbolic link such
  200. as::
  201. lib<name>.so -> lib<name>.so.1
  202. where ``lib<name>.so.1`` is the soname of the library and ``lib<name>.so``
  203. is a "namelink" allowing linkers to find the library when given
  204. ``-l<name>``. The ``NAMELINK_COMPONENT`` option is similar to the
  205. ``COMPONENT`` option, but it changes the installation component of a shared
  206. library namelink if one is generated. If not specified, this defaults to the
  207. value of ``COMPONENT``. It is an error to use this parameter outside of a
  208. ``LIBRARY`` block.
  209. Consider the following example:
  210. .. code-block:: cmake
  211. install(TARGETS mylib
  212. LIBRARY
  213. COMPONENT Libraries
  214. NAMELINK_COMPONENT Development
  215. PUBLIC_HEADER
  216. COMPONENT Development
  217. )
  218. In this scenario, if you choose to install only the ``Development``
  219. component, both the headers and namelink will be installed without the
  220. library. (If you don't also install the ``Libraries`` component, the
  221. namelink will be a dangling symlink, and projects that link to the library
  222. will have build errors.) If you install only the ``Libraries`` component,
  223. only the library will be installed, without the headers and namelink.
  224. This option is typically used for package managers that have separate
  225. runtime and development packages. For example, on Debian systems, the
  226. library is expected to be in the runtime package, and the headers and
  227. namelink are expected to be in the development package.
  228. See the :prop_tgt:`VERSION` and :prop_tgt:`SOVERSION` target properties for
  229. details on creating versioned shared libraries.
  230. ``NAMELINK_ONLY``
  231. This option causes the installation of only the namelink when a library
  232. target is installed. On platforms where versioned shared libraries do not
  233. have namelinks or when a library is not versioned, the ``NAMELINK_ONLY``
  234. option installs nothing. It is an error to use this parameter outside of a
  235. ``LIBRARY`` block.
  236. When ``NAMELINK_ONLY`` is given, either ``NAMELINK_COMPONENT`` or
  237. ``COMPONENT`` may be used to specify the installation component of the
  238. namelink, but ``COMPONENT`` should generally be preferred.
  239. ``NAMELINK_SKIP``
  240. Similar to ``NAMELINK_ONLY``, but it has the opposite effect: it causes the
  241. installation of library files other than the namelink when a library target
  242. is installed. When neither ``NAMELINK_ONLY`` or ``NAMELINK_SKIP`` are given,
  243. both portions are installed. On platforms where versioned shared libraries
  244. do not have symlinks or when a library is not versioned, ``NAMELINK_SKIP``
  245. installs the library. It is an error to use this parameter outside of a
  246. ``LIBRARY`` block.
  247. If ``NAMELINK_SKIP`` is specified, ``NAMELINK_COMPONENT`` has no effect. It
  248. is not recommended to use ``NAMELINK_SKIP`` in conjunction with
  249. ``NAMELINK_COMPONENT``.
  250. The `install(TARGETS)`_ command can also accept the following options at the
  251. top level:
  252. ``EXPORT``
  253. This option associates the installed target files with an export called
  254. ``<export-name>``. It must appear before any target options. To actually
  255. install the export file itself, call `install(EXPORT)`_, documented below.
  256. See documentation of the :prop_tgt:`EXPORT_NAME` target property to change
  257. the name of the exported target.
  258. ``INCLUDES DESTINATION``
  259. This option specifies a list of directories which will be added to the
  260. :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` target property of the
  261. ``<targets>`` when exported by the `install(EXPORT)`_ command. If a
  262. relative path is specified, it is treated as relative to the
  263. ``$<INSTALL_PREFIX>``.
  264. One or more groups of properties may be specified in a single call to
  265. the ``TARGETS`` form of this command. A target may be installed more than
  266. once to different locations. Consider hypothetical targets ``myExe``,
  267. ``mySharedLib``, and ``myStaticLib``. The code:
  268. .. code-block:: cmake
  269. install(TARGETS myExe mySharedLib myStaticLib
  270. RUNTIME DESTINATION bin
  271. LIBRARY DESTINATION lib
  272. ARCHIVE DESTINATION lib/static)
  273. install(TARGETS mySharedLib DESTINATION /some/full/path)
  274. will install ``myExe`` to ``<prefix>/bin`` and ``myStaticLib`` to
  275. ``<prefix>/lib/static``. On non-DLL platforms ``mySharedLib`` will be
  276. installed to ``<prefix>/lib`` and ``/some/full/path``. On DLL platforms
  277. the ``mySharedLib`` DLL will be installed to ``<prefix>/bin`` and
  278. ``/some/full/path`` and its import library will be installed to
  279. ``<prefix>/lib/static`` and ``/some/full/path``.
  280. :ref:`Interface Libraries` may be listed among the targets to install.
  281. They install no artifacts but will be included in an associated ``EXPORT``.
  282. If :ref:`Object Libraries` are listed but given no destination for their
  283. object files, they will be exported as :ref:`Interface Libraries`.
  284. This is sufficient to satisfy transitive usage requirements of other
  285. targets that link to the object libraries in their implementation.
  286. Installing a target with the :prop_tgt:`EXCLUDE_FROM_ALL` target property
  287. set to ``TRUE`` has undefined behavior.
  288. `install(TARGETS)`_ can install targets that were created in
  289. other directories. When using such cross-directory install rules, running
  290. ``make install`` (or similar) from a subdirectory will not guarantee that
  291. targets from other directories are up-to-date. You can use
  292. :command:`target_link_libraries` or :command:`add_dependencies`
  293. to ensure that such out-of-directory targets are built before the
  294. subdirectory-specific install rules are run.
  295. An install destination given as a ``DESTINATION`` argument may
  296. use "generator expressions" with the syntax ``$<...>``. See the
  297. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  298. Installing Files
  299. ^^^^^^^^^^^^^^^^
  300. .. _`install(FILES)`:
  301. .. _`install(PROGRAMS)`:
  302. .. _FILES:
  303. .. _PROGRAMS:
  304. .. code-block:: cmake
  305. install(<FILES|PROGRAMS> files...
  306. TYPE <type> | DESTINATION <dir>
  307. [PERMISSIONS permissions...]
  308. [CONFIGURATIONS [Debug|Release|...]]
  309. [COMPONENT <component>]
  310. [RENAME <name>] [OPTIONAL] [EXCLUDE_FROM_ALL])
  311. The ``FILES`` form specifies rules for installing files for a project.
  312. File names given as relative paths are interpreted with respect to the
  313. current source directory. Files installed by this form are by default
  314. given permissions ``OWNER_WRITE``, ``OWNER_READ``, ``GROUP_READ``, and
  315. ``WORLD_READ`` if no ``PERMISSIONS`` argument is given.
  316. The ``PROGRAMS`` form is identical to the ``FILES`` form except that the
  317. default permissions for the installed file also include ``OWNER_EXECUTE``,
  318. ``GROUP_EXECUTE``, and ``WORLD_EXECUTE``. This form is intended to install
  319. programs that are not targets, such as shell scripts. Use the ``TARGETS``
  320. form to install targets built within the project.
  321. The list of ``files...`` given to ``FILES`` or ``PROGRAMS`` may use
  322. "generator expressions" with the syntax ``$<...>``. See the
  323. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  324. However, if any item begins in a generator expression it must evaluate
  325. to a full path.
  326. Either a ``TYPE`` or a ``DESTINATION`` must be provided, but not both.
  327. A ``TYPE`` argument specifies the generic file type of the files being
  328. installed. A destination will then be set automatically by taking the
  329. corresponding variable from :module:`GNUInstallDirs`, or by using a
  330. built-in default if that variable is not defined. See the table below for
  331. the supported file types and their corresponding variables and built-in
  332. defaults. Projects can provide a ``DESTINATION`` argument instead of a
  333. file type if they wish to explicitly define the install destination.
  334. ======================= ================================== =========================
  335. ``TYPE`` Argument GNUInstallDirs Variable Built-In Default
  336. ======================= ================================== =========================
  337. ``BIN`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
  338. ``SBIN`` ``${CMAKE_INSTALL_SBINDIR}`` ``sbin``
  339. ``LIB`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
  340. ``INCLUDE`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
  341. ``SYSCONF`` ``${CMAKE_INSTALL_SYSCONFDIR}`` ``etc``
  342. ``SHAREDSTATE`` ``${CMAKE_INSTALL_SHARESTATEDIR}`` ``com``
  343. ``LOCALSTATE`` ``${CMAKE_INSTALL_LOCALSTATEDIR}`` ``var``
  344. ``RUNSTATE`` ``${CMAKE_INSTALL_RUNSTATEDIR}`` ``<LOCALSTATE dir>/run``
  345. ``DATA`` ``${CMAKE_INSTALL_DATADIR}`` ``<DATAROOT dir>``
  346. ``INFO`` ``${CMAKE_INSTALL_INFODIR}`` ``<DATAROOT dir>/info``
  347. ``LOCALE`` ``${CMAKE_INSTALL_LOCALEDIR}`` ``<DATAROOT dir>/locale``
  348. ``MAN`` ``${CMAKE_INSTALL_MANDIR}`` ``<DATAROOT dir>/man``
  349. ``DOC`` ``${CMAKE_INSTALL_DOCDIR}`` ``<DATAROOT dir>/doc``
  350. ======================= ================================== =========================
  351. Projects wishing to follow the common practice of installing headers into a
  352. project-specific subdirectory will need to provide a destination rather than
  353. rely on the above.
  354. Note that some of the types' built-in defaults use the ``DATAROOT`` directory as
  355. a prefix. The ``DATAROOT`` prefix is calculated similarly to the types, with
  356. ``CMAKE_INSTALL_DATAROOTDIR`` as the variable and ``share`` as the built-in
  357. default. You cannot use ``DATAROOT`` as a ``TYPE`` parameter; please use
  358. ``DATA`` instead.
  359. To make packages compliant with distribution filesystem layout policies, if
  360. projects must specify a ``DESTINATION``, it is recommended that they use a
  361. path that begins with the appropriate :module:`GNUInstallDirs` variable.
  362. This allows package maintainers to control the install destination by setting
  363. the appropriate cache variables. The following example shows how to follow
  364. this advice while installing headers to a project-specific subdirectory:
  365. .. code-block:: cmake
  366. include(GNUInstallDirs)
  367. install(FILES mylib.h
  368. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/myproj
  369. )
  370. An install destination given as a ``DESTINATION`` argument may
  371. use "generator expressions" with the syntax ``$<...>``. See the
  372. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  373. Installing Directories
  374. ^^^^^^^^^^^^^^^^^^^^^^
  375. .. _`install(DIRECTORY)`:
  376. .. _DIRECTORY:
  377. .. code-block:: cmake
  378. install(DIRECTORY dirs...
  379. TYPE <type> | DESTINATION <dir>
  380. [FILE_PERMISSIONS permissions...]
  381. [DIRECTORY_PERMISSIONS permissions...]
  382. [USE_SOURCE_PERMISSIONS] [OPTIONAL] [MESSAGE_NEVER]
  383. [CONFIGURATIONS [Debug|Release|...]]
  384. [COMPONENT <component>] [EXCLUDE_FROM_ALL]
  385. [FILES_MATCHING]
  386. [[PATTERN <pattern> | REGEX <regex>]
  387. [EXCLUDE] [PERMISSIONS permissions...]] [...])
  388. The ``DIRECTORY`` form installs contents of one or more directories to a
  389. given destination. The directory structure is copied verbatim to the
  390. destination. The last component of each directory name is appended to
  391. the destination directory but a trailing slash may be used to avoid
  392. this because it leaves the last component empty. Directory names
  393. given as relative paths are interpreted with respect to the current
  394. source directory. If no input directory names are given the
  395. destination directory will be created but nothing will be installed
  396. into it. The ``FILE_PERMISSIONS`` and ``DIRECTORY_PERMISSIONS`` options
  397. specify permissions given to files and directories in the destination.
  398. If ``USE_SOURCE_PERMISSIONS`` is specified and ``FILE_PERMISSIONS`` is not,
  399. file permissions will be copied from the source directory structure.
  400. If no permissions are specified files will be given the default
  401. permissions specified in the ``FILES`` form of the command, and the
  402. directories will be given the default permissions specified in the
  403. ``PROGRAMS`` form of the command.
  404. The ``MESSAGE_NEVER`` option disables file installation status output.
  405. Installation of directories may be controlled with fine granularity
  406. using the ``PATTERN`` or ``REGEX`` options. These "match" options specify a
  407. globbing pattern or regular expression to match directories or files
  408. encountered within input directories. They may be used to apply
  409. certain options (see below) to a subset of the files and directories
  410. encountered. The full path to each input file or directory (with
  411. forward slashes) is matched against the expression. A ``PATTERN`` will
  412. match only complete file names: the portion of the full path matching
  413. the pattern must occur at the end of the file name and be preceded by
  414. a slash. A ``REGEX`` will match any portion of the full path but it may
  415. use ``/`` and ``$`` to simulate the ``PATTERN`` behavior. By default all
  416. files and directories are installed whether or not they are matched.
  417. The ``FILES_MATCHING`` option may be given before the first match option
  418. to disable installation of files (but not directories) not matched by
  419. any expression. For example, the code
  420. .. code-block:: cmake
  421. install(DIRECTORY src/ DESTINATION include/myproj
  422. FILES_MATCHING PATTERN "*.h")
  423. will extract and install header files from a source tree.
  424. Some options may follow a ``PATTERN`` or ``REGEX`` expression and are applied
  425. only to files or directories matching them. The ``EXCLUDE`` option will
  426. skip the matched file or directory. The ``PERMISSIONS`` option overrides
  427. the permissions setting for the matched file or directory. For
  428. example the code
  429. .. code-block:: cmake
  430. install(DIRECTORY icons scripts/ DESTINATION share/myproj
  431. PATTERN "CVS" EXCLUDE
  432. PATTERN "scripts/*"
  433. PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
  434. GROUP_EXECUTE GROUP_READ)
  435. will install the ``icons`` directory to ``share/myproj/icons`` and the
  436. ``scripts`` directory to ``share/myproj``. The icons will get default
  437. file permissions, the scripts will be given specific permissions, and any
  438. ``CVS`` directories will be excluded.
  439. Either a ``TYPE`` or a ``DESTINATION`` must be provided, but not both.
  440. A ``TYPE`` argument specifies the generic file type of the files within the
  441. listed directories being installed. A destination will then be set
  442. automatically by taking the corresponding variable from
  443. :module:`GNUInstallDirs`, or by using a built-in default if that variable
  444. is not defined. See the table below for the supported file types and their
  445. corresponding variables and built-in defaults. Projects can provide a
  446. ``DESTINATION`` argument instead of a file type if they wish to explicitly
  447. define the install destination.
  448. ======================= ================================== =========================
  449. ``TYPE`` Argument GNUInstallDirs Variable Built-In Default
  450. ======================= ================================== =========================
  451. ``BIN`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
  452. ``SBIN`` ``${CMAKE_INSTALL_SBINDIR}`` ``sbin``
  453. ``LIB`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
  454. ``INCLUDE`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
  455. ``SYSCONF`` ``${CMAKE_INSTALL_SYSCONFDIR}`` ``etc``
  456. ``SHAREDSTATE`` ``${CMAKE_INSTALL_SHARESTATEDIR}`` ``com``
  457. ``LOCALSTATE`` ``${CMAKE_INSTALL_LOCALSTATEDIR}`` ``var``
  458. ``RUNSTATE`` ``${CMAKE_INSTALL_RUNSTATEDIR}`` ``<LOCALSTATE dir>/run``
  459. ``DATA`` ``${CMAKE_INSTALL_DATADIR}`` ``<DATAROOT dir>``
  460. ``INFO`` ``${CMAKE_INSTALL_INFODIR}`` ``<DATAROOT dir>/info``
  461. ``LOCALE`` ``${CMAKE_INSTALL_LOCALEDIR}`` ``<DATAROOT dir>/locale``
  462. ``MAN`` ``${CMAKE_INSTALL_MANDIR}`` ``<DATAROOT dir>/man``
  463. ``DOC`` ``${CMAKE_INSTALL_DOCDIR}`` ``<DATAROOT dir>/doc``
  464. ======================= ================================== =========================
  465. Note that some of the types' built-in defaults use the ``DATAROOT`` directory as
  466. a prefix. The ``DATAROOT`` prefix is calculated similarly to the types, with
  467. ``CMAKE_INSTALL_DATAROOTDIR`` as the variable and ``share`` as the built-in
  468. default. You cannot use ``DATAROOT`` as a ``TYPE`` parameter; please use
  469. ``DATA`` instead.
  470. To make packages compliant with distribution filesystem layout policies, if
  471. projects must specify a ``DESTINATION``, it is recommended that they use a
  472. path that begins with the appropriate :module:`GNUInstallDirs` variable.
  473. This allows package maintainers to control the install destination by setting
  474. the appropriate cache variables.
  475. The list of ``dirs...`` given to ``DIRECTORY`` and an install destination
  476. given as a ``DESTINATION`` argument may use "generator expressions"
  477. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  478. manual for available expressions.
  479. Custom Installation Logic
  480. ^^^^^^^^^^^^^^^^^^^^^^^^^
  481. .. _`install(CODE)`:
  482. .. _`install(SCRIPT)`:
  483. .. _CODE:
  484. .. _SCRIPT:
  485. .. code-block:: cmake
  486. install([[SCRIPT <file>] [CODE <code>]]
  487. [COMPONENT <component>] [EXCLUDE_FROM_ALL] [...])
  488. The ``SCRIPT`` form will invoke the given CMake script files during
  489. installation. If the script file name is a relative path it will be
  490. interpreted with respect to the current source directory. The ``CODE``
  491. form will invoke the given CMake code during installation. Code is
  492. specified as a single argument inside a double-quoted string. For
  493. example, the code
  494. .. code-block:: cmake
  495. install(CODE "MESSAGE(\"Sample install message.\")")
  496. will print a message during installation.
  497. ``<file>`` or ``<code>`` may use "generator expressions" with the syntax
  498. ``$<...>`` (in the case of ``<file>``, this refers to their use in the file
  499. name, not the file's contents). See the
  500. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  501. Installing Exports
  502. ^^^^^^^^^^^^^^^^^^
  503. .. _`install(EXPORT)`:
  504. .. _EXPORT:
  505. .. code-block:: cmake
  506. install(EXPORT <export-name> DESTINATION <dir>
  507. [NAMESPACE <namespace>] [[FILE <name>.cmake]|
  508. [PERMISSIONS permissions...]
  509. [CONFIGURATIONS [Debug|Release|...]]
  510. [EXPORT_LINK_INTERFACE_LIBRARIES]
  511. [COMPONENT <component>]
  512. [EXCLUDE_FROM_ALL])
  513. install(EXPORT_ANDROID_MK <export-name> DESTINATION <dir> [...])
  514. The ``EXPORT`` form generates and installs a CMake file containing code to
  515. import targets from the installation tree into another project.
  516. Target installations are associated with the export ``<export-name>``
  517. using the ``EXPORT`` option of the `install(TARGETS)`_ signature
  518. documented above. The ``NAMESPACE`` option will prepend ``<namespace>`` to
  519. the target names as they are written to the import file. By default
  520. the generated file will be called ``<export-name>.cmake`` but the ``FILE``
  521. option may be used to specify a different name. The value given to
  522. the ``FILE`` option must be a file name with the ``.cmake`` extension.
  523. If a ``CONFIGURATIONS`` option is given then the file will only be installed
  524. when one of the named configurations is installed. Additionally, the
  525. generated import file will reference only the matching target
  526. configurations. The ``EXPORT_LINK_INTERFACE_LIBRARIES`` keyword, if
  527. present, causes the contents of the properties matching
  528. ``(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?`` to be exported, when
  529. policy :policy:`CMP0022` is ``NEW``.
  530. .. note::
  531. The installed ``<export-name>.cmake`` file may come with additional
  532. per-configuration ``<export-name>-*.cmake`` files to be loaded by
  533. globbing. Do not use an export name that is the same as the package
  534. name in combination with installing a ``<package-name>-config.cmake``
  535. file or the latter may be incorrectly matched by the glob and loaded.
  536. When a ``COMPONENT`` option is given, the listed ``<component>`` implicitly
  537. depends on all components mentioned in the export set. The exported
  538. ``<name>.cmake`` file will require each of the exported components to be
  539. present in order for dependent projects to build properly. For example, a
  540. project may define components ``Runtime`` and ``Development``, with shared
  541. libraries going into the ``Runtime`` component and static libraries and
  542. headers going into the ``Development`` component. The export set would also
  543. typically be part of the ``Development`` component, but it would export
  544. targets from both the ``Runtime`` and ``Development`` components. Therefore,
  545. the ``Runtime`` component would need to be installed if the ``Development``
  546. component was installed, but not vice versa. If the ``Development`` component
  547. was installed without the ``Runtime`` component, dependent projects that try
  548. to link against it would have build errors. Package managers, such as APT and
  549. RPM, typically handle this by listing the ``Runtime`` component as a dependency
  550. of the ``Development`` component in the package metadata, ensuring that the
  551. library is always installed if the headers and CMake export file are present.
  552. In addition to cmake language files, the ``EXPORT_ANDROID_MK`` mode maybe
  553. used to specify an export to the android ndk build system. This mode
  554. accepts the same options as the normal export mode. The Android
  555. NDK supports the use of prebuilt libraries, both static and shared. This
  556. allows cmake to build the libraries of a project and make them available
  557. to an ndk build system complete with transitive dependencies, include flags
  558. and defines required to use the libraries.
  559. The ``EXPORT`` form is useful to help outside projects use targets built
  560. and installed by the current project. For example, the code
  561. .. code-block:: cmake
  562. install(TARGETS myexe EXPORT myproj DESTINATION bin)
  563. install(EXPORT myproj NAMESPACE mp_ DESTINATION lib/myproj)
  564. install(EXPORT_ANDROID_MK myproj DESTINATION share/ndk-modules)
  565. will install the executable ``myexe`` to ``<prefix>/bin`` and code to import
  566. it in the file ``<prefix>/lib/myproj/myproj.cmake`` and
  567. ``<prefix>/share/ndk-modules/Android.mk``. An outside project
  568. may load this file with the include command and reference the ``myexe``
  569. executable from the installation tree using the imported target name
  570. ``mp_myexe`` as if the target were built in its own tree.
  571. .. note::
  572. This command supercedes the :command:`install_targets` command and
  573. the :prop_tgt:`PRE_INSTALL_SCRIPT` and :prop_tgt:`POST_INSTALL_SCRIPT`
  574. target properties. It also replaces the ``FILES`` forms of the
  575. :command:`install_files` and :command:`install_programs` commands.
  576. The processing order of these install rules relative to
  577. those generated by :command:`install_targets`,
  578. :command:`install_files`, and :command:`install_programs` commands
  579. is not defined.
  580. Generated Installation Script
  581. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  582. .. note::
  583. Use of this feature is not recommended. Please consider using the
  584. ``--install`` argument of :manual:`cmake(1)` instead.
  585. The ``install()`` command generates a file, ``cmake_install.cmake``, inside
  586. the build directory, which is used internally by the generated install target
  587. and by CPack. You can also invoke this script manually with ``cmake -P``. This
  588. script accepts several variables:
  589. ``COMPONENT``
  590. Set this variable to install only a single CPack component as opposed to all
  591. of them. For example, if you only want to install the ``Development``
  592. component, run ``cmake -DCOMPONENT=Development -P cmake_install.cmake``.
  593. ``BUILD_TYPE``
  594. Set this variable to change the build type if you are using a multi-config
  595. generator. For example, to install with the ``Debug`` configuration, run
  596. ``cmake -DBUILD_TYPE=Debug -P cmake_install.cmake``.
  597. ``DESTDIR``
  598. This is an environment variable rather than a CMake variable. It allows you
  599. to change the installation prefix on UNIX systems. See :envvar:`DESTDIR` for
  600. details.