target_compile_options.rst 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. target_compile_options
  2. ----------------------
  3. Add compile options to a target.
  4. .. code-block:: cmake
  5. target_compile_options(<target> [BEFORE]
  6. <INTERFACE|PUBLIC|PRIVATE> [items1...]
  7. [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
  8. Adds options to the :prop_tgt:`COMPILE_OPTIONS` or
  9. :prop_tgt:`INTERFACE_COMPILE_OPTIONS` target properties. These options
  10. are used when compiling the given ``<target>``, which must have been
  11. created by a command such as :command:`add_executable` or
  12. :command:`add_library` and must not be an :ref:`ALIAS target <Alias Targets>`.
  13. Arguments
  14. ^^^^^^^^^
  15. If ``BEFORE`` is specified, the content will be prepended to the property
  16. instead of being appended.
  17. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  18. specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
  19. items will populate the :prop_tgt:`COMPILE_OPTIONS` property of
  20. ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
  21. :prop_tgt:`INTERFACE_COMPILE_OPTIONS` property of ``<target>``.
  22. The following arguments specify compile options. Repeated calls for the same
  23. ``<target>`` append items in the order called.
  24. .. versionadded:: 3.11
  25. Allow setting ``INTERFACE`` items on :ref:`IMPORTED targets <Imported Targets>`.
  26. Arguments to ``target_compile_options`` 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. .. include:: OPTIONS_SHELL.txt
  31. See Also
  32. ^^^^^^^^
  33. This command can be used to add any options. However, for adding
  34. preprocessor definitions and include directories it is recommended
  35. to use the more specific commands :command:`target_compile_definitions`
  36. and :command:`target_include_directories`.
  37. For directory-wide settings, there is the command :command:`add_compile_options`.
  38. For file-specific settings, there is the source file property :prop_sf:`COMPILE_OPTIONS`.