install.rst 61 KB

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