From 4196a0e73a972c7a0eb163a3b5ceded78c8fc28f Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 25 Feb 2022 12:52:18 +0000 Subject: [PATCH] set some -Ds depending on the release type (#2682) * set some -Ds depending on the release type libvips uses g_assert() quite a bit to check things like pointer bounds, and this can have a large performance impact. This PR turns off g_assert() (plus some other things) in release mode, and enables leak checking (and some other things) in debug mode. I'm not sure if this is the best way to implement this kind of thing. Does meson have a more offical path for this? * incorporate comments * link asserts and cast checks to optimization level --- meson.build | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 24d239f3..d03cb67c 100644 --- a/meson.build +++ b/meson.build @@ -3,7 +3,9 @@ project('vips', 'c', 'cpp', meson_version: '>=0.56', default_options: [ # this is what glib uses (one of our required deps), so we use it too - 'c_std=gnu99' + 'c_std=gnu99', + # turn off asserts etc. in release mode + 'b_ndebug=if-release' ] ) @@ -33,6 +35,21 @@ add_project_link_arguments( language: 'c', ) +# if we're optimising (eg. release mode) we turn off cast checks and +# g_asserts +if get_option('optimization') in ['2', '3', 's'] + add_project_arguments('-DG_DISABLE_CAST_CHECKS', language : ['cpp', 'c']) + add_project_arguments('-DG_DISABLE_CHECKS', language : ['cpp', 'c']) + add_project_arguments('-DG_DISABLE_ASSERT', language : ['cpp', 'c']) +endif + +# in debug mode we automatically enable leak checks and fatal warnings +# also true for 'debugoptimized' +if get_option('debug') + add_project_arguments('-DDEBUG_FATAL', language : ['cpp', 'c']) + add_project_arguments('-DDEBUG_LEAK', language : ['cpp', 'c']) +endif + cc = meson.get_compiler('c') cpp = meson.get_compiler('cpp')