export.rst 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. export
  2. ------
  3. Export targets from the build tree for use by outside projects.
  4. ::
  5. export(EXPORT <export-name> [NAMESPACE <namespace>] [FILE <filename>])
  6. Create a file ``<filename>`` that may be included by outside projects to
  7. import targets from the current project's build tree. This is useful
  8. during cross-compiling to build utility executables that can run on
  9. the host platform in one project and then import them into another
  10. project being compiled for the target platform. If the ``NAMESPACE``
  11. option is given the ``<namespace>`` string will be prepended to all target
  12. names written to the file.
  13. Target installations are associated with the export ``<export-name>``
  14. using the ``EXPORT`` option of the :command:`install(TARGETS)` command.
  15. The file created by this command is specific to the build tree and
  16. should never be installed. See the :command:`install(EXPORT)` command to
  17. export targets from an installation tree.
  18. The properties set on the generated IMPORTED targets will have the
  19. same values as the final values of the input TARGETS.
  20. ::
  21. export(TARGETS [target1 [target2 [...]]] [NAMESPACE <namespace>]
  22. [APPEND] FILE <filename> [EXPORT_LINK_INTERFACE_LIBRARIES])
  23. This signature is similar to the ``EXPORT`` signature, but targets are listed
  24. explicitly rather than specified as an export-name. If the APPEND option is
  25. given the generated code will be appended to the file instead of overwriting it.
  26. The EXPORT_LINK_INTERFACE_LIBRARIES keyword, if present, causes the
  27. contents of the properties matching
  28. ``(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?`` to be exported, when
  29. policy CMP0022 is NEW. If a library target is included in the export
  30. but a target to which it links is not included the behavior is
  31. unspecified.
  32. .. note::
  33. :ref:`Object Libraries` under :generator:`Xcode` have special handling if
  34. multiple architectures are listed in :variable:`CMAKE_OSX_ARCHITECTURES`.
  35. In this case they will be exported as :ref:`Interface Libraries` with
  36. no object files available to clients.
  37. ::
  38. export(PACKAGE <name>)
  39. Store the current build directory in the CMake user package registry
  40. for package ``<name>``. The find_package command may consider the
  41. directory while searching for package ``<name>``. This helps dependent
  42. projects find and use a package from the current project's build tree
  43. without help from the user. Note that the entry in the package
  44. registry that this command creates works only in conjunction with a
  45. package configuration file (``<name>Config.cmake``) that works with the
  46. build tree. In some cases, for example for packaging and for system
  47. wide installations, it is not desirable to write the user package
  48. registry. If the :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` variable
  49. is enabled, the ``export(PACKAGE)`` command will do nothing.
  50. ::
  51. export(TARGETS [target1 [target2 [...]]] [ANDROID_MK <filename>])
  52. This signature exports cmake built targets to the android ndk build system
  53. by creating an Android.mk file that references the prebuilt targets. The
  54. Android NDK supports the use of prebuilt libraries, both static and shared.
  55. This allows cmake to build the libraries of a project and make them available
  56. to an ndk build system complete with transitive dependencies, include flags
  57. and defines required to use the libraries. The signature takes a list of
  58. targets and puts them in the Android.mk file specified by the ``<filename>``
  59. given. This signature can only be used if policy CMP0022 is NEW for all
  60. targets given. A error will be issued if that policy is set to OLD for one
  61. of the targets.