install.rst 47 KB

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