target_compile_options.rst 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 :ref:`scope <Target Usage Requirements>` of the following arguments.
  19. ``PRIVATE`` and ``PUBLIC`` items will populate the :prop_tgt:`COMPILE_OPTIONS`
  20. property of ``<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. .. |command_name| replace:: ``target_compile_options``
  27. .. include:: GENEX_NOTE.txt
  28. .. include:: OPTIONS_SHELL.txt
  29. See Also
  30. ^^^^^^^^
  31. * This command can be used to add any options. However, for adding
  32. preprocessor definitions and include directories it is recommended
  33. to use the more specific commands :command:`target_compile_definitions`
  34. and :command:`target_include_directories`.
  35. * For directory-wide settings, there is the command :command:`add_compile_options`.
  36. * For file-specific settings, there is the source file property :prop_sf:`COMPILE_OPTIONS`.
  37. * :command:`target_compile_features`
  38. * :command:`target_link_libraries`
  39. * :command:`target_link_directories`
  40. * :command:`target_link_options`
  41. * :command:`target_precompile_headers`
  42. * :command:`target_sources`