当构建类型为调试时,如何定义 DEBUG?

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

当构建类型以 "debug" 开头时,我想将“-DDEBUG”传递给 C++ 编译器,如下所示:

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

但是没有meson.build_type(),所以我从介子那里得到这个错误信息:

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

如何获取构建类型?或者是否有不同的方式在调试版本中定义 DEBUG

if get_option('buildtype').startswith('debug')
  add_project_arguments('-DDEBUG', language : 'cpp')
endif