install.rst 52 KB

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