[gtk/mcatanzaro/build-best-practices] Add build options for finer-grained control over build flags
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/mcatanzaro/build-best-practices] Add build options for finer-grained control over build flags
- Date: Sat, 13 Aug 2022 16:19:32 +0000 (UTC)
commit c3fafbdf37ee7e1ee10617d89cf5e6a4906e467a
Author: Michael Catanzaro <mcatanzaro redhat com>
Date: Thu Aug 4 13:18:39 2022 -0500
Add build options for finer-grained control over build flags
GLib has nice build options to allow finer-grained control over its
debug options. GTK should too, because explicit is better than implicit.
Sadly, it is impossible to make our options compatible with the
corresponding GLib options, so I have named them with gtk_ prefixes
instead of glib_ prefixes, and disabled the ability to yield them from
the parent project, which is arguably expected. The problem is GLib's
options are mostly boolean options (except for glib_debug, which is a
feature option) whereas the GTK options have to be feature options. This
is because GTK wants to vary the default behavior of most of its options
based on build type. In contrast, GLib varies only the value of
glib_debug based on build type.
If we want to be compatible with GLib's build options, then we would
need to either (a) change GLib's build options to be feature options
instead of bool options, or (b) not vary the default value of gtk_assert
and gtk_consistency_checks based on build type.
docs/reference/gtk/building.md | 4 ++++
meson.build | 23 ++++++++++++++++++++---
meson_options.txt | 22 ++++++++++++++++++++++
3 files changed, 46 insertions(+), 3 deletions(-)
---
diff --git a/docs/reference/gtk/building.md b/docs/reference/gtk/building.md
index e12f0e33ed..6f6c0b1e58 100644
--- a/docs/reference/gtk/building.md
+++ b/docs/reference/gtk/building.md
@@ -95,6 +95,10 @@ applications, as they include additional validation of the internal state.
The `debugoptimized` build type is the default for GTK if no build
type is specified when calling *meson*.
+You may use the `gtk_debug`, `gtk_assert`, `gtk_checks`, and
+`gtk_consistency_checks` build options if you wish to configure
+debugging features manually.
+
## Dependencies
Before you can compile the GTK widget toolkit, you need to have
diff --git a/meson.build b/meson.build
index 2f5670321d..0e5fc2f322 100644
--- a/meson.build
+++ b/meson.build
@@ -61,11 +61,28 @@ add_project_arguments('-D_GNU_SOURCE', language: 'c')
# cast checks. We have a non-production (debug) build if debug is true and if
# optimization is 0 or g; otherwise, we have a production build.
gtk_debug_cflags = []
+gtk_debug = get_option('gtk_debug')
optimized_build = get_option('optimization') not in [ '0', 'g' ]
-if get_option('debug') and not optimized_build
- gtk_debug_cflags += ['-DG_ENABLE_DEBUG', '-DG_ENABLE_CONSISTENCY_CHECKS']
+debug_build = get_option('debug') and not optimized_build
+
+if gtk_debug.enabled() or (gtk_debug.auto() and debug_build)
+ gtk_debug_cflags += ['-DG_ENABLE_DEBUG']
elif optimized_build
- gtk_debug_cflags += ['-DG_DISABLE_CAST_CHECKS', '-DG_DISABLE_ASSERT']
+ gtk_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
+endif
+
+gtk_assert = get_option('gtk_assert')
+if gtk_assert.disabled() or (gtk_assert.auto() and not debug_build)
+ gtk_debug_cflags += ['-DG_DISABLE_ASSERT']
+endif
+
+if get_option('gtk_checks').disabled()
+ gtk_debug_cflags += ['-DG_DISABLE_CHECKS']
+endif
+
+gtk_consistency_checks = get_option('gtk_consistency_checks')
+if gtk_consistency_checks.enabled() or (gtk_consistency_checks.auto() and debug_build)
+ gtk_debug_cflags += ['-DG_ENABLE_CONSISTENCY_CHECKS']
endif
add_project_arguments(gtk_debug_cflags, language: 'c')
diff --git a/meson_options.txt b/meson_options.txt
index 2084ab86e1..f2df4f9670 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -128,3 +128,25 @@ option('install-tests',
type: 'boolean',
value: false,
description : 'Install tests')
+
+# Diagnostics and performance
+
+option('gtk_debug',
+ type : 'feature',
+ value : 'auto',
+ description : 'Enable GTK debug infrastructure')
+
+option('gtk_assert',
+ type : 'feature',
+ value : 'auto',
+ description : 'Enable assertions')
+
+option('gtk_checks',
+ type : 'feature',
+ value : 'enabled',
+ description : 'Enable extra checks such as API guards')
+
+option('gtk_consistency_checks',
+ type : 'feature',
+ value : 'auto',
+ description : 'Enable extra internal consistency checks')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]