[libgit2-glib] meson: Improve compiler flags and debugging options



commit 5691ce60dbc922b1df39dfea8358dbd59d9ad01b
Author: Iñigo Martínez <inigomartinez gmail com>
Date:   Fri Jan 19 16:15:54 2018 +0100

    meson: Improve compiler flags and debugging options
    
    meson provides two options related to debug options. The first one
    is the build type, which among others, can be `debug` build or
    `debugoptimized`. The second option which is called `b_ndebug` can
    be used to enable or disable assertions.
    
    The meson guidelines[0] recommends the use of options present in
    meson, so the combination of these two options has been used to
    replace the `debug` option.
    
    - `debug` build sets the `LIBGIT2_GLIB_ENABLE_DEBUG` macro, which
      is equivalent to `debug=yes`.
    - `debugoptimized` build sets the same macros as `debug`, but also
      set `G_DISABLE_CAST_CHECKS`, which is equivalent to
      `debug=minimum`.
    - If build is not a `debug*` build it sets `G_DISABLE_CAST_CHECKS`
      and `-G_DISABLE_CHECKS`.
    - If `b_ndebug` is true it sets `G_DISABLE_ASSERT`.
    
    To ease the compiler flags checking the `get_supported_arguments`
    helper function is also used, which implies bumping meson version to
    0.43.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=792699
    
    [0] https://wiki.gnome.org/Initiatives/GnomeGoals/MesonPorting

 libgit2-glib/meson.build |    3 +-
 meson.build              |   58 ++++++++++++++++-----------------------------
 meson_options.txt        |    1 -
 3 files changed, 22 insertions(+), 40 deletions(-)
---
diff --git a/libgit2-glib/meson.build b/libgit2-glib/meson.build
index 1d002b8..64f2596 100644
--- a/libgit2-glib/meson.build
+++ b/libgit2-glib/meson.build
@@ -200,8 +200,7 @@ libgit2_glib = shared_library('git2-glib-@0@'.format(libgit2_glib_api_version),
   soversion: soversion,
   install: true,
   dependencies: platform_deps,
-  c_args: extra_args + common_flags + debug_flags + [
-            '-DG_LOG_DOMAIN="Ggit"' ],
+  c_args: extra_args + [ '-DG_LOG_DOMAIN="Ggit"' ],
   link_args: libgit2_glib_link_args)
 
 pkg.generate(
diff --git a/meson.build b/meson.build
index 7454068..6aa8e8e 100644
--- a/meson.build
+++ b/meson.build
@@ -4,7 +4,7 @@ project('libgit2-glib', 'c',
           'buildtype=debugoptimized'
         ],
         license: 'LGPL2+',
-        meson_version: '>= 0.36.0')
+        meson_version: '>= 0.43.0')
 
 libgit2_glib_version = meson.project_version()
 version_array = libgit2_glib_version.split('.')
@@ -15,6 +15,8 @@ libgit2_glib_micro_version = version_array[2].to_int()
 libgit2_glib_api_version = '1.0'
 libgit2_glib_api_name = '@0@-@1@'.format(meson.project_name(), libgit2_glib_api_version)
 
+libgit2_glib_buildtype = get_option('buildtype')
+
 # The interface age is reset every time we add new API; this
 # should only happen during development cycles, otherwise the
 # interface age is the same as the micro version
@@ -41,12 +43,11 @@ libgit2_glib_pkgincludedir = join_paths(libgit2_glib_includedir, libgit2_glib_ap
 
 cc = meson.get_compiler('c')
 
-# Compiler flags
+# Compiler and Debugging flags
 if cc.get_id() == 'msvc'
   # Compiler options taken from msvc_recommended_pragmas.h
   # in GLib, based on _Win32_Programming_ by Rector and Newcomer
-  test_cflags = []
-  add_project_arguments('-FImsvc_recommended_pragmas.h', language: 'c')
+  common_flags = ['-FImsvc_recommended_pragmas.h']
 else
   test_cflags = [
     '-ffast-math',
@@ -76,48 +77,31 @@ else
     '-Werror=array-bounds',
     '-Werror=write-strings'
   ]
+
+  common_flags = cc.get_supported_arguments(test_cflags)
 endif
-common_flags = []
-foreach cflag: test_cflags
-  if cc.has_argument(cflag)
-    common_flags += [ cflag ]
-  endif
-endforeach
 
-# Termios
-have_termios = cc.has_header('termios.h')
+if libgit2_glib_buildtype.contains('debug')
+  common_flags += [ '-DLIBGIT2_GLIB_ENABLE_DEBUG' ]
 
-# Debugging
-enable_debug = get_option('debug')
-if enable_debug == 'auto'
-  if libgit2_glib_minor_version.is_odd()
-    enable_debug = 'yes'
-  else
-    enable_debug = 'minimum'
+  if libgit2_glib_buildtype.contains('optimized')
+    common_flags += [ '-DG_DISABLE_CAST_CHECKS' ]
   endif
-endif
-
-debug_flags = []
-if enable_debug == 'yes'
-  debug_flags += [
-    '-DLIBGIT2_GLIB_ENABLE_DEBUG'
+else
+  common_flags += [
+    '-DG_DISABLE_CAST_CHECKS',
+    '-DG_DISABLE_CHECKS'
   ]
 endif
 
-if enable_debug == 'minimum'
-  debug_flags += [
-    '-DLIBGIT2_GLIB_ENABLE_DEBUG',
-    '-DG_DISABLE_CAST_CHECKS'
-  ]
+if get_option('b_ndebug')
+  common_flags += [ '-DG_DISABLE_ASSERT' ]
 endif
 
-if enable_debug == 'no'
-  debug_flags += [
-    '-DG_DISABLE_CAST_CHECKS',
-    '-DG_DISABLE_CHECKS',
-    '-DG_DISABLE_ASSERT'
-  ]
-endif
+add_project_arguments(common_flags, language: 'c')
+
+# Termios
+have_termios = cc.has_header('termios.h')
 
 extra_args= []
 
diff --git a/meson_options.txt b/meson_options.txt
index 65f4a31..aa1c2c8 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,4 +1,3 @@
 option('gtk_doc', type: 'boolean', value: false, description: 'Enable generating the API reference (depends 
on GTK-Doc)')
 option('introspection', type: 'boolean', value: true, description: 'Enable GObject Introspection')
-option('debug', type: 'combo', choices: [ 'auto', 'yes', 'minimum', 'no' ], value: 'yes', description: 
'Enable debugging level')
 option('ssh', type: 'boolean', value: true, description: 'Build with libgit2 ssh support')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]