target_link_directories.rst 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. target_link_directories
  2. -----------------------
  3. Add link directories to a target.
  4. .. code-block:: cmake
  5. target_link_directories(<target> [BEFORE]
  6. <INTERFACE|PUBLIC|PRIVATE> [items1...]
  7. [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
  8. Specifies the paths in which the linker should search for libraries when
  9. linking a given target. Each item can be an absolute or relative path,
  10. with the latter being interpreted as relative to the current source
  11. directory. These items will be added to the link command.
  12. The named ``<target>`` must have been created by a command such as
  13. :command:`add_executable` or :command:`add_library` and must not be an
  14. :ref:`ALIAS target <Alias Targets>`.
  15. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  16. specify the scope of the items that follow them. ``PRIVATE`` and
  17. ``PUBLIC`` items will populate the :prop_tgt:`LINK_DIRECTORIES` property
  18. of ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
  19. :prop_tgt:`INTERFACE_LINK_DIRECTORIES` property of ``<target>``
  20. (:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items).
  21. Each item specifies a link directory and will be converted to an absolute
  22. path if necessary before adding it to the relevant property. Repeated
  23. calls for the same ``<target>`` append items in the order called.
  24. If ``BEFORE`` is specified, the content will be prepended to the relevant
  25. property instead of being appended.
  26. Arguments to ``target_link_directories`` may use "generator expressions"
  27. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  28. manual for available expressions. See the :manual:`cmake-buildsystem(7)`
  29. manual for more on defining buildsystem properties.
  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 Xcode where the user can switch target
  38. 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``).