install.rst 33 KB

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