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