install.rst 53 KB

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