87dff39ae655e77ffc08bc8aca70bf4c40e3bdb0
[platform/upstream/cmake.git] / Help / command / target_link_options.rst
1 target_link_options
2 -------------------
3
4 .. versionadded:: 3.13
5
6 Add options to the link step for an executable, shared library or module
7 library target.
8
9 .. code-block:: cmake
10
11   target_link_options(<target> [BEFORE]
12     <INTERFACE|PUBLIC|PRIVATE> [items1...]
13     [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
14
15 The named ``<target>`` must have been created by a command such as
16 :command:`add_executable` or :command:`add_library` and must not be an
17 :ref:`ALIAS target <Alias Targets>`.
18
19 This command can be used to add any link options, but alternative commands
20 exist to add libraries (:command:`target_link_libraries` or
21 :command:`link_libraries`).  See documentation of the
22 :prop_dir:`directory <LINK_OPTIONS>` and
23 :prop_tgt:`target <LINK_OPTIONS>` ``LINK_OPTIONS`` properties.
24
25 .. note::
26
27   This command cannot be used to add options for static library targets,
28   since they do not use a linker.  To add archiver or MSVC librarian flags,
29   see the :prop_tgt:`STATIC_LIBRARY_OPTIONS` target property.
30
31 If ``BEFORE`` is specified, the content will be prepended to the property
32 instead of being appended.
33
34 The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
35 specify the scope of the following arguments.  ``PRIVATE`` and ``PUBLIC``
36 items will populate the :prop_tgt:`LINK_OPTIONS` property of
37 ``<target>``.  ``PUBLIC`` and ``INTERFACE`` items will populate the
38 :prop_tgt:`INTERFACE_LINK_OPTIONS` property of ``<target>``.
39 The following arguments specify link options.  Repeated calls for the same
40 ``<target>`` append items in the order called.
41
42 .. note::
43   :ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.
44
45 Arguments to ``target_link_options`` may use "generator expressions"
46 with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
47 manual for available expressions.  See the :manual:`cmake-buildsystem(7)`
48 manual for more on defining buildsystem properties.
49
50 .. include:: DEVICE_LINK_OPTIONS.txt
51
52 .. include:: OPTIONS_SHELL.txt
53
54 .. include:: LINK_OPTIONS_LINKER.txt