target_compile_options.rst 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. :prop_tgt:`IMPORTED Target`. If ``BEFORE`` is specified, the content will
  12. be prepended to the property instead of being appended.
  13. This command can be used to add any options, but
  14. alternative commands exist to add preprocessor definitions
  15. (:command:`target_compile_definitions` and :command:`add_definitions`) or
  16. include directories (:command:`target_include_directories` and
  17. :command:`include_directories`). See documentation of the
  18. :prop_tgt:`directory <COMPILE_OPTIONS>` and
  19. :prop_tgt:` target <COMPILE_OPTIONS>` ``COMPILE_OPTIONS`` properties.
  20. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  21. specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
  22. items will populate the :prop_tgt:`COMPILE_OPTIONS` property of
  23. ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
  24. :prop_tgt:`INTERFACE_COMPILE_OPTIONS` property of ``<target>``. The
  25. following arguments specify compile options. Repeated calls for the same
  26. ``<target>`` append items in the order called.
  27. Arguments to ``target_compile_options`` may use "generator expressions"
  28. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  29. manual for available expressions. See the :manual:`cmake-buildsystem(7)`
  30. manual for more on defining buildsystem properties.