5

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?

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113

2 Answers2

7
if get_option('buildtype').startswith('debug')
  add_project_arguments('-DDEBUG', language : 'cpp')
endif
TingPing
  • 2,129
  • 1
  • 12
  • 15
2

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
Steven R. Loomis
  • 4,228
  • 28
  • 39