install.rst 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  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. [FILES_MATCHING]
  518. [<match-rule> <match-option>...]...
  519. )
  520. The ``DIRECTORY`` form installs contents of one or more directories to a
  521. given destination. The directory structure is copied verbatim to the
  522. destination.
  523. Either a ``TYPE`` or a ``DESTINATION`` must be provided, but not both.
  524. If no permissions is given, files will be given the default permissions
  525. specified in the `FILES`_ form of the command, and the directories
  526. will be given the default permissions specified in the `PROGRAMS`_
  527. form of the command.
  528. The options are:
  529. ``<dir>...``
  530. The list of directories to be installed.
  531. The last component of each directory name is appended to the
  532. destination directory but a trailing slash may be used to avoid
  533. this because it leaves the last component empty. Directory names
  534. given as relative paths are interpreted with respect to the current
  535. source directory. If no input directory names are given the
  536. destination directory will be created but nothing will be installed
  537. into it.
  538. .. versionadded:: 3.5
  539. The source ``<dir>...`` list may use "generator expressions" with the
  540. syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  541. manual for available expressions.
  542. ``TYPE <type>``
  543. Specifies the generic file type of the files within the listed
  544. directories being installed. A destination will then be set
  545. automatically by taking the corresponding variable from
  546. :module:`GNUInstallDirs`, or by using a built-in default if that
  547. variable is not defined. See the table below for the supported
  548. file types and their corresponding variables and built-in defaults.
  549. Projects can provide a ``DESTINATION`` argument instead of a file
  550. type if they wish to explicitly define the install destination.
  551. ======================= ================================== =========================
  552. ``TYPE`` Argument GNUInstallDirs Variable Built-In Default
  553. ======================= ================================== =========================
  554. ``BIN`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
  555. ``SBIN`` ``${CMAKE_INSTALL_SBINDIR}`` ``sbin``
  556. ``LIB`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
  557. ``INCLUDE`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
  558. ``SYSCONF`` ``${CMAKE_INSTALL_SYSCONFDIR}`` ``etc``
  559. ``SHAREDSTATE`` ``${CMAKE_INSTALL_SHARESTATEDIR}`` ``com``
  560. ``LOCALSTATE`` ``${CMAKE_INSTALL_LOCALSTATEDIR}`` ``var``
  561. ``RUNSTATE`` ``${CMAKE_INSTALL_RUNSTATEDIR}`` ``<LOCALSTATE dir>/run``
  562. ``DATA`` ``${CMAKE_INSTALL_DATADIR}`` ``<DATAROOT dir>``
  563. ``INFO`` ``${CMAKE_INSTALL_INFODIR}`` ``<DATAROOT dir>/info``
  564. ``LOCALE`` ``${CMAKE_INSTALL_LOCALEDIR}`` ``<DATAROOT dir>/locale``
  565. ``MAN`` ``${CMAKE_INSTALL_MANDIR}`` ``<DATAROOT dir>/man``
  566. ``DOC`` ``${CMAKE_INSTALL_DOCDIR}`` ``<DATAROOT dir>/doc``
  567. ``LIBEXEC`` ``${CMAKE_INSTALL_LIBEXECDIR}`` ``libexec``
  568. ======================= ================================== =========================
  569. Note that some of the types' built-in defaults use the ``DATAROOT``
  570. directory as a prefix. The ``DATAROOT`` prefix is calculated similarly
  571. to the types, with ``CMAKE_INSTALL_DATAROOTDIR`` as the variable and
  572. ``share`` as the built-in default. You cannot use ``DATAROOT`` as a
  573. ``TYPE`` parameter; please use ``DATA`` instead.
  574. .. versionadded:: 3.31
  575. The ``LIBEXEC`` type.
  576. ``DESTINATION <dir>``
  577. The destination directory, as documented among the `common options`_.
  578. To make packages compliant with distribution filesystem layout
  579. policies, if projects must specify a ``DESTINATION``, it is
  580. strongly recommended that they use a path that begins with the
  581. appropriate relative :module:`GNUInstallDirs` variable.
  582. This allows package maintainers to control the install destination
  583. by setting the appropriate cache variables.
  584. .. versionadded:: 3.4
  585. The destination ``<dir>`` may use "generator expressions" with the
  586. syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  587. manual for available expressions.
  588. ``FILE_PERMISSIONS <permission>...``
  589. Specify permissions given to files in the destination, where the
  590. ``<permission>`` names are documented among the `common options`_.
  591. ``DIRECTORY_PERMISSIONS <permission>...``
  592. Specify permissions given to directories in the destination, where the
  593. ``<permission>`` names are documented among the `common options`_.
  594. ``USE_SOURCE_PERMISSIONS``
  595. If specified, and ``FILE_PERMISSIONS`` is not, file permissions will
  596. be copied from the source directory structure.
  597. ``MESSAGE_NEVER``
  598. .. versionadded:: 3.1
  599. Disable file installation status output.
  600. ``FILES_MATCHING``
  601. This option may be given before the first ``<match-rule>`` to
  602. disable installation of files (but not directories) not matched
  603. by any expression. For example, the code
  604. .. code-block:: cmake
  605. install(DIRECTORY src/ DESTINATION doc/myproj
  606. FILES_MATCHING PATTERN "*.png")
  607. will extract and install images from a source tree.
  608. ``<match-rule> <match-option>...``
  609. Installation of directories may be controlled with fine granularity
  610. using rules that match directories or files encountered within input
  611. directories. They may be used to apply certain options (see below)
  612. to a subset of the files and directories encountered. All files
  613. and directories are installed whether or not they are matched,
  614. unless the above ``FILES_MATCHING`` option is given.
  615. The full path to each input file or directory, with forward slashes,
  616. may be matched by a ``<match-rule>``:
  617. ``PATTERN <pattern>``
  618. Match complete file names using a globbing pattern. The portion of
  619. the full path matching the pattern must occur at the end of the file
  620. name and be preceded by a slash (which is not part of the pattern).
  621. ``REGEX <regex>``
  622. Match any portion of the full path of a file with a
  623. :ref:`regular expression <Regex Specification>`.
  624. One may use ``/`` and ``$`` to limit matching to the end of a path.
  625. Each ``<match-rule>`` may be followed by ``<match-option>`` arguments.
  626. The match options apply to the files or directories matched by the rule.
  627. The match options are:
  628. ``EXCLUDE``
  629. Exclude the matched file or directory from installation.
  630. ``PERMISSIONS <permission>...``
  631. Ovrerride the permissions setting for the matched file or directory.
  632. For example, the code
  633. .. code-block:: cmake
  634. install(DIRECTORY icons scripts/ DESTINATION share/myproj
  635. PATTERN "CVS" EXCLUDE
  636. PATTERN "scripts/*"
  637. PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
  638. GROUP_EXECUTE GROUP_READ)
  639. will install the ``icons`` directory to ``share/myproj/icons`` and the
  640. ``scripts`` directory to ``share/myproj``. The icons will get default
  641. file permissions, the scripts will be given specific permissions, and any
  642. ``CVS`` directories will be excluded.
  643. .. signature::
  644. install(SCRIPT <file> [...])
  645. install(CODE <code> [...])
  646. Invoke CMake scripts or code during installation:
  647. .. code-block:: cmake
  648. install([[SCRIPT <file>] [CODE <code>]]
  649. [ALL_COMPONENTS | COMPONENT <component>]
  650. [EXCLUDE_FROM_ALL] [...])
  651. The ``SCRIPT`` form will invoke the given CMake script files during
  652. installation. If the script file name is a relative path it will be
  653. interpreted with respect to the current source directory. The ``CODE``
  654. form will invoke the given CMake code during installation. Code is
  655. specified as a single argument inside a double-quoted string. For
  656. example, the code
  657. .. code-block:: cmake
  658. install(CODE "message(\"Sample install message.\")")
  659. will print a message during installation.
  660. .. versionadded:: 3.21
  661. When the ``ALL_COMPONENTS`` option is given, the custom installation
  662. script code will be executed for every component of a component-specific
  663. installation. This option is mutually exclusive with the ``COMPONENT``
  664. option.
  665. .. versionadded:: 3.14
  666. ``<file>`` or ``<code>`` may use "generator expressions" with the syntax
  667. ``$<...>`` (in the case of ``<file>``, this refers to their use in the file
  668. name, not the file's contents). See the
  669. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  670. .. signature::
  671. install(EXPORT <export-name> [...])
  672. Install a CMake file exporting targets for dependent projects:
  673. .. code-block:: cmake
  674. install(EXPORT <export-name> DESTINATION <dir>
  675. [NAMESPACE <namespace>] [FILE <name>.cmake]
  676. [PERMISSIONS <permission>...]
  677. [CONFIGURATIONS <config>...]
  678. [CXX_MODULES_DIRECTORY <directory>]
  679. [EXPORT_LINK_INTERFACE_LIBRARIES]
  680. [COMPONENT <component>]
  681. [EXCLUDE_FROM_ALL]
  682. [EXPORT_PACKAGE_DEPENDENCIES])
  683. install(EXPORT_ANDROID_MK <export-name> DESTINATION <dir> [...])
  684. The ``EXPORT`` form generates and installs a CMake file containing code to
  685. import targets from the installation tree into another project.
  686. Target installations are associated with the export ``<export-name>``
  687. using the ``EXPORT`` option of the :command:`install(TARGETS)` signature
  688. documented above. The ``NAMESPACE`` option will prepend ``<namespace>`` to
  689. the target names as they are written to the import file. By default
  690. the generated file will be called ``<export-name>.cmake`` but the ``FILE``
  691. option may be used to specify a different name. The value given to
  692. the ``FILE`` option must be a file name with the ``.cmake`` extension.
  693. If a ``CONFIGURATIONS`` option is given then the file will only be installed
  694. when one of the named configurations is installed. Additionally, the
  695. generated import file will reference only the matching target
  696. configurations. See the :variable:`CMAKE_MAP_IMPORTED_CONFIG_<CONFIG>`
  697. variable to map configurations of dependent projects to the installed
  698. configurations. The ``EXPORT_LINK_INTERFACE_LIBRARIES`` keyword, if
  699. present, causes the contents of the properties matching
  700. ``(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?`` to be exported, when
  701. policy :policy:`CMP0022` is ``NEW``.
  702. .. note::
  703. The installed ``<export-name>.cmake`` file may come with additional
  704. per-configuration ``<export-name>-*.cmake`` files to be loaded by
  705. globbing. Do not use an export name that is the same as the package
  706. name in combination with installing a ``<package-name>-config.cmake``
  707. file or the latter may be incorrectly matched by the glob and loaded.
  708. When a ``COMPONENT`` option is given, the listed ``<component>`` implicitly
  709. depends on all components mentioned in the export set. The exported
  710. ``<name>.cmake`` file will require each of the exported components to be
  711. present in order for dependent projects to build properly. For example, a
  712. project may define components ``Runtime`` and ``Development``, with shared
  713. libraries going into the ``Runtime`` component and static libraries and
  714. headers going into the ``Development`` component. The export set would also
  715. typically be part of the ``Development`` component, but it would export
  716. targets from both the ``Runtime`` and ``Development`` components. Therefore,
  717. the ``Runtime`` component would need to be installed if the ``Development``
  718. component was installed, but not vice versa. If the ``Development`` component
  719. was installed without the ``Runtime`` component, dependent projects that try
  720. to link against it would have build errors. Package managers, such as APT and
  721. RPM, typically handle this by listing the ``Runtime`` component as a dependency
  722. of the ``Development`` component in the package metadata, ensuring that the
  723. library is always installed if the headers and CMake export file are present.
  724. .. versionadded:: 3.7
  725. In addition to cmake language files, the ``EXPORT_ANDROID_MK`` mode may be
  726. used to specify an export to the android ndk build system. This mode
  727. accepts the same options as the normal export mode. The Android
  728. NDK supports the use of prebuilt libraries, both static and shared. This
  729. allows cmake to build the libraries of a project and make them available
  730. to an ndk build system complete with transitive dependencies, include flags
  731. and defines required to use the libraries.
  732. ``CXX_MODULES_DIRECTORY``
  733. .. versionadded:: 3.28
  734. Specify a subdirectory to store C++ module information for targets in the
  735. export set. This directory will be populated with files which add the
  736. necessary target property information to the relevant targets. Note that
  737. without this information, none of the C++ modules which are part of the
  738. targets in the export set will support being imported in consuming targets.
  739. ``EXPORT_PACKAGE_DEPENDENCIES``
  740. .. note::
  741. Experimental. Gated by ``CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES``.
  742. Specify that :command:`find_dependency` calls should be exported. If this
  743. argument is specified, CMake examines all targets in the export set and
  744. gathers their ``INTERFACE`` link targets. If any such targets either were
  745. found with :command:`find_package` or have the
  746. :prop_tgt:`EXPORT_FIND_PACKAGE_NAME` property set, and such package
  747. dependency was not disabled by passing ``ENABLED OFF`` to
  748. :command:`export(SETUP)`, then a :command:`find_dependency` call is
  749. written with the target's corresponding package name, a ``REQUIRED``
  750. argument, and any additional arguments specified by the ``EXTRA_ARGS``
  751. argument of :command:`export(SETUP)`. Any package dependencies that were
  752. manually specified by passing ``ENABLED ON`` to :command:`export(SETUP)`
  753. are also added, even if the exported targets don't depend on any targets
  754. from them.
  755. The :command:`find_dependency` calls are written in the following order:
  756. 1. Any package dependencies that were listed in :command:`export(SETUP)`
  757. are written in the order they were first specified, regardless of
  758. whether or not they contain ``INTERFACE`` dependencies of the
  759. exported targets.
  760. 2. Any package dependencies that contain ``INTERFACE`` link dependencies
  761. of the exported targets and that were never specified in
  762. :command:`export(SETUP)` are written in the order they were first
  763. found.
  764. The ``EXPORT`` form is useful to help outside projects use targets built
  765. and installed by the current project. For example, the code
  766. .. code-block:: cmake
  767. install(TARGETS myexe EXPORT myproj DESTINATION bin)
  768. install(EXPORT myproj NAMESPACE mp_ DESTINATION lib/myproj)
  769. install(EXPORT_ANDROID_MK myproj DESTINATION share/ndk-modules)
  770. will install the executable ``myexe`` to ``<prefix>/bin`` and code to import
  771. it in the file ``<prefix>/lib/myproj/myproj.cmake`` and
  772. ``<prefix>/share/ndk-modules/Android.mk``. An outside project
  773. may load this file with the include command and reference the ``myexe``
  774. executable from the installation tree using the imported target name
  775. ``mp_myexe`` as if the target were built in its own tree.
  776. .. signature::
  777. install(PACKAGE_INFO <package-name> [...])
  778. .. versionadded:: 3.31
  779. .. note::
  780. Experimental. Gated by ``CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO``.
  781. Installs a |CPS|_ file exporting targets for dependent projects:
  782. .. code-block:: cmake
  783. install(PACKAGE_INFO <package-name> EXPORT <export-name>
  784. [PROJECT <project-name>|NO_PROJECT_METADATA]
  785. [APPENDIX <appendix-name>]
  786. [DESTINATION <dir>]
  787. [LOWER_CASE_FILE]
  788. [VERSION <version>
  789. [COMPAT_VERSION <version>]
  790. [VERSION_SCHEMA <string>]]
  791. [DEFAULT_TARGETS <target>...]
  792. [DEFAULT_CONFIGURATIONS <config>...]
  793. [DESCRIPTION <project-description-string>]
  794. [HOMEPAGE_URL <url-string>]
  795. [PERMISSIONS <permission>...]
  796. [CONFIGURATIONS <config>...]
  797. [COMPONENT <component>]
  798. [EXCLUDE_FROM_ALL])
  799. The ``PACKAGE_INFO`` form generates and installs a |CPS| file which describes
  800. installed targets such that they can be consumed by another project.
  801. Target installations are associated with the export ``<export-name>``
  802. using the ``EXPORT`` option of the :command:`install(TARGETS)` signature
  803. documented above. Unlike :command:`install(EXPORT)`, this information is not
  804. expressed in CMake code, and can be consumed by tools other than CMake. When
  805. imported into another CMake project, the imported targets will be prefixed
  806. with ``<package-name>::``. By default, the generated file will be called
  807. ``<package-name>[-<appendix-name>].cps``. If ``LOWER_CASE_FILE`` is given,
  808. the package name as it appears on disk (in both the file name and install
  809. destination) will be first converted to lower case.
  810. If ``DESTINATION`` is not specified, a platform-specific default is used.
  811. Several options may be used to specify package metadata:
  812. ``VERSION <version>``
  813. Version of the package. The ``<version>`` shall conform to the specified
  814. schema. Refer to :ref:`Version Selection (CPS) <cps version selection>`
  815. for more information on how the package version is used when consumers
  816. request a package.
  817. ``COMPAT_VERSION <version>``
  818. Oldest version for which the package provides compatibility.
  819. If not specified, ``COMPAT_VERSION`` is implicitly taken to equal the
  820. package's ``VERSION``, which is to say that no backwards compatibility is
  821. provided.
  822. ``VERSION_SCHEMA <schema>``
  823. The schema that the package's version number(s) (both ``VERSION`` and
  824. ``COMPAT_VERSION``) follow. While no schema will be written to the
  825. ``.cps`` file if this option is not provided, CPS specifies that the schema
  826. is assumed to be ``simple`` in such cases. Refer to |cps-version_schema|_
  827. for more details and a list of officially supported schemas, but be aware
  828. that the specification may include schemas that are not supported by CMake.
  829. See :ref:`Version Selection (CPS) <cps version selection>` for the list of
  830. schemas supported by :command:`find_package`.
  831. ``DEFAULT_TARGETS <target>...``
  832. Targets to be used if a consumer requests linking to the package name,
  833. rather than to specific components.
  834. ``DEFAULT_CONFIGURATIONS <config>...``
  835. Ordered list of configurations consumers should prefer if no exact match or
  836. mapping of the consumer's configuration to the package's available
  837. configurations exists. If not specified, CMake will fall back to the
  838. package's available configurations in an unspecified order.
  839. ``DESCRIPTION <project-description-string>``
  840. .. versionadded:: 4.1
  841. An informational description of the project. It is recommended that this
  842. description is a relatively short string, usually no more than a few words.
  843. ``HOMEPAGE_URL <url-string>``
  844. .. versionadded:: 4.1
  845. An informational canonical home URL for the project.
  846. By default, if the specified ``<package-name>`` matches the current CMake
  847. :variable:`PROJECT_NAME`, package metadata will be inherited from the
  848. project. The ``PROJECT <project-name>`` option may be used to specify a
  849. different project from which to inherit metadata. If ``NO_PROJECT_METADATA``
  850. is specified, automatic inheritance of package metadata will be disabled.
  851. In any case, any metadata values specified in the ``install`` command will
  852. take precedence.
  853. If ``APPENDIX`` is specified, rather than generating a top level package
  854. specification, the specified targets will be exported as an appendix to the
  855. named package. Appendices may be used to separate less commonly used targets
  856. (along with their external dependencies) from the rest of a package. This
  857. enables consumers to ignore transitive dependencies for targets that they
  858. don't use, and also allows a single logical "package" to be composed of
  859. artifacts produced by multiple build trees.
  860. Appendices are not permitted to change basic package metadata; therefore,
  861. none of ``PROJECT``, ``VERSION``, ``COMPAT_VERSION``, ``VERSION_SCHEMA``,
  862. ``DEFAULT_TARGETS`` or ``DEFAULT_CONFIGURATIONS`` may be specified in
  863. combination with ``APPENDIX``. Additionally, it is strongly recommended that
  864. use of ``LOWER_CASE_FILE`` should be consistent between the main package and
  865. any appendices.
  866. .. signature::
  867. install(RUNTIME_DEPENDENCY_SET <set-name> [...])
  868. .. versionadded:: 3.21
  869. Installs a runtime dependency set:
  870. .. code-block:: cmake
  871. install(RUNTIME_DEPENDENCY_SET <set-name>
  872. [[LIBRARY|RUNTIME|FRAMEWORK]
  873. [DESTINATION <dir>]
  874. [PERMISSIONS <permission>...]
  875. [CONFIGURATIONS <config>...]
  876. [COMPONENT <component>]
  877. [NAMELINK_COMPONENT <component>]
  878. [OPTIONAL] [EXCLUDE_FROM_ALL]
  879. ] [...]
  880. [PRE_INCLUDE_REGEXES <regex>...]
  881. [PRE_EXCLUDE_REGEXES <regex>...]
  882. [POST_INCLUDE_REGEXES <regex>...]
  883. [POST_EXCLUDE_REGEXES <regex>...]
  884. [POST_INCLUDE_FILES <file>...]
  885. [POST_EXCLUDE_FILES <file>...]
  886. [DIRECTORIES <dir>...]
  887. )
  888. Installs a runtime dependency set previously created by one or more
  889. :command:`install(TARGETS)` or :command:`install(IMPORTED_RUNTIME_ARTIFACTS)`
  890. commands. The dependencies of targets belonging to a runtime dependency set
  891. are installed in the ``RUNTIME`` destination and component on DLL platforms,
  892. and in the ``LIBRARY`` destination and component on non-DLL platforms.
  893. macOS frameworks are installed in the ``FRAMEWORK`` destination and component.
  894. Targets built within the build tree will never be installed as runtime
  895. dependencies, nor will their own dependencies, unless the targets themselves
  896. are installed with :command:`install(TARGETS)`.
  897. The generated install script calls :command:`file(GET_RUNTIME_DEPENDENCIES)`
  898. on the build-tree files to calculate the runtime dependencies. The build-tree
  899. executable files are passed as the ``EXECUTABLES`` argument, the build-tree
  900. shared libraries as the ``LIBRARIES`` argument, and the build-tree modules as
  901. the ``MODULES`` argument. On macOS, if one of the executables is a
  902. :prop_tgt:`MACOSX_BUNDLE`, that executable is passed as the
  903. ``BUNDLE_EXECUTABLE`` argument. At most one such bundle executable may be in
  904. the runtime dependency set on macOS. The :prop_tgt:`MACOSX_BUNDLE` property
  905. has no effect on other platforms. Note that
  906. :command:`file(GET_RUNTIME_DEPENDENCIES)` only supports collecting the runtime
  907. dependencies for Windows, Linux and macOS platforms, so
  908. ``install(RUNTIME_DEPENDENCY_SET)`` has the same limitation.
  909. The following sub-arguments are forwarded through as the corresponding
  910. arguments to :command:`file(GET_RUNTIME_DEPENDENCIES)` (for those that provide
  911. a non-empty list of directories, regular expressions or files). They all
  912. support :manual:`generator expressions <cmake-generator-expressions(7)>`.
  913. * ``DIRECTORIES <dir>...``
  914. * ``PRE_INCLUDE_REGEXES <regex>...``
  915. * ``PRE_EXCLUDE_REGEXES <regex>...``
  916. * ``POST_INCLUDE_REGEXES <regex>...``
  917. * ``POST_EXCLUDE_REGEXES <regex>...``
  918. * ``POST_INCLUDE_FILES <file>...``
  919. * ``POST_EXCLUDE_FILES <file>...``
  920. .. note::
  921. This command supersedes the :command:`install_targets` command and
  922. the :prop_tgt:`PRE_INSTALL_SCRIPT` and :prop_tgt:`POST_INSTALL_SCRIPT`
  923. target properties. It also replaces the ``FILES`` forms of the
  924. :command:`install_files` and :command:`install_programs` commands.
  925. The processing order of these install rules relative to
  926. those generated by :command:`install_targets`,
  927. :command:`install_files`, and :command:`install_programs` commands
  928. is not defined.
  929. Examples
  930. ^^^^^^^^
  931. Example: Install Targets with Per-Artifact Components
  932. """""""""""""""""""""""""""""""""""""""""""""""""""""
  933. Consider a project that defines targets with different artifact kinds:
  934. .. code-block:: cmake
  935. add_executable(myExe myExe.c)
  936. add_library(myStaticLib STATIC myStaticLib.c)
  937. target_sources(myStaticLib PUBLIC FILE_SET HEADERS FILES myStaticLib.h)
  938. add_library(mySharedLib SHARED mySharedLib.c)
  939. target_sources(mySharedLib PUBLIC FILE_SET HEADERS FILES mySharedLib.h)
  940. set_property(TARGET mySharedLib PROPERTY SOVERSION 1)
  941. We may call :command:`install(TARGETS)` with `\<artifact-kind\>`_ arguments
  942. to specify different options for each kind of artifact:
  943. .. code-block:: cmake
  944. install(TARGETS
  945. myExe
  946. mySharedLib
  947. myStaticLib
  948. RUNTIME # Following options apply to runtime artifacts.
  949. COMPONENT Runtime
  950. LIBRARY # Following options apply to library artifacts.
  951. COMPONENT Runtime
  952. NAMELINK_COMPONENT Development
  953. ARCHIVE # Following options apply to archive artifacts.
  954. COMPONENT Development
  955. DESTINATION lib/static
  956. FILE_SET HEADERS # Following options apply to file set HEADERS.
  957. COMPONENT Development
  958. )
  959. This will:
  960. * Install ``myExe`` to ``<prefix>/bin``, the default RUNTIME artifact
  961. destination, as part of the ``Runtime`` component.
  962. * On non-DLL platforms:
  963. * Install ``libmySharedLib.so.1`` to ``<prefix>/lib``, the default
  964. LIBRARY artifact destination, as part of the ``Runtime`` component.
  965. * Install the ``libmySharedLib.so`` "namelink" (symbolic link) to
  966. ``<prefix>/lib``, the default LIBRARY artifact destination, as part
  967. of the ``Development`` component.
  968. * On DLL platforms:
  969. * Install ``mySharedLib.dll`` to ``<prefix>/bin``, the default RUNTIME
  970. artifact destination, as part of the ``Runtime`` component.
  971. * Install ``mySharedLib.lib`` to ``<prefix>/lib/static``, the specified
  972. ARCHIVE artifact destination, as part of the ``Development`` component.
  973. * Install ``myStaticLib`` to ``<prefix>/lib/static``, the specified
  974. ARCHIVE artifact destination, as part of the ``Development`` component.
  975. * Install ``mySharedLib.h`` and ``myStaticLib.h`` to ``<prefix>/include``,
  976. the default destination for a file set of type HEADERS, as part of the
  977. ``Development`` component.
  978. Example: Install Targets to Per-Config Destinations
  979. """""""""""""""""""""""""""""""""""""""""""""""""""
  980. Each :command:`install(TARGETS)` call installs a given target
  981. :ref:`output artifact <Output Artifacts>` to at most one ``DESTINATION``,
  982. but the install rule itself may be filtered by the ``CONFIGURATIONS`` option.
  983. In order to install to a different destination for each configuration, one
  984. call per configuration is needed. For example, the code:
  985. .. code-block:: cmake
  986. install(TARGETS myExe
  987. CONFIGURATIONS Debug
  988. RUNTIME
  989. DESTINATION Debug/bin
  990. )
  991. install(TARGETS myExe
  992. CONFIGURATIONS Release
  993. RUNTIME
  994. DESTINATION Release/bin
  995. )
  996. will install ``myExe`` to ``<prefix>/Debug/bin`` in the Debug configuration,
  997. and to ``<prefix>/Release/bin`` in the Release configuration.
  998. Generated Installation Script
  999. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1000. .. note::
  1001. Use of this feature is not recommended. Please consider using the
  1002. :option:`cmake --install` instead.
  1003. The ``install()`` command generates a file, ``cmake_install.cmake``, inside
  1004. the build directory, which is used internally by the generated install target
  1005. and by CPack. You can also invoke this script manually with
  1006. :option:`cmake -P`. This script accepts several variables:
  1007. ``COMPONENT``
  1008. Set this variable to install only a single CPack component as opposed to all
  1009. of them. For example, if you only want to install the ``Development``
  1010. component, run ``cmake -DCOMPONENT=Development -P cmake_install.cmake``.
  1011. ``BUILD_TYPE``
  1012. Set this variable to change the build type if you are using a multi-config
  1013. generator. For example, to install with the ``Debug`` configuration, run
  1014. ``cmake -DBUILD_TYPE=Debug -P cmake_install.cmake``.
  1015. ``DESTDIR``
  1016. This is an environment variable rather than a CMake variable. It allows you
  1017. to change the installation prefix on UNIX systems. See :envvar:`DESTDIR` for
  1018. details.
  1019. .. _CPS: https://cps-org.github.io/cps/
  1020. .. |CPS| replace:: Common Package Specification
  1021. .. _cps-version_schema: https://cps-org.github.io/cps/schema.html#version-schema
  1022. .. |cps-version_schema| replace:: ``version_schema``