target_link_directories.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. target_link_directories
  2. -----------------------
  3. .. versionadded:: 3.13
  4. Add link directories to a target.
  5. .. code-block:: cmake
  6. target_link_directories(<target> [BEFORE]
  7. <INTERFACE|PUBLIC|PRIVATE> [items1...]
  8. [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
  9. Specifies the paths in which the linker should search for libraries when
  10. linking a given target. Each item can be an absolute or relative path,
  11. with the latter being interpreted as relative to the current source
  12. directory. These items will be added to the link command.
  13. The named ``<target>`` must have been created by a command such as
  14. :command:`add_executable` or :command:`add_library` and must not be an
  15. :ref:`ALIAS target <Alias Targets>`.
  16. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  17. specify the :ref:`scope <Target Command Scope>` of the items that follow
  18. them. ``PRIVATE`` and ``PUBLIC`` items will populate the
  19. :prop_tgt:`LINK_DIRECTORIES` property of ``<target>``. ``PUBLIC`` and
  20. ``INTERFACE`` items will populate the :prop_tgt:`INTERFACE_LINK_DIRECTORIES`
  21. property of ``<target>`` (:ref:`IMPORTED targets <Imported Targets>` only
  22. support ``INTERFACE`` items).
  23. Each item specifies a link directory and will be converted to an absolute
  24. path if necessary before adding it to the relevant property. Repeated
  25. calls for the same ``<target>`` append items in the order called.
  26. If ``BEFORE`` is specified, the content will be prepended to the relevant
  27. property instead of being appended.
  28. .. |command_name| replace:: ``target_link_directories``
  29. .. include:: include/GENEX_NOTE.rst
  30. .. note::
  31. This command is rarely necessary and should be avoided where there are
  32. other choices. Prefer to pass full absolute paths to libraries where
  33. possible, since this ensures the correct library will always be linked.
  34. The :command:`find_library` command provides the full path, which can
  35. generally be used directly in calls to :command:`target_link_libraries`.
  36. Situations where a library search path may be needed include:
  37. - Project generators like :generator:`Xcode` where the user can switch
  38. target architecture at build time, but a full path to a library cannot
  39. be used because it only provides one architecture (i.e. it is not
  40. a universal binary).
  41. - Libraries may themselves have other private library dependencies
  42. that expect to be found via ``RPATH`` mechanisms, but some linkers
  43. are not able to fully decode those paths (e.g. due to the presence
  44. of things like ``$ORIGIN``).
  45. See Also
  46. ^^^^^^^^
  47. * :command:`link_directories`
  48. * :command:`target_compile_definitions`
  49. * :command:`target_compile_features`
  50. * :command:`target_compile_options`
  51. * :command:`target_include_directories`
  52. * :command:`target_link_libraries`
  53. * :command:`target_link_options`
  54. * :command:`target_precompile_headers`
  55. * :command:`target_sources`