target_link_options.rst 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. target_link_options
  2. -------------------
  3. Add link options to a target.
  4. ::
  5. target_link_options(<target> [BEFORE]
  6. <INTERFACE|PUBLIC|PRIVATE> [items1...]
  7. [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
  8. Specify link options to use when linking a given target. The
  9. named ``<target>`` must have been created by a command such as
  10. :command:`add_executable` or :command:`add_library` and must not be an
  11. :ref:`ALIAS target <Alias Targets>`.
  12. If ``BEFORE`` is specified, the content will be prepended to the property
  13. instead of being appended.
  14. This command can be used to add any options, but
  15. alternative commands exist to add libraries
  16. (:command:`target_link_libraries` and :command:`link_libraries`).
  17. See documentation of the :prop_dir:`directory <LINK_OPTIONS>` and
  18. :prop_tgt:`target <LINK_OPTIONS>` ``LINK_OPTIONS`` properties.
  19. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  20. specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
  21. items will populate the :prop_tgt:`LINK_OPTIONS` property of
  22. ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
  23. :prop_tgt:`INTERFACE_LINK_OPTIONS` property of ``<target>``.
  24. (:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
  25. The following arguments specify link options. Repeated calls for the same
  26. ``<target>`` append items in the order called.
  27. Arguments to ``target_link_options`` may use "generator expressions"
  28. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  29. manual for available expressions. See the :manual:`cmake-buildsystem(7)`
  30. manual for more on defining buildsystem properties.
  31. .. include:: LINK_OPTIONS_LINKER.txt
  32. .. include:: OPTIONS_SHELL.txt