install.rst 52 KB

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