How can i define DEBUG when the build type is debug?

Viewed 1231

I want to pass "-DDEBUG" to the C++ compiler when the build type starts with "debug", something like this:

if meson.build_type().starts_with('debug')
  add_global_arguments('-DDEBUG', language : 'cpp')
endif

However there is no meson.build_type(), so I get this error message from meson:

Meson encountered an error in file meson.build, line 5, column 23:
Unknown method "build_type" in object.

How can I get the build type? Or is there a different way to define DEBUG in debug builds?

2 Answers

The accepted answer didn't work on meson 0.63.0, instead I did this, per the FAQ:

if get_option('buildtype') == 'debug'
  add_global_arguments('-DDEBUG', language : 'cpp')
endif
Related