install.rst 53 KB

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