target_compile_options.rst 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. See policy :policy:`CMP0101` which affects
  17. whether ``BEFORE`` will be ignored in certain cases.
  18. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  19. specify the :ref:`scope <Target Usage Requirements>` of the following arguments.
  20. ``PRIVATE`` and ``PUBLIC`` items will populate the :prop_tgt:`COMPILE_OPTIONS`
  21. property of ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
  22. :prop_tgt:`INTERFACE_COMPILE_OPTIONS` property of ``<target>``.
  23. The following arguments specify compile options. Repeated calls for the same
  24. ``<target>`` append items in the order called.
  25. .. versionadded:: 3.11
  26. Allow setting ``INTERFACE`` items on :ref:`IMPORTED targets <Imported Targets>`.
  27. .. |command_name| replace:: ``target_compile_options``
  28. .. include:: GENEX_NOTE.txt
  29. .. include:: OPTIONS_SHELL.txt
  30. See Also
  31. ^^^^^^^^
  32. * This command can be used to add any options. However, for adding
  33. preprocessor definitions and include directories it is recommended
  34. to use the more specific commands :command:`target_compile_definitions`
  35. and :command:`target_include_directories`.
  36. * For directory-wide settings, there is the command :command:`add_compile_options`.
  37. * For file-specific settings, there is the source file property :prop_sf:`COMPILE_OPTIONS`.
  38. * :command:`target_compile_features`
  39. * :command:`target_link_libraries`
  40. * :command:`target_link_directories`
  41. * :command:`target_link_options`
  42. * :command:`target_precompile_headers`
  43. * :command:`target_sources`