install.rst 49 KB

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