From 8603bb491925d9cb74f63725e02fab2a0c6fafe1 Mon Sep 17 00:00:00 2001 From: Emil Melnikov Date: Wed, 29 May 2024 16:04:44 +0200 Subject: Explain how to add preprocessor defines in FAQ.md See https://github.com/mesonbuild/meson/issues/6269 for the discussion. Co-authored-by: Eli Schwartz --- docs/markdown/FAQ.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/markdown/FAQ.md b/docs/markdown/FAQ.md index ffc9e17..810e9da 100644 --- a/docs/markdown/FAQ.md +++ b/docs/markdown/FAQ.md @@ -695,3 +695,16 @@ directory. It glob ignores ```"*"```, since all generated files should not be checked into git. Users of older versions of Meson may need to set up ignore files themselves. + +## How to add preprocessor defines to a target? + +Just add `-DFOO` to `c_args` or `cpp_args`. This works for all known compilers. + +```meson +mylib = library('mylib', 'mysource.c', c_args: ['-DFOO']) +``` + +Even though [MSVC documentation](https://learn.microsoft.com/en-us/cpp/build/reference/d-preprocessor-definitions) +uses `/D` for preprocessor defines, its [command-line syntax](https://learn.microsoft.com/en-us/cpp/build/reference/compiler-command-line-syntax) +accepts `-` instead of `/`. +It's not necessary to treat preprocessor defines specially in Meson ([GH-6269](https://github.com/mesonbuild/meson/issues/6269#issuecomment-560003922)). -- cgit v1.1