4 Add compile options to a target.
8 target_compile_options(<target> [BEFORE]
9 <INTERFACE|PUBLIC|PRIVATE> [items1...]
10 [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
12 Adds options to the :prop_tgt:`COMPILE_OPTIONS` or
13 :prop_tgt:`INTERFACE_COMPILE_OPTIONS` target properties. These options
14 are used when compiling the given ``<target>``, which must have been
15 created by a command such as :command:`add_executable` or
16 :command:`add_library` and must not be an :ref:`ALIAS target <Alias Targets>`.
21 If ``BEFORE`` is specified, the content will be prepended to the property
22 instead of being appended.
24 The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
25 specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
26 items will populate the :prop_tgt:`COMPILE_OPTIONS` property of
27 ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
28 :prop_tgt:`INTERFACE_COMPILE_OPTIONS` property of ``<target>``.
29 The following arguments specify compile options. Repeated calls for the same
30 ``<target>`` append items in the order called.
32 .. versionadded:: 3.11
33 Allow setting ``INTERFACE`` items on :ref:`IMPORTED targets <Imported Targets>`.
35 Arguments to ``target_compile_options`` may use "generator expressions"
36 with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
37 manual for available expressions. See the :manual:`cmake-buildsystem(7)`
38 manual for more on defining buildsystem properties.
40 .. include:: OPTIONS_SHELL.txt
45 This command can be used to add any options. However, for adding
46 preprocessor definitions and include directories it is recommended
47 to use the more specific commands :command:`target_compile_definitions`
48 and :command:`target_include_directories`.
50 For directory-wide settings, there is the command :command:`add_compile_options`.
52 For file-specific settings, there is the source file property :prop_sf:`COMPILE_OPTIONS`.