target_link_options.rst 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. target_link_options
  2. -------------------
  3. Add options to the link step for an executable, shared library or module
  4. library target.
  5. .. code-block:: cmake
  6. target_link_options(<target> [BEFORE]
  7. <INTERFACE|PUBLIC|PRIVATE> [items1...]
  8. [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
  9. The 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. This command can be used to add any link options, but alternative commands
  13. exist to add libraries (:command:`target_link_libraries` or
  14. :command:`link_libraries`). See documentation of the
  15. :prop_dir:`directory <LINK_OPTIONS>` and
  16. :prop_tgt:`target <LINK_OPTIONS>` ``LINK_OPTIONS`` properties.
  17. .. note::
  18. This command cannot be used to add options for static library targets,
  19. since they do not use a linker. To add archiver or MSVC librarian flags,
  20. see the :prop_tgt:`STATIC_LIBRARY_OPTIONS` target property.
  21. If ``BEFORE`` is specified, the content will be prepended to the property
  22. instead of being appended.
  23. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  24. specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
  25. items will populate the :prop_tgt:`LINK_OPTIONS` property of
  26. ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
  27. :prop_tgt:`INTERFACE_LINK_OPTIONS` property of ``<target>``.
  28. (:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
  29. The following arguments specify link options. Repeated calls for the same
  30. ``<target>`` append items in the order called.
  31. Arguments to ``target_link_options`` may use "generator expressions"
  32. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  33. manual for available expressions. See the :manual:`cmake-buildsystem(7)`
  34. manual for more on defining buildsystem properties.
  35. .. include:: OPTIONS_SHELL.txt
  36. .. include:: LINK_OPTIONS_LINKER.txt