install.rst 56 KB

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