target_compile_options.rst 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. (:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
  23. The following arguments specify compile options. Repeated calls for the same
  24. ``<target>`` append items in the order called.
  25. Arguments to ``target_compile_options`` may use "generator expressions"
  26. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  27. manual for available expressions. See the :manual:`cmake-buildsystem(7)`
  28. manual for more on defining buildsystem properties.
  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`.