install.rst 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. install
  2. -------
  3. .. only:: html
  4. .. contents::
  5. Specify rules to run at install time.
  6. Synopsis
  7. ^^^^^^^^
  8. .. parsed-literal::
  9. install(`TARGETS`_ <target>... [...])
  10. install(`IMPORTED_RUNTIME_ARTIFACTS`_ <target>... [...])
  11. install({`FILES`_ | `PROGRAMS`_} <file>... [...])
  12. install(`DIRECTORY`_ <dir>... [...])
  13. install(`SCRIPT`_ <file> [...])
  14. install(`CODE`_ <code> [...])
  15. install(`EXPORT`_ <export-name> [...])
  16. install(`RUNTIME_DEPENDENCY_SET`_ <set-name> [...])
  17. Introduction
  18. ^^^^^^^^^^^^
  19. This command generates installation rules for a project. Install rules
  20. specified by calls to the ``install()`` command within a source directory
  21. are executed in order during installation.
  22. .. versionchanged:: 3.14
  23. Install rules in subdirectories
  24. added by calls to the :command:`add_subdirectory` command are interleaved
  25. with those in the parent directory to run in the order declared (see
  26. policy :policy:`CMP0082`).
  27. .. versionchanged:: 3.22
  28. The environment variable :envvar:`CMAKE_INSTALL_MODE` can override the
  29. default copying behavior of ``install()``.
  30. .. versionchanged:: 3.31
  31. Projects can enable :prop_gbl:`INSTALL_PARALLEL` to enable a parallel
  32. installation. When using the parallel install, subdirectories added by calls
  33. to the :command:`add_subdirectory` command are installed independently
  34. and the order that install rules added in different subdirectories will run is
  35. not guaranteed.
  36. .. _`common options`:
  37. There are multiple signatures for this command. Some of them define
  38. installation options for files and targets. Options common to
  39. multiple signatures are covered here but they are valid only for
  40. signatures that specify them. The common options are:
  41. ``DESTINATION <dir>``
  42. Specify the directory on disk to which a file will be installed.
  43. ``<dir>`` should be a relative path. An absolute path is allowed,
  44. but not recommended.
  45. When a relative path is given it is interpreted relative to the value
  46. of the :variable:`CMAKE_INSTALL_PREFIX` variable.
  47. The prefix can be relocated at install time using the ``DESTDIR``
  48. mechanism explained in the :variable:`CMAKE_INSTALL_PREFIX` variable
  49. documentation.
  50. As absolute paths do not work with the ``cmake --install`` command's
  51. :option:`--prefix <cmake--install --prefix>` option, or with the
  52. :manual:`cpack <cpack(1)>` installer generators, it is strongly recommended
  53. to use relative paths throughout for best support by package maintainers.
  54. In particular, there is no need to make paths absolute by prepending
  55. :variable:`CMAKE_INSTALL_PREFIX`; this prefix is used by default if
  56. the DESTINATION is a relative path.
  57. If an absolute path (with a leading slash or drive letter) is given
  58. it is used verbatim.
  59. ``PERMISSIONS <permission>...``
  60. Specify permissions for installed files. Valid permissions are
  61. ``OWNER_READ``, ``OWNER_WRITE``, ``OWNER_EXECUTE``, ``GROUP_READ``,
  62. ``GROUP_WRITE``, ``GROUP_EXECUTE``, ``WORLD_READ``, ``WORLD_WRITE``,
  63. ``WORLD_EXECUTE``, ``SETUID``, and ``SETGID``. Permissions that do
  64. not make sense on certain platforms are ignored on those platforms.
  65. If this option is used multiple times in a single call, its list
  66. of permissions accumulates. If an :command:`install(TARGETS)` call
  67. uses `\<artifact-kind\>`_ arguments, a separate list of permissions
  68. is accumulated for each kind of artifact.
  69. ``CONFIGURATIONS <config>...``
  70. Specify a list of build configurations for which the install rule
  71. applies (Debug, Release, etc.).
  72. If this option is used multiple times in a single call, its list
  73. of configurations accumulates. If an :command:`install(TARGETS)`
  74. call uses `\<artifact-kind\>`_ arguments, a separate list of
  75. configurations is accumulated for each kind of artifact.
  76. ``COMPONENT <component>``
  77. Specify an installation component name with which the install rule
  78. is associated, such as ``Runtime`` or ``Development``. During
  79. component-specific installation only install rules associated with
  80. the given component name will be executed. During a full installation
  81. all components are installed unless marked with ``EXCLUDE_FROM_ALL``.
  82. If ``COMPONENT`` is not provided a default component "Unspecified" is
  83. created. The default component name may be controlled with the
  84. :variable:`CMAKE_INSTALL_DEFAULT_COMPONENT_NAME` variable.
  85. ``EXCLUDE_FROM_ALL``
  86. .. versionadded:: 3.6
  87. Specify that the file is excluded from a full installation and only
  88. installed as part of a component-specific installation
  89. ``RENAME <name>``
  90. Specify a name for an installed file that may be different from the
  91. original file. Renaming is allowed only when a single file is
  92. installed by the command.
  93. ``OPTIONAL``
  94. Specify that it is not an error if the file to be installed does
  95. not exist.
  96. .. versionadded:: 3.1
  97. Command signatures that install files may print messages during
  98. installation. Use the :variable:`CMAKE_INSTALL_MESSAGE` variable
  99. to control which messages are printed.
  100. .. versionadded:: 3.11
  101. Many of the ``install()`` variants implicitly create the directories
  102. containing the installed files. If
  103. :variable:`CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS` is set, these
  104. directories will be created with the permissions specified. Otherwise,
  105. they will be created according to the uname rules on Unix-like platforms.
  106. Windows platforms are unaffected.
  107. Signatures
  108. ^^^^^^^^^^
  109. .. signature::
  110. install(TARGETS <target>... [...])
  111. Install target :ref:`Output Artifacts` and associated files:
  112. .. code-block:: cmake
  113. install(TARGETS <target>... [EXPORT <export-name>]
  114. [RUNTIME_DEPENDENCIES <arg>...|RUNTIME_DEPENDENCY_SET <set-name>]
  115. [<artifact-option>...]
  116. [<artifact-kind> <artifact-option>...]...
  117. [INCLUDES DESTINATION [<dir> ...]]
  118. )
  119. where ``<artifact-option>...`` group may contain:
  120. .. code-block:: cmake
  121. [DESTINATION <dir>]
  122. [PERMISSIONS <permission>...]
  123. [CONFIGURATIONS <config>...]
  124. [COMPONENT <component>]
  125. [NAMELINK_COMPONENT <component>]
  126. [OPTIONAL] [EXCLUDE_FROM_ALL]
  127. [NAMELINK_ONLY|NAMELINK_SKIP]
  128. The first ``<artifact-option>...`` group applies to target
  129. :ref:`Output Artifacts` that do not have a dedicated group specified
  130. later in the same call.
  131. .. _`<artifact-kind>`:
  132. Each ``<artifact-kind> <artifact-option>...`` group applies to
  133. :ref:`Output Artifacts` of the specified artifact kind:
  134. ``ARCHIVE``
  135. Target artifacts of this kind include:
  136. * *Static libraries*
  137. (except on macOS when marked as ``FRAMEWORK``, see below);
  138. * *DLL import libraries*
  139. (on all Windows-based systems including Cygwin; they have extension
  140. ``.lib``, in contrast to the ``.dll`` libraries that go to ``RUNTIME``);
  141. * On AIX, the *linker import file* created for executables with
  142. :prop_tgt:`ENABLE_EXPORTS` enabled.
  143. * On macOS, the *linker import file* created for shared libraries with
  144. :prop_tgt:`ENABLE_EXPORTS` enabled (except when marked as ``FRAMEWORK``,
  145. see below).
  146. ``LIBRARY``
  147. Target artifacts of this kind include:
  148. * *Shared libraries*, except
  149. - DLLs (these go to ``RUNTIME``, see below),
  150. - on macOS when marked as ``FRAMEWORK`` (see below).
  151. ``RUNTIME``
  152. Target artifacts of this kind include:
  153. * *Executables*
  154. (except on macOS when marked as ``MACOSX_BUNDLE``, see ``BUNDLE`` below);
  155. * DLLs (on all Windows-based systems including Cygwin; note that the
  156. accompanying import libraries are of kind ``ARCHIVE``).
  157. ``OBJECTS``
  158. .. versionadded:: 3.9
  159. Object files associated with *object libraries*.
  160. ``FRAMEWORK``
  161. Both static and shared libraries marked with the ``FRAMEWORK``
  162. property are treated as ``FRAMEWORK`` targets on macOS.
  163. ``BUNDLE``
  164. Executables marked with the :prop_tgt:`MACOSX_BUNDLE` property are treated as
  165. ``BUNDLE`` targets on macOS.
  166. ``PUBLIC_HEADER``
  167. Any :prop_tgt:`PUBLIC_HEADER` files associated with a library are installed in
  168. the destination specified by the ``PUBLIC_HEADER`` argument on non-Apple
  169. platforms. Rules defined by this argument are ignored for :prop_tgt:`FRAMEWORK`
  170. libraries on Apple platforms because the associated files are installed
  171. into the appropriate locations inside the framework folder. See
  172. :prop_tgt:`PUBLIC_HEADER` for details.
  173. ``PRIVATE_HEADER``
  174. Similar to ``PUBLIC_HEADER``, but for ``PRIVATE_HEADER`` files. See
  175. :prop_tgt:`PRIVATE_HEADER` for details.
  176. ``RESOURCE``
  177. Similar to ``PUBLIC_HEADER`` and ``PRIVATE_HEADER``, but for
  178. ``RESOURCE`` files. See :prop_tgt:`RESOURCE` for details.
  179. ``FILE_SET <set-name>``
  180. .. versionadded:: 3.23
  181. File sets are defined by the :command:`target_sources(FILE_SET)` command.
  182. If the file set ``<set-name>`` exists and is ``PUBLIC`` or ``INTERFACE``,
  183. any files in the set are installed under the destination (see below).
  184. The directory structure relative to the file set's base directories is
  185. preserved. For example, a file added to the file set as
  186. ``/blah/include/myproj/here.h`` with a base directory ``/blah/include``
  187. would be installed to ``myproj/here.h`` below the destination.
  188. ``CXX_MODULES_BMI``
  189. .. versionadded:: 3.28
  190. Any module files from C++ modules from ``PUBLIC`` sources in a file set of
  191. type ``CXX_MODULES`` will be installed to the given ``DESTINATION``. All
  192. modules are placed directly in the destination as no directory structure is
  193. derived from the names of the modules. An empty ``DESTINATION`` may be used
  194. to suppress installing these files (for use in generic code).
  195. For regular executables, static libraries and shared libraries, the
  196. ``DESTINATION`` argument is not required. For these target types, when
  197. ``DESTINATION`` is omitted, a default destination will be taken from the
  198. appropriate variable from :module:`GNUInstallDirs`, or set to a built-in
  199. default value if that variable is not defined. The same is true for file
  200. sets, and the public and private headers associated with the installed
  201. targets through the :prop_tgt:`PUBLIC_HEADER` and :prop_tgt:`PRIVATE_HEADER`
  202. target properties. A destination must always be provided for module libraries,
  203. Apple bundles and frameworks. A destination can be omitted for interface and
  204. object libraries, but they are handled differently (see the discussion of this
  205. topic toward the end of this section).
  206. For shared libraries on DLL platforms, if neither ``RUNTIME`` nor ``ARCHIVE``
  207. destinations are specified, both the ``RUNTIME`` and ``ARCHIVE`` components are
  208. installed to their default destinations. If either a ``RUNTIME`` or ``ARCHIVE``
  209. destination is specified, the component is installed to that destination, and
  210. the other component is not installed. If both ``RUNTIME`` and ``ARCHIVE``
  211. destinations are specified, then both components are installed to their
  212. respective destinations.
  213. The following table shows the target types with their associated variables and
  214. built-in defaults that apply when no destination is given:
  215. =============================== =============================== ======================
  216. Target Type GNUInstallDirs Variable Built-In Default
  217. =============================== =============================== ======================
  218. ``RUNTIME`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
  219. ``LIBRARY`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
  220. ``ARCHIVE`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
  221. ``PRIVATE_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
  222. ``PUBLIC_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
  223. ``FILE_SET`` (type ``HEADERS``) ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
  224. =============================== =============================== ======================
  225. Projects wishing to follow the common practice of installing headers into a
  226. project-specific subdirectory may prefer using file sets with appropriate
  227. paths and base directories. Otherwise, they must provide a ``DESTINATION``
  228. instead of being able to rely on the above (see next example below).
  229. To make packages compliant with distribution filesystem layout policies, if
  230. projects must specify a ``DESTINATION``, it is strongly recommended that they use
  231. a path that begins with the appropriate relative :module:`GNUInstallDirs` variable.
  232. This allows package maintainers to control the install destination by setting
  233. the appropriate cache variables. The following example shows a static library
  234. being installed to the default destination provided by
  235. :module:`GNUInstallDirs`, but with its headers installed to a project-specific
  236. subdirectory without using file sets:
  237. .. code-block:: cmake
  238. add_library(mylib STATIC ...)
  239. set_target_properties(mylib PROPERTIES PUBLIC_HEADER mylib.h)
  240. include(GNUInstallDirs)
  241. install(TARGETS mylib
  242. PUBLIC_HEADER
  243. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/myproj
  244. )
  245. In addition to the `common options`_ listed above, each target can accept
  246. the following additional arguments:
  247. ``NAMELINK_COMPONENT``
  248. .. versionadded:: 3.12
  249. On some platforms a versioned shared library has a symbolic link such
  250. as::
  251. lib<name>.so -> lib<name>.so.1
  252. where ``lib<name>.so.1`` is the soname of the library and ``lib<name>.so``
  253. is a "namelink" allowing linkers to find the library when given
  254. ``-l<name>``. The ``NAMELINK_COMPONENT`` option is similar to the
  255. ``COMPONENT`` option, but it changes the installation component of a shared
  256. library namelink if one is generated. If not specified, this defaults to the
  257. value of ``COMPONENT``. It is an error to use this parameter outside of a
  258. ``LIBRARY`` block.
  259. .. versionchanged:: 3.27
  260. This parameter is also usable for an ``ARCHIVE`` block to manage
  261. the linker import file created, on macOS, for shared libraries with
  262. :prop_tgt:`ENABLE_EXPORTS` enabled.
  263. See the `Example: Install Targets with Per-Artifact Components`_
  264. for an example using ``NAMELINK_COMPONENT``.
  265. This option is typically used for package managers that have separate
  266. runtime and development packages. For example, on Debian systems, the
  267. library is expected to be in the runtime package, and the headers and
  268. namelink are expected to be in the development package.
  269. See the :prop_tgt:`VERSION` and :prop_tgt:`SOVERSION` target properties for
  270. details on creating versioned shared libraries.
  271. ``NAMELINK_ONLY``
  272. This option causes the installation of only the namelink when a library
  273. target is installed. On platforms where versioned shared libraries do not
  274. have namelinks or when a library is not versioned, the ``NAMELINK_ONLY``
  275. option installs nothing. It is an error to use this parameter outside of a
  276. ``LIBRARY`` block.
  277. .. versionchanged:: 3.27
  278. This parameter is also usable for an ``ARCHIVE`` block to manage
  279. the linker import file created, on macOS, for shared libraries with
  280. :prop_tgt:`ENABLE_EXPORTS` enabled.
  281. When ``NAMELINK_ONLY`` is given, either ``NAMELINK_COMPONENT`` or
  282. ``COMPONENT`` may be used to specify the installation component of the
  283. namelink, but ``COMPONENT`` should generally be preferred.
  284. ``NAMELINK_SKIP``
  285. Similar to ``NAMELINK_ONLY``, but it has the opposite effect: it causes the
  286. installation of library files other than the namelink when a library target
  287. is installed. When neither ``NAMELINK_ONLY`` or ``NAMELINK_SKIP`` are given,
  288. both portions are installed. On platforms where versioned shared libraries
  289. do not have symlinks or when a library is not versioned, ``NAMELINK_SKIP``
  290. installs the library. It is an error to use this parameter outside of a
  291. ``LIBRARY`` block.
  292. .. versionchanged:: 3.27
  293. This parameter is also usable for an ``ARCHIVE`` block to manage
  294. the linker import file created, on macOS, for shared libraries with
  295. :prop_tgt:`ENABLE_EXPORTS` enabled.
  296. If ``NAMELINK_SKIP`` is specified, ``NAMELINK_COMPONENT`` has no effect. It
  297. is not recommended to use ``NAMELINK_SKIP`` in conjunction with
  298. ``NAMELINK_COMPONENT``.
  299. The :command:`install(TARGETS)` command can also accept the following
  300. options at the top level:
  301. ``EXPORT``
  302. This option associates the installed target files with an export called
  303. ``<export-name>``. It must appear before any target options.
  304. To actually install the export file itself, call
  305. :command:`install(EXPORT)`, documented below.
  306. See documentation of the :prop_tgt:`EXPORT_NAME` target property to change
  307. the name of the exported target.
  308. If ``EXPORT`` is used and the targets include ``PUBLIC`` or ``INTERFACE``
  309. file sets, all of them must be specified with ``FILE_SET`` arguments. All
  310. ``PUBLIC`` or ``INTERFACE`` file sets associated with a target are included
  311. in the export.
  312. ``INCLUDES DESTINATION``
  313. This option specifies a list of directories which will be added to the
  314. :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` target property of the
  315. ``<targets>`` when exported by the :command:`install(EXPORT)` command.
  316. If a relative path is specified, it is treated as relative to the
  317. :genex:`$<INSTALL_PREFIX>`.
  318. ``RUNTIME_DEPENDENCY_SET <set-name>``
  319. .. versionadded:: 3.21
  320. This option causes all runtime dependencies of installed executable, shared
  321. library, and module targets to be added to the specified runtime dependency
  322. set. This set can then be installed with an
  323. :command:`install(RUNTIME_DEPENDENCY_SET)` command.
  324. This keyword and the ``RUNTIME_DEPENDENCIES`` keyword are mutually
  325. exclusive.
  326. ``RUNTIME_DEPENDENCIES <arg>...``
  327. .. versionadded:: 3.21
  328. This option causes all runtime dependencies of installed executable, shared
  329. library, and module targets to be installed along with the targets
  330. themselves. The ``RUNTIME``, ``LIBRARY``, ``FRAMEWORK``, and generic
  331. arguments are used to determine the properties (``DESTINATION``,
  332. ``COMPONENT``, etc.) of the installation of these dependencies.
  333. ``RUNTIME_DEPENDENCIES`` is semantically equivalent to the following pair
  334. of calls:
  335. .. code-block:: cmake
  336. install(TARGETS ... RUNTIME_DEPENDENCY_SET <set-name>)
  337. install(RUNTIME_DEPENDENCY_SET <set-name> <arg>...)
  338. where ``<set-name>`` will be a randomly generated set name.
  339. ``<arg>...`` may include any of the following keywords supported by
  340. the :command:`install(RUNTIME_DEPENDENCY_SET)` command:
  341. * ``DIRECTORIES``
  342. * ``PRE_INCLUDE_REGEXES``
  343. * ``PRE_EXCLUDE_REGEXES``
  344. * ``POST_INCLUDE_REGEXES``
  345. * ``POST_EXCLUDE_REGEXES``
  346. * ``POST_INCLUDE_FILES``
  347. * ``POST_EXCLUDE_FILES``
  348. The ``RUNTIME_DEPENDENCIES`` and ``RUNTIME_DEPENDENCY_SET`` keywords are
  349. mutually exclusive.
  350. :ref:`Interface Libraries` may be listed among the targets to install.
  351. They install no artifacts but will be included in an associated ``EXPORT``.
  352. If :ref:`Object Libraries` are listed but given no destination for their
  353. object files, they will be exported as :ref:`Interface Libraries`.
  354. This is sufficient to satisfy transitive usage requirements of other
  355. targets that link to the object libraries in their implementation.
  356. Installing a target with the :prop_tgt:`EXCLUDE_FROM_ALL` target property
  357. set to ``TRUE`` has undefined behavior.
  358. .. versionadded:: 3.3
  359. An install destination given as a ``DESTINATION`` argument may
  360. use "generator expressions" with the syntax ``$<...>``. See the
  361. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  362. .. versionadded:: 3.13
  363. :command:`install(TARGETS)` can install targets that were created in
  364. other directories. When using such cross-directory install rules, running
  365. ``make install`` (or similar) from a subdirectory will not guarantee that
  366. targets from other directories are up-to-date. You can use
  367. :command:`target_link_libraries` or :command:`add_dependencies`
  368. to ensure that such out-of-directory targets are built before the
  369. subdirectory-specific install rules are run.
  370. .. signature::
  371. install(IMPORTED_RUNTIME_ARTIFACTS <target>... [...])
  372. .. versionadded:: 3.21
  373. Install runtime artifacts of imported targets:
  374. .. code-block:: cmake
  375. install(IMPORTED_RUNTIME_ARTIFACTS <target>...
  376. [RUNTIME_DEPENDENCY_SET <set-name>]
  377. [[LIBRARY|RUNTIME|FRAMEWORK|BUNDLE]
  378. [DESTINATION <dir>]
  379. [PERMISSIONS <permission>...]
  380. [CONFIGURATIONS <config>...]
  381. [COMPONENT <component>]
  382. [OPTIONAL] [EXCLUDE_FROM_ALL]
  383. ] [...]
  384. )
  385. The ``IMPORTED_RUNTIME_ARTIFACTS`` form specifies rules for installing the
  386. runtime artifacts of imported targets. Projects may do this if they want to
  387. bundle outside executables or modules inside their installation. The
  388. ``LIBRARY``, ``RUNTIME``, ``FRAMEWORK``, and ``BUNDLE`` arguments have the
  389. same semantics that they do in the `TARGETS`_ mode. Only the runtime artifacts
  390. of imported targets are installed (except in the case of :prop_tgt:`FRAMEWORK`
  391. libraries, :prop_tgt:`MACOSX_BUNDLE` executables, and :prop_tgt:`BUNDLE`
  392. CFBundles.) For example, headers and import libraries associated with DLLs are
  393. not installed. In the case of :prop_tgt:`FRAMEWORK` libraries,
  394. :prop_tgt:`MACOSX_BUNDLE` executables, and :prop_tgt:`BUNDLE` CFBundles, the
  395. entire directory is installed.
  396. The ``RUNTIME_DEPENDENCY_SET`` option causes the runtime artifacts of the
  397. imported executable, shared library, and module library ``targets`` to be
  398. added to the ``<set-name>`` runtime dependency set. This set can then be
  399. installed with an :command:`install(RUNTIME_DEPENDENCY_SET)` command.
  400. .. signature::
  401. install(FILES <file>... [...])
  402. install(PROGRAMS <program>... [...])
  403. .. note::
  404. If installing header files, consider using file sets defined by
  405. :command:`target_sources(FILE_SET)` instead. File sets associate
  406. headers with a target and they install as part of the target.
  407. Install files or programs:
  408. .. code-block:: cmake
  409. install(<FILES|PROGRAMS> <file>...
  410. TYPE <type> | DESTINATION <dir>
  411. [PERMISSIONS <permission>...]
  412. [CONFIGURATIONS <config>...]
  413. [COMPONENT <component>]
  414. [RENAME <name>] [OPTIONAL] [EXCLUDE_FROM_ALL])
  415. The ``FILES`` form specifies rules for installing files for a project.
  416. File names given as relative paths are interpreted with respect to the
  417. current source directory. Files installed by this form are by default
  418. given permissions ``OWNER_WRITE``, ``OWNER_READ``, ``GROUP_READ``, and
  419. ``WORLD_READ`` if no ``PERMISSIONS`` argument is given.
  420. The ``PROGRAMS`` form is identical to the ``FILES`` form except that the
  421. default permissions for the installed file also include ``OWNER_EXECUTE``,
  422. ``GROUP_EXECUTE``, and ``WORLD_EXECUTE``. This form is intended to install
  423. programs that are not targets, such as shell scripts. Use the ``TARGETS``
  424. form to install targets built within the project.
  425. The list of ``files...`` given to ``FILES`` or ``PROGRAMS`` may use
  426. "generator expressions" with the syntax ``$<...>``. See the
  427. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  428. However, if any item begins in a generator expression it must evaluate
  429. to a full path.
  430. Either a ``TYPE`` or a ``DESTINATION`` must be provided, but not both.
  431. A ``TYPE`` argument specifies the generic file type of the files being
  432. installed. A destination will then be set automatically by taking the
  433. corresponding variable from :module:`GNUInstallDirs`, or by using a
  434. built-in default if that variable is not defined. See the table below for
  435. the supported file types and their corresponding variables and built-in
  436. defaults. Projects can provide a ``DESTINATION`` argument instead of a
  437. file type if they wish to explicitly define the install destination.
  438. ======================= ================================== =========================
  439. ``TYPE`` Argument GNUInstallDirs Variable Built-In Default
  440. ======================= ================================== =========================
  441. ``BIN`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
  442. ``SBIN`` ``${CMAKE_INSTALL_SBINDIR}`` ``sbin``
  443. ``LIB`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
  444. ``INCLUDE`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
  445. ``SYSCONF`` ``${CMAKE_INSTALL_SYSCONFDIR}`` ``etc``
  446. ``SHAREDSTATE`` ``${CMAKE_INSTALL_SHARESTATEDIR}`` ``com``
  447. ``LOCALSTATE`` ``${CMAKE_INSTALL_LOCALSTATEDIR}`` ``var``
  448. ``RUNSTATE`` ``${CMAKE_INSTALL_RUNSTATEDIR}`` ``<LOCALSTATE dir>/run``
  449. ``DATA`` ``${CMAKE_INSTALL_DATADIR}`` ``<DATAROOT dir>``
  450. ``INFO`` ``${CMAKE_INSTALL_INFODIR}`` ``<DATAROOT dir>/info``
  451. ``LOCALE`` ``${CMAKE_INSTALL_LOCALEDIR}`` ``<DATAROOT dir>/locale``
  452. ``MAN`` ``${CMAKE_INSTALL_MANDIR}`` ``<DATAROOT dir>/man``
  453. ``DOC`` ``${CMAKE_INSTALL_DOCDIR}`` ``<DATAROOT dir>/doc``
  454. ======================= ================================== =========================
  455. Projects wishing to follow the common practice of installing headers into a
  456. project-specific subdirectory will need to provide a destination rather than
  457. rely on the above. Using file sets for headers instead of ``install(FILES)``
  458. would be even better (see :command:`target_sources(FILE_SET)`).
  459. Note that some of the types' built-in defaults use the ``DATAROOT`` directory as
  460. a prefix. The ``DATAROOT`` prefix is calculated similarly to the types, with
  461. ``CMAKE_INSTALL_DATAROOTDIR`` as the variable and ``share`` as the built-in
  462. default. You cannot use ``DATAROOT`` as a ``TYPE`` parameter; please use
  463. ``DATA`` instead.
  464. To make packages compliant with distribution filesystem layout policies, if
  465. projects must specify a ``DESTINATION``, it is strongly recommended that they use
  466. a path that begins with the appropriate relative :module:`GNUInstallDirs` variable.
  467. This allows package maintainers to control the install destination by setting
  468. the appropriate cache variables. The following example shows how to follow
  469. this advice while installing an image to a project-specific documentation
  470. subdirectory:
  471. .. code-block:: cmake
  472. include(GNUInstallDirs)
  473. install(FILES logo.png
  474. DESTINATION ${CMAKE_INSTALL_DOCDIR}/myproj
  475. )
  476. .. versionadded:: 3.4
  477. An install destination given as a ``DESTINATION`` argument may
  478. use "generator expressions" with the syntax ``$<...>``. See the
  479. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  480. .. versionadded:: 3.20
  481. An install rename given as a ``RENAME`` argument may
  482. use "generator expressions" with the syntax ``$<...>``. See the
  483. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  484. .. signature::
  485. install(DIRECTORY <dir>... [...])
  486. .. note::
  487. To install a directory sub-tree of headers, consider using file sets
  488. defined by :command:`target_sources(FILE_SET)` instead. File sets not only
  489. preserve directory structure, they also associate headers with a target
  490. and install as part of the target.
  491. Install the contents of one or more directories:
  492. .. code-block:: cmake
  493. install(DIRECTORY dirs...
  494. TYPE <type> | DESTINATION <dir>
  495. [FILE_PERMISSIONS <permission>...]
  496. [DIRECTORY_PERMISSIONS <permission>...]
  497. [USE_SOURCE_PERMISSIONS] [OPTIONAL] [MESSAGE_NEVER]
  498. [CONFIGURATIONS <config>...]
  499. [COMPONENT <component>] [EXCLUDE_FROM_ALL]
  500. [FILES_MATCHING]
  501. [[PATTERN <pattern> | REGEX <regex>]
  502. [EXCLUDE] [PERMISSIONS <permission>...]] [...])
  503. The ``DIRECTORY`` form installs contents of one or more directories to a
  504. given destination. The directory structure is copied verbatim to the
  505. destination. The last component of each directory name is appended to
  506. the destination directory but a trailing slash may be used to avoid
  507. this because it leaves the last component empty. Directory names
  508. given as relative paths are interpreted with respect to the current
  509. source directory. If no input directory names are given the
  510. destination directory will be created but nothing will be installed
  511. into it. The ``FILE_PERMISSIONS`` and ``DIRECTORY_PERMISSIONS`` options
  512. specify permissions given to files and directories in the destination.
  513. If ``USE_SOURCE_PERMISSIONS`` is specified and ``FILE_PERMISSIONS`` is not,
  514. file permissions will be copied from the source directory structure.
  515. If no permissions are specified files will be given the default
  516. permissions specified in the ``FILES`` form of the command, and the
  517. directories will be given the default permissions specified in the
  518. ``PROGRAMS`` form of the command.
  519. .. versionadded:: 3.1
  520. The ``MESSAGE_NEVER`` option disables file installation status output.
  521. Installation of directories may be controlled with fine granularity
  522. using the ``PATTERN`` or ``REGEX`` options. These "match" options specify a
  523. globbing pattern or regular expression to match directories or files
  524. encountered within input directories. They may be used to apply
  525. certain options (see below) to a subset of the files and directories
  526. encountered. The full path to each input file or directory (with
  527. forward slashes) is matched against the expression. A ``PATTERN`` will
  528. match only complete file names: the portion of the full path matching
  529. the pattern must occur at the end of the file name and be preceded by
  530. a slash. A ``REGEX`` will match any portion of the full path but it may
  531. use ``/`` and ``$`` to simulate the ``PATTERN`` behavior. By default all
  532. files and directories are installed whether or not they are matched.
  533. The ``FILES_MATCHING`` option may be given before the first match option
  534. to disable installation of files (but not directories) not matched by
  535. any expression. For example, the code
  536. .. code-block:: cmake
  537. install(DIRECTORY src/ DESTINATION doc/myproj
  538. FILES_MATCHING PATTERN "*.png")
  539. will extract and install images from a source tree.
  540. Some options may follow a ``PATTERN`` or ``REGEX`` expression as described
  541. under :ref:`string(REGEX) <Regex Specification>` and are applied
  542. only to files or directories matching them. The ``EXCLUDE`` option will
  543. skip the matched file or directory. The ``PERMISSIONS`` option overrides
  544. the permissions setting for the matched file or directory. For
  545. example the code
  546. .. code-block:: cmake
  547. install(DIRECTORY icons scripts/ DESTINATION share/myproj
  548. PATTERN "CVS" EXCLUDE
  549. PATTERN "scripts/*"
  550. PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
  551. GROUP_EXECUTE GROUP_READ)
  552. will install the ``icons`` directory to ``share/myproj/icons`` and the
  553. ``scripts`` directory to ``share/myproj``. The icons will get default
  554. file permissions, the scripts will be given specific permissions, and any
  555. ``CVS`` directories will be excluded.
  556. Either a ``TYPE`` or a ``DESTINATION`` must be provided, but not both.
  557. A ``TYPE`` argument specifies the generic file type of the files within the
  558. listed directories being installed. A destination will then be set
  559. automatically by taking the corresponding variable from
  560. :module:`GNUInstallDirs`, or by using a built-in default if that variable
  561. is not defined. See the table below for the supported file types and their
  562. corresponding variables and built-in defaults. Projects can provide a
  563. ``DESTINATION`` argument instead of a file type if they wish to explicitly
  564. define the install destination.
  565. ======================= ================================== =========================
  566. ``TYPE`` Argument GNUInstallDirs Variable Built-In Default
  567. ======================= ================================== =========================
  568. ``BIN`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
  569. ``SBIN`` ``${CMAKE_INSTALL_SBINDIR}`` ``sbin``
  570. ``LIB`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
  571. ``INCLUDE`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
  572. ``SYSCONF`` ``${CMAKE_INSTALL_SYSCONFDIR}`` ``etc``
  573. ``SHAREDSTATE`` ``${CMAKE_INSTALL_SHARESTATEDIR}`` ``com``
  574. ``LOCALSTATE`` ``${CMAKE_INSTALL_LOCALSTATEDIR}`` ``var``
  575. ``RUNSTATE`` ``${CMAKE_INSTALL_RUNSTATEDIR}`` ``<LOCALSTATE dir>/run``
  576. ``DATA`` ``${CMAKE_INSTALL_DATADIR}`` ``<DATAROOT dir>``
  577. ``INFO`` ``${CMAKE_INSTALL_INFODIR}`` ``<DATAROOT dir>/info``
  578. ``LOCALE`` ``${CMAKE_INSTALL_LOCALEDIR}`` ``<DATAROOT dir>/locale``
  579. ``MAN`` ``${CMAKE_INSTALL_MANDIR}`` ``<DATAROOT dir>/man``
  580. ``DOC`` ``${CMAKE_INSTALL_DOCDIR}`` ``<DATAROOT dir>/doc``
  581. ======================= ================================== =========================
  582. Note that some of the types' built-in defaults use the ``DATAROOT`` directory as
  583. a prefix. The ``DATAROOT`` prefix is calculated similarly to the types, with
  584. ``CMAKE_INSTALL_DATAROOTDIR`` as the variable and ``share`` as the built-in
  585. default. You cannot use ``DATAROOT`` as a ``TYPE`` parameter; please use
  586. ``DATA`` instead.
  587. To make packages compliant with distribution filesystem layout policies, if
  588. projects must specify a ``DESTINATION``, it is strongly recommended that they use
  589. a path that begins with the appropriate relative :module:`GNUInstallDirs` variable.
  590. This allows package maintainers to control the install destination by setting
  591. the appropriate cache variables.
  592. .. versionadded:: 3.4
  593. An install destination given as a ``DESTINATION`` argument may
  594. use "generator expressions" with the syntax ``$<...>``. See the
  595. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  596. .. versionadded:: 3.5
  597. The list of ``dirs...`` given to ``DIRECTORY`` may use
  598. "generator expressions" too.
  599. .. signature::
  600. install(SCRIPT <file> [...])
  601. install(CODE <code> [...])
  602. Invoke CMake scripts or code during installation:
  603. .. code-block:: cmake
  604. install([[SCRIPT <file>] [CODE <code>]]
  605. [ALL_COMPONENTS | COMPONENT <component>]
  606. [EXCLUDE_FROM_ALL] [...])
  607. The ``SCRIPT`` form will invoke the given CMake script files during
  608. installation. If the script file name is a relative path it will be
  609. interpreted with respect to the current source directory. The ``CODE``
  610. form will invoke the given CMake code during installation. Code is
  611. specified as a single argument inside a double-quoted string. For
  612. example, the code
  613. .. code-block:: cmake
  614. install(CODE "MESSAGE(\"Sample install message.\")")
  615. will print a message during installation.
  616. .. versionadded:: 3.21
  617. When the ``ALL_COMPONENTS`` option is given, the custom installation
  618. script code will be executed for every component of a component-specific
  619. installation. This option is mutually exclusive with the ``COMPONENT``
  620. option.
  621. .. versionadded:: 3.14
  622. ``<file>`` or ``<code>`` may use "generator expressions" with the syntax
  623. ``$<...>`` (in the case of ``<file>``, this refers to their use in the file
  624. name, not the file's contents). See the
  625. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  626. .. signature::
  627. install(EXPORT <export-name> [...])
  628. Install a CMake file exporting targets for dependent projects:
  629. .. code-block:: cmake
  630. install(EXPORT <export-name> DESTINATION <dir>
  631. [NAMESPACE <namespace>] [FILE <name>.cmake]
  632. [PERMISSIONS <permission>...]
  633. [CONFIGURATIONS <config>...]
  634. [CXX_MODULES_DIRECTORY <directory>]
  635. [EXPORT_LINK_INTERFACE_LIBRARIES]
  636. [COMPONENT <component>]
  637. [EXCLUDE_FROM_ALL]
  638. [EXPORT_PACKAGE_DEPENDENCIES])
  639. install(EXPORT_ANDROID_MK <export-name> DESTINATION <dir> [...])
  640. The ``EXPORT`` form generates and installs a CMake file containing code to
  641. import targets from the installation tree into another project.
  642. Target installations are associated with the export ``<export-name>``
  643. using the ``EXPORT`` option of the :command:`install(TARGETS)` signature
  644. documented above. The ``NAMESPACE`` option will prepend ``<namespace>`` to
  645. the target names as they are written to the import file. By default
  646. the generated file will be called ``<export-name>.cmake`` but the ``FILE``
  647. option may be used to specify a different name. The value given to
  648. the ``FILE`` option must be a file name with the ``.cmake`` extension.
  649. If a ``CONFIGURATIONS`` option is given then the file will only be installed
  650. when one of the named configurations is installed. Additionally, the
  651. generated import file will reference only the matching target
  652. configurations. See the :variable:`CMAKE_MAP_IMPORTED_CONFIG_<CONFIG>`
  653. variable to map configurations of dependent projects to the installed
  654. configurations. The ``EXPORT_LINK_INTERFACE_LIBRARIES`` keyword, if
  655. present, causes the contents of the properties matching
  656. ``(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?`` to be exported, when
  657. policy :policy:`CMP0022` is ``NEW``.
  658. .. note::
  659. The installed ``<export-name>.cmake`` file may come with additional
  660. per-configuration ``<export-name>-*.cmake`` files to be loaded by
  661. globbing. Do not use an export name that is the same as the package
  662. name in combination with installing a ``<package-name>-config.cmake``
  663. file or the latter may be incorrectly matched by the glob and loaded.
  664. When a ``COMPONENT`` option is given, the listed ``<component>`` implicitly
  665. depends on all components mentioned in the export set. The exported
  666. ``<name>.cmake`` file will require each of the exported components to be
  667. present in order for dependent projects to build properly. For example, a
  668. project may define components ``Runtime`` and ``Development``, with shared
  669. libraries going into the ``Runtime`` component and static libraries and
  670. headers going into the ``Development`` component. The export set would also
  671. typically be part of the ``Development`` component, but it would export
  672. targets from both the ``Runtime`` and ``Development`` components. Therefore,
  673. the ``Runtime`` component would need to be installed if the ``Development``
  674. component was installed, but not vice versa. If the ``Development`` component
  675. was installed without the ``Runtime`` component, dependent projects that try
  676. to link against it would have build errors. Package managers, such as APT and
  677. RPM, typically handle this by listing the ``Runtime`` component as a dependency
  678. of the ``Development`` component in the package metadata, ensuring that the
  679. library is always installed if the headers and CMake export file are present.
  680. .. versionadded:: 3.7
  681. In addition to cmake language files, the ``EXPORT_ANDROID_MK`` mode may be
  682. used to specify an export to the android ndk build system. This mode
  683. accepts the same options as the normal export mode. The Android
  684. NDK supports the use of prebuilt libraries, both static and shared. This
  685. allows cmake to build the libraries of a project and make them available
  686. to an ndk build system complete with transitive dependencies, include flags
  687. and defines required to use the libraries.
  688. ``CXX_MODULES_DIRECTORY``
  689. .. versionadded:: 3.28
  690. Specify a subdirectory to store C++ module information for targets in the
  691. export set. This directory will be populated with files which add the
  692. necessary target property information to the relevant targets. Note that
  693. without this information, none of the C++ modules which are part of the
  694. targets in the export set will support being imported in consuming targets.
  695. ``EXPORT_PACKAGE_DEPENDENCIES``
  696. .. note::
  697. Experimental. Gated by ``CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES``.
  698. Specify that :command:`find_dependency` calls should be exported. If this
  699. argument is specified, CMake examines all targets in the export set and
  700. gathers their ``INTERFACE`` link targets. If any such targets either were
  701. found with :command:`find_package` or have the
  702. :prop_tgt:`EXPORT_FIND_PACKAGE_NAME` property set, and such package
  703. dependency was not disabled by passing ``ENABLED OFF`` to
  704. :command:`export(SETUP)`, then a :command:`find_dependency` call is
  705. written with the target's corresponding package name, a ``REQUIRED``
  706. argument, and any additional arguments specified by the ``EXTRA_ARGS``
  707. argument of :command:`export(SETUP)`. Any package dependencies that were
  708. manually specified by passing ``ENABLED ON`` to :command:`export(SETUP)`
  709. are also added, even if the exported targets don't depend on any targets
  710. from them.
  711. The :command:`find_dependency` calls are written in the following order:
  712. 1. Any package dependencies that were listed in :command:`export(SETUP)`
  713. are written in the order they were first specified, regardless of
  714. whether or not they contain ``INTERFACE`` dependencies of the
  715. exported targets.
  716. 2. Any package dependencies that contain ``INTERFACE`` link dependencies
  717. of the exported targets and that were never specified in
  718. :command:`export(SETUP)` are written in the order they were first
  719. found.
  720. The ``EXPORT`` form is useful to help outside projects use targets built
  721. and installed by the current project. For example, the code
  722. .. code-block:: cmake
  723. install(TARGETS myexe EXPORT myproj DESTINATION bin)
  724. install(EXPORT myproj NAMESPACE mp_ DESTINATION lib/myproj)
  725. install(EXPORT_ANDROID_MK myproj DESTINATION share/ndk-modules)
  726. will install the executable ``myexe`` to ``<prefix>/bin`` and code to import
  727. it in the file ``<prefix>/lib/myproj/myproj.cmake`` and
  728. ``<prefix>/share/ndk-modules/Android.mk``. An outside project
  729. may load this file with the include command and reference the ``myexe``
  730. executable from the installation tree using the imported target name
  731. ``mp_myexe`` as if the target were built in its own tree.
  732. .. signature::
  733. install(RUNTIME_DEPENDENCY_SET <set-name> [...])
  734. .. versionadded:: 3.21
  735. Installs a runtime dependency set:
  736. .. code-block:: cmake
  737. install(RUNTIME_DEPENDENCY_SET <set-name>
  738. [[LIBRARY|RUNTIME|FRAMEWORK]
  739. [DESTINATION <dir>]
  740. [PERMISSIONS <permission>...]
  741. [CONFIGURATIONS <config>...]
  742. [COMPONENT <component>]
  743. [NAMELINK_COMPONENT <component>]
  744. [OPTIONAL] [EXCLUDE_FROM_ALL]
  745. ] [...]
  746. [PRE_INCLUDE_REGEXES <regex>...]
  747. [PRE_EXCLUDE_REGEXES <regex>...]
  748. [POST_INCLUDE_REGEXES <regex>...]
  749. [POST_EXCLUDE_REGEXES <regex>...]
  750. [POST_INCLUDE_FILES <file>...]
  751. [POST_EXCLUDE_FILES <file>...]
  752. [DIRECTORIES <dir>...]
  753. )
  754. Installs a runtime dependency set previously created by one or more
  755. :command:`install(TARGETS)` or :command:`install(IMPORTED_RUNTIME_ARTIFACTS)`
  756. commands. The dependencies of targets belonging to a runtime dependency set
  757. are installed in the ``RUNTIME`` destination and component on DLL platforms,
  758. and in the ``LIBRARY`` destination and component on non-DLL platforms.
  759. macOS frameworks are installed in the ``FRAMEWORK`` destination and component.
  760. Targets built within the build tree will never be installed as runtime
  761. dependencies, nor will their own dependencies, unless the targets themselves
  762. are installed with :command:`install(TARGETS)`.
  763. The generated install script calls :command:`file(GET_RUNTIME_DEPENDENCIES)`
  764. on the build-tree files to calculate the runtime dependencies. The build-tree
  765. executable files are passed as the ``EXECUTABLES`` argument, the build-tree
  766. shared libraries as the ``LIBRARIES`` argument, and the build-tree modules as
  767. the ``MODULES`` argument. On macOS, if one of the executables is a
  768. :prop_tgt:`MACOSX_BUNDLE`, that executable is passed as the
  769. ``BUNDLE_EXECUTABLE`` argument. At most one such bundle executable may be in
  770. the runtime dependency set on macOS. The :prop_tgt:`MACOSX_BUNDLE` property
  771. has no effect on other platforms. Note that
  772. :command:`file(GET_RUNTIME_DEPENDENCIES)` only supports collecting the runtime
  773. dependencies for Windows, Linux and macOS platforms, so
  774. ``install(RUNTIME_DEPENDENCY_SET)`` has the same limitation.
  775. The following sub-arguments are forwarded through as the corresponding
  776. arguments to :command:`file(GET_RUNTIME_DEPENDENCIES)` (for those that provide
  777. a non-empty list of directories, regular expressions or files). They all
  778. support :manual:`generator expressions <cmake-generator-expressions(7)>`.
  779. * ``DIRECTORIES <dir>...``
  780. * ``PRE_INCLUDE_REGEXES <regex>...``
  781. * ``PRE_EXCLUDE_REGEXES <regex>...``
  782. * ``POST_INCLUDE_REGEXES <regex>...``
  783. * ``POST_EXCLUDE_REGEXES <regex>...``
  784. * ``POST_INCLUDE_FILES <file>...``
  785. * ``POST_EXCLUDE_FILES <file>...``
  786. .. note::
  787. This command supersedes the :command:`install_targets` command and
  788. the :prop_tgt:`PRE_INSTALL_SCRIPT` and :prop_tgt:`POST_INSTALL_SCRIPT`
  789. target properties. It also replaces the ``FILES`` forms of the
  790. :command:`install_files` and :command:`install_programs` commands.
  791. The processing order of these install rules relative to
  792. those generated by :command:`install_targets`,
  793. :command:`install_files`, and :command:`install_programs` commands
  794. is not defined.
  795. Examples
  796. ^^^^^^^^
  797. Example: Install Targets with Per-Artifact Components
  798. """""""""""""""""""""""""""""""""""""""""""""""""""""
  799. Consider a project that defines targets with different artifact kinds:
  800. .. code-block:: cmake
  801. add_executable(myExe myExe.c)
  802. add_library(myStaticLib STATIC myStaticLib.c)
  803. target_sources(myStaticLib PUBLIC FILE_SET HEADERS FILES myStaticLib.h)
  804. add_library(mySharedLib SHARED mySharedLib.c)
  805. target_sources(mySharedLib PUBLIC FILE_SET HEADERS FILES mySharedLib.h)
  806. set_property(TARGET mySharedLib PROPERTY SOVERSION 1)
  807. We may call :command:`install(TARGETS)` with `\<artifact-kind\>`_ arguments
  808. to specify different options for each kind of artifact:
  809. .. code-block:: cmake
  810. install(TARGETS
  811. myExe
  812. mySharedLib
  813. myStaticLib
  814. RUNTIME # Following options apply to runtime artifacts.
  815. COMPONENT Runtime
  816. LIBRARY # Following options apply to library artifacts.
  817. COMPONENT Runtime
  818. NAMELINK_COMPONENT Development
  819. ARCHIVE # Following options apply to archive artifacts.
  820. COMPONENT Development
  821. DESTINATION lib/static
  822. FILE_SET HEADERS # Following options apply to file set HEADERS.
  823. COMPONENT Development
  824. )
  825. This will:
  826. * Install ``myExe`` to ``<prefix>/bin``, the default RUNTIME artifact
  827. destination, as part of the ``Runtime`` component.
  828. * On non-DLL platforms:
  829. * Install ``libmySharedLib.so.1`` to ``<prefix>/lib``, the default
  830. LIBRARY artifact destination, as part of the ``Runtime`` component.
  831. * Install the ``libmySharedLib.so`` "namelink" (symbolic link) to
  832. ``<prefix>/lib``, the default LIBRARY artifact destination, as part
  833. of the ``Development`` component.
  834. * On DLL platforms:
  835. * Install ``mySharedLib.dll`` to ``<prefix>/bin``, the default RUNTIME
  836. artifact destination, as part of the ``Runtime`` component.
  837. * Install ``mySharedLib.lib`` to ``<prefix>/lib/static``, the specified
  838. ARCHIVE artifact destination, as part of the ``Development`` component.
  839. * Install ``myStaticLib`` to ``<prefix>/lib/static``, the specified
  840. ARCHIVE artifact destination, as part of the ``Development`` component.
  841. * Install ``mySharedLib.h`` and ``myStaticLib.h`` to ``<prefix>/include``,
  842. the default destination for a file set of type HEADERS, as part of the
  843. ``Development`` component.
  844. Example: Install Targets to Per-Config Destinations
  845. """""""""""""""""""""""""""""""""""""""""""""""""""
  846. Each :command:`install(TARGETS)` call installs a given target
  847. :ref:`output artifact <Output Artifacts>` to at most one ``DESTINATION``,
  848. but the install rule itself may be filtered by the ``CONFIGURATIONS`` option.
  849. In order to install to a different destination for each configuration, one
  850. call per configuration is needed. For example, the code:
  851. .. code-block:: cmake
  852. install(TARGETS myExe
  853. CONFIGURATIONS Debug
  854. RUNTIME
  855. DESTINATION Debug/bin
  856. )
  857. install(TARGETS myExe
  858. CONFIGURATIONS Release
  859. RUNTIME
  860. DESTINATION Release/bin
  861. )
  862. will install ``myExe`` to ``<prefix>/Debug/bin`` in the Debug configuration,
  863. and to ``<prefix>/Release/bin`` in the Release configuration.
  864. Generated Installation Script
  865. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  866. .. note::
  867. Use of this feature is not recommended. Please consider using the
  868. :option:`cmake --install` instead.
  869. The ``install()`` command generates a file, ``cmake_install.cmake``, inside
  870. the build directory, which is used internally by the generated install target
  871. and by CPack. You can also invoke this script manually with
  872. :option:`cmake -P`. This script accepts several variables:
  873. ``COMPONENT``
  874. Set this variable to install only a single CPack component as opposed to all
  875. of them. For example, if you only want to install the ``Development``
  876. component, run ``cmake -DCOMPONENT=Development -P cmake_install.cmake``.
  877. ``BUILD_TYPE``
  878. Set this variable to change the build type if you are using a multi-config
  879. generator. For example, to install with the ``Debug`` configuration, run
  880. ``cmake -DBUILD_TYPE=Debug -P cmake_install.cmake``.
  881. ``DESTDIR``
  882. This is an environment variable rather than a CMake variable. It allows you
  883. to change the installation prefix on UNIX systems. See :envvar:`DESTDIR` for
  884. details.