export.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. export
  2. ------
  3. Export targets or packages for outside projects to use them directly
  4. from the current project's build tree, without installation.
  5. See the :command:`install(EXPORT)` command to export targets from an
  6. install tree.
  7. Synopsis
  8. ^^^^^^^^
  9. .. parsed-literal::
  10. export(`TARGETS`_ <target>... [...])
  11. export(`EXPORT`_ <export-name> [...])
  12. export(`PACKAGE`_ <PackageName>)
  13. Exporting Targets
  14. ^^^^^^^^^^^^^^^^^
  15. .. _`export(TARGETS)`:
  16. .. _TARGETS:
  17. .. code-block:: cmake
  18. export(TARGETS <target>... [NAMESPACE <namespace>]
  19. [APPEND] FILE <filename> [EXPORT_LINK_INTERFACE_LIBRARIES]
  20. [CXX_MODULES_DIRECTORY <directory>])
  21. Creates a file ``<filename>`` that may be included by outside projects to
  22. import targets named by ``<target>...`` from the current project's build tree.
  23. This is useful during cross-compiling to build utility executables that can
  24. run on the host platform in one project and then import them into another
  25. project being compiled for the target platform.
  26. The file created by this command is specific to the build tree and
  27. should never be installed. See the :command:`install(EXPORT)` command to
  28. export targets from an install tree.
  29. The options are:
  30. ``NAMESPACE <namespace>``
  31. Prepend the ``<namespace>`` string to all target names written to the file.
  32. ``APPEND``
  33. Append to the file instead of overwriting it. This can be used to
  34. incrementally export multiple targets to the same file.
  35. ``EXPORT_LINK_INTERFACE_LIBRARIES``
  36. Include the contents of the properties named with the pattern
  37. ``(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?``
  38. in the export, even when policy :policy:`CMP0022` is NEW. This is useful
  39. to support consumers using CMake versions older than 2.8.12.
  40. ``CXX_MODULES_DIRECTORY <directory>``
  41. .. versionadded:: 3.28
  42. Export C++ module properties to files under the given directory. Each file
  43. will be named according to the target's export name (without any namespace).
  44. These files will automatically be included from the export file.
  45. This signature requires all targets to be listed explicitly. If a library
  46. target is included in the export, but a target to which it links is not
  47. included, the behavior is unspecified. See the `export(EXPORT)`_ signature
  48. to automatically export the same targets from the build tree as
  49. :command:`install(EXPORT)` would from an install tree.
  50. .. note::
  51. :ref:`Object Libraries` under :generator:`Xcode` have special handling if
  52. multiple architectures are listed in :variable:`CMAKE_OSX_ARCHITECTURES`.
  53. In this case they will be exported as :ref:`Interface Libraries` with
  54. no object files available to clients. This is sufficient to satisfy
  55. transitive usage requirements of other targets that link to the
  56. object libraries in their implementation.
  57. This command exports all :ref:`build configurations` from the build tree.
  58. See the :variable:`CMAKE_MAP_IMPORTED_CONFIG_<CONFIG>` variable to map
  59. configurations of dependent projects to the exported configurations.
  60. Exporting Targets to Android.mk
  61. """""""""""""""""""""""""""""""
  62. .. code-block:: cmake
  63. export(TARGETS <target>... ANDROID_MK <filename>)
  64. .. versionadded:: 3.7
  65. This signature exports cmake built targets to the android ndk build system
  66. by creating an ``Android.mk`` file that references the prebuilt targets. The
  67. Android NDK supports the use of prebuilt libraries, both static and shared.
  68. This allows cmake to build the libraries of a project and make them available
  69. to an ndk build system complete with transitive dependencies, include flags
  70. and defines required to use the libraries. The signature takes a list of
  71. targets and puts them in the ``Android.mk`` file specified by the
  72. ``<filename>`` given. This signature can only be used if policy
  73. :policy:`CMP0022` is NEW for all targets given. A error will be issued if
  74. that policy is set to OLD for one of the targets.
  75. Exporting Targets matching install(EXPORT)
  76. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  77. .. _`export(EXPORT)`:
  78. .. _EXPORT:
  79. .. code-block:: cmake
  80. export(EXPORT <export-name> [NAMESPACE <namespace>] [FILE <filename>]
  81. [CXX_MODULES_DIRECTORY <directory>])
  82. Creates a file ``<filename>`` that may be included by outside projects to
  83. import targets from the current project's build tree. This is the same
  84. as the `export(TARGETS)`_ signature, except that the targets are not
  85. explicitly listed. Instead, it exports the targets associated with
  86. the installation export ``<export-name>``. Target installations may be
  87. associated with the export ``<export-name>`` using the ``EXPORT`` option
  88. of the :command:`install(TARGETS)` command.
  89. Exporting Packages
  90. ^^^^^^^^^^^^^^^^^^
  91. .. _`export(PACKAGE)`:
  92. .. _PACKAGE:
  93. .. code-block:: cmake
  94. export(PACKAGE <PackageName>)
  95. Store the current build directory in the CMake user package registry
  96. for package ``<PackageName>``. The :command:`find_package` command may consider the
  97. directory while searching for package ``<PackageName>``. This helps dependent
  98. projects find and use a package from the current project's build tree
  99. without help from the user. Note that the entry in the package
  100. registry that this command creates works only in conjunction with a
  101. package configuration file (``<PackageName>Config.cmake``) that works with the
  102. build tree. In some cases, for example for packaging and for system
  103. wide installations, it is not desirable to write the user package
  104. registry.
  105. .. versionchanged:: 3.1
  106. If the :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` variable
  107. is enabled, the ``export(PACKAGE)`` command will do nothing.
  108. .. versionchanged:: 3.15
  109. By default the ``export(PACKAGE)`` command does nothing (see policy
  110. :policy:`CMP0090`) because populating the user package registry has effects
  111. outside the source and build trees. Set the
  112. :variable:`CMAKE_EXPORT_PACKAGE_REGISTRY` variable to add build directories
  113. to the CMake user package registry.