target_compile_options.rst 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. target_compile_options
  2. ----------------------
  3. Add compile options to a target.
  4. ::
  5. target_compile_options(<target> [BEFORE]
  6. <INTERFACE|PUBLIC|PRIVATE> [items1...]
  7. [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
  8. Specify compile options to use when compiling a given target. The
  9. 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. If ``BEFORE`` is specified, the content will be prepended to the property
  13. instead of being appended.
  14. This command can be used to add any options, but
  15. alternative commands exist to add preprocessor definitions
  16. (:command:`target_compile_definitions` and :command:`add_definitions`) or
  17. include directories (:command:`target_include_directories` and
  18. :command:`include_directories`). See documentation of the
  19. :prop_dir:`directory <COMPILE_OPTIONS>` and
  20. :prop_tgt:`target <COMPILE_OPTIONS>` ``COMPILE_OPTIONS`` properties.
  21. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  22. specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
  23. items will populate the :prop_tgt:`COMPILE_OPTIONS` property of
  24. ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
  25. :prop_tgt:`INTERFACE_COMPILE_OPTIONS` property of ``<target>``.
  26. (:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
  27. The following arguments specify compile options. Repeated calls for the same
  28. ``<target>`` append items in the order called.
  29. Arguments to ``target_compile_options`` may use "generator expressions"
  30. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  31. manual for available expressions. See the :manual:`cmake-buildsystem(7)`
  32. manual for more on defining buildsystem properties.