install.rst 47 KB

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