From be3728b9fa319774687c91d3844e237dbaf1980c Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 8 Apr 2020 15:14:31 -0400 Subject: [PATCH] Meson: Add glib_checks and glib_asserts options In cases where performance are critical it can be useful to disable checks and asserts. GStreamer has those options too, using the same name and setting them yielding means we can set those options on the main project (e.g. gst-build) and glib will inherit the same value when built as subproject. --- .gitlab-ci.yml | 3 +-- docs/macros.txt | 7 ++++--- meson.build | 10 ++++++++++ meson_options.txt | 12 ++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aa4e004ec..7df220930 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -178,8 +178,6 @@ G_DISABLE_ASSERT: extends: .build image: $FEDORA_IMAGE stage: build - variables: - CPPFLAGS: "-DG_DISABLE_ASSERT" script: - meson ${MESON_COMMON_OPTIONS} --werror @@ -187,6 +185,7 @@ G_DISABLE_ASSERT: -Ddtrace=true -Dfam=true -Dinstalled_tests=true + -Dglib_assert=false _build - ninja -C _build - bash -x ./.gitlab-ci/run-tests.sh diff --git a/docs/macros.txt b/docs/macros.txt index c462de513..aa326a4dc 100644 --- a/docs/macros.txt +++ b/docs/macros.txt @@ -5,9 +5,10 @@ GLib's configure options and corresponding macros none --buildtype={debug,debugoptimized} [debugoptimized is the default] -DG_ENABLE_DEBUG -g - -Available to define yourself: - -DG_DISABLE_ASSERT -DG_DISABLE_CHECKS +-Dglib_asserts=false + -DG_DISABLE_ASSERT +-Dglib_checks=false + -DG_DISABLE_CHECKS Besides these, there are some local feature specific options, but my main focus here is to concentrate on macros that affect overall GLib behaviour diff --git a/meson.build b/meson.build index 1e3ba4d38..34d830c21 100644 --- a/meson.build +++ b/meson.build @@ -233,6 +233,16 @@ elif get_option('optimization') in ['2', '3', 's'] message('Disabling cast checks') endif +if not get_option('glib_assert') + glib_debug_cflags += ['-DG_DISABLE_ASSERT'] + message('Disabling GLib asserts') +endif + +if not get_option('glib_checks') + glib_debug_cflags += ['-DG_DISABLE_CHECKS'] + message('Disabling GLib checks') +endif + add_project_arguments(glib_debug_cflags, language: 'c') # check for header files diff --git a/meson_options.txt b/meson_options.txt index 6c72168dd..80a1d9d8f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -94,3 +94,15 @@ option('oss_fuzz', type : 'feature', value : 'disabled', description : 'Indicate oss-fuzz build environment') + +option('glib_assert', + type : 'boolean', + value : true, + yield : true, + description : 'Enable GLib assertion (see docs/macros.txt)') + +option('glib_checks', + type : 'boolean', + value : true, + yield : true, + description : 'Enable GLib checks such as API guards (see docs/macros.txt)')