target_compile_definitions.rst 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. target_compile_definitions
  2. --------------------------
  3. Add compile definitions to a target.
  4. .. code-block:: cmake
  5. target_compile_definitions(<target>
  6. <INTERFACE|PUBLIC|PRIVATE> [items1...]
  7. [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
  8. Specifies compile definitions 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. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  13. specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
  14. items will populate the :prop_tgt:`COMPILE_DEFINITIONS` property of
  15. ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
  16. :prop_tgt:`INTERFACE_COMPILE_DEFINITIONS` property of ``<target>``.
  17. (:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
  18. The following arguments specify compile definitions. Repeated calls for the
  19. same ``<target>`` append items in the order called.
  20. Arguments to ``target_compile_definitions`` may use "generator expressions"
  21. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  22. manual for available expressions. See the :manual:`cmake-buildsystem(7)`
  23. manual for more on defining buildsystem properties.
  24. Any leading ``-D`` on an item will be removed. Empty items are ignored.
  25. For example, the following are all equivalent:
  26. .. code-block:: cmake
  27. target_compile_definitions(foo PUBLIC FOO)
  28. target_compile_definitions(foo PUBLIC -DFOO) # -D removed
  29. target_compile_definitions(foo PUBLIC "" FOO) # "" ignored
  30. target_compile_definitions(foo PUBLIC -D FOO) # -D becomes "", then ignored