[template-glib] build: setup various performance build options



commit 1c0a3e2b610d4cdfaf276d7c3fd4377f31105a82
Author: Christian Hergert <chergert redhat com>
Date:   Thu May 5 13:35:16 2022 -0700

    build: setup various performance build options
    
     * Use -Wl,-z,relro and -Wl,-z,now when possible in release builds
     * Use -Wl,-Bsymbolic and -fno-plt when possible
     * Disable cast checks and assertions in release builds

 meson.build     | 23 +++++++++++++++++++++++
 src/meson.build |  1 +
 2 files changed, 24 insertions(+)
---
diff --git a/meson.build b/meson.build
index e4632bf..cc92f42 100644
--- a/meson.build
+++ b/meson.build
@@ -32,6 +32,29 @@ config_h = configuration_data()
 config_h.set_quoted('GETTEXT_PACKAGE', 'libtemplate_glib')
 config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
 
+cc = meson.get_compiler('c')
+
+release_args = []
+global_link_args = []
+test_link_args = [
+  '-Wl,-z,relro',
+  '-Wl,-z,now',
+]
+if not get_option('buildtype').startswith('debug')
+  add_project_arguments(['-DG_DISABLE_CAST_CHECKS'], language: 'c')
+  release_args += [ '-DG_DISABLE_ASSERT' ]
+  test_link_args += [
+    '-Wl,-Bsymbolic',
+    '-fno-plt',
+  ]
+endif
+foreach link_arg: test_link_args
+  if cc.links('int main () { return 0; }', name: link_arg, args: link_arg)
+    global_link_args += link_arg
+  endif
+endforeach
+add_project_link_arguments(global_link_args, language: 'c')
+
 configure_file(
   output: 'config.h',
   configuration: config_h,
diff --git a/src/meson.build b/src/meson.build
index bc654e1..b622c4d 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -142,6 +142,7 @@ endif
 
 core_lib = static_library('template_glib', libtemplate_glib_sources,
    dependencies: libtemplate_glib_deps,
+         c_args: release_args,
 )
 
 libtemplate_glib = library(


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