install.rst 49 KB

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