add_compile_definitions.rst 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. add_compile_definitions
  2. -----------------------
  3. .. versionadded:: 3.12
  4. Add preprocessor definitions to the compilation of source files.
  5. .. code-block:: cmake
  6. add_compile_definitions(<definition> ...)
  7. Adds preprocessor definitions to the compiler command line.
  8. The preprocessor definitions are added to the :prop_dir:`COMPILE_DEFINITIONS`
  9. directory property for the current ``CMakeLists`` file. They are also added to
  10. the :prop_tgt:`COMPILE_DEFINITIONS` target property for each target in the
  11. current ``CMakeLists`` file.
  12. Definitions are specified using the syntax ``VAR`` or ``VAR=value``.
  13. Function-style definitions are not supported. CMake will automatically
  14. escape the value correctly for the native build system (note that CMake
  15. language syntax may require escapes to specify some values).
  16. .. versionadded:: 3.26
  17. Any leading ``-D`` on an item will be removed.
  18. .. |command_name| replace:: ``add_compile_definitions``
  19. .. include:: GENEX_NOTE.txt
  20. See Also
  21. ^^^^^^^^
  22. * The command :command:`target_compile_definitions` adds target-specific definitions.