install.rst 53 KB

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