1target_compile_definitions 2-------------------------- 3 4Add compile definitions to a target. 5 6.. code-block:: cmake 7 8 target_compile_definitions(<target> 9 <INTERFACE|PUBLIC|PRIVATE> [items1...] 10 [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...]) 11 12Specifies compile definitions to use when compiling a given ``<target>``. The 13named ``<target>`` must have been created by a command such as 14:command:`add_executable` or :command:`add_library` and must not be an 15:ref:`ALIAS target <Alias Targets>`. 16 17The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to 18specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC`` 19items will populate the :prop_tgt:`COMPILE_DEFINITIONS` property of 20``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the 21:prop_tgt:`INTERFACE_COMPILE_DEFINITIONS` property of ``<target>``. 22The following arguments specify compile definitions. Repeated calls for the 23same ``<target>`` append items in the order called. 24 25.. versionadded:: 3.11 26 Allow setting ``INTERFACE`` items on :ref:`IMPORTED targets <Imported Targets>`. 27 28Arguments to ``target_compile_definitions`` may use "generator expressions" 29with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` 30manual for available expressions. See the :manual:`cmake-buildsystem(7)` 31manual for more on defining buildsystem properties. 32 33Any leading ``-D`` on an item will be removed. Empty items are ignored. 34For example, the following are all equivalent: 35 36.. code-block:: cmake 37 38 target_compile_definitions(foo PUBLIC FOO) 39 target_compile_definitions(foo PUBLIC -DFOO) # -D removed 40 target_compile_definitions(foo PUBLIC "" FOO) # "" ignored 41 target_compile_definitions(foo PUBLIC -D FOO) # -D becomes "", then ignored 42 43Definitions may optionally have values: 44 45.. code-block:: cmake 46 47 target_compile_definitions(foo PUBLIC FOO=1) 48 49Note that many compilers treat ``-DFOO`` as equivalent to ``-DFOO=1``, but 50other tools may not recognize this in all circumstances (e.g. IntelliSense). 51