Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Help / command / target_compile_options.rst
1 target_compile_options
2 ----------------------
3
4 Add compile options to a target.
5
6 .. code-block:: cmake
7
8   target_compile_options(<target> [BEFORE]
9     <INTERFACE|PUBLIC|PRIVATE> [items1...]
10     [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
11
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>`.
17
18 Arguments
19 ^^^^^^^^^
20
21 If ``BEFORE`` is specified, the content will be prepended to the property
22 instead of being appended.
23
24 The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
25 specify the :ref:`scope <Target Usage Requirements>` of the following arguments.
26 ``PRIVATE`` and ``PUBLIC`` items will populate the :prop_tgt:`COMPILE_OPTIONS`
27 property of ``<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.
31
32 .. versionadded:: 3.11
33   Allow setting ``INTERFACE`` items on :ref:`IMPORTED targets <Imported Targets>`.
34
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.
39
40 .. include:: OPTIONS_SHELL.txt
41
42 See Also
43 ^^^^^^^^
44
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`.
49
50 For directory-wide settings, there is the command :command:`add_compile_options`.
51
52 For file-specific settings, there is the source file property :prop_sf:`COMPILE_OPTIONS`.