[gnome-builder/wip/gtk4-port: 1407/1774] plugins/meson-templates: import some compiler wisdom




commit d47fe30abd931d15be3d25886134433bac862f2c
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jun 7 17:26:09 2022 -0700

    plugins/meson-templates: import some compiler wisdom
    
    Seriously though, we need to tweak our compiler flags quit a bit to get
    something that will help people catch bugs without being overly pedantic
    and annoying. This at least shows the way.
    
    Happy to take other ideas here, but this fixes a bunch of warnings that
    would be shown for typical GLib/GTK stuff while also ramping up some
    errors on things that should also matter.

 src/plugins/meson-templates/resources/meson.build | 73 ++++++++++++++++++++++-
 1 file changed, 72 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/meson-templates/resources/meson.build 
b/src/plugins/meson-templates/resources/meson.build
index 0c74af043..b30a83a11 100644
--- a/src/plugins/meson-templates/resources/meson.build
+++ b/src/plugins/meson-templates/resources/meson.build
@@ -16,10 +16,12 @@ project('{{name}}',{{if language == "c"}} 'c',{{else if language == "c++"}} ['cp
 {{if enable_i18n}}
 i18n = import('i18n')
 {{end}}
-
 {{if enable_gnome}}
 gnome = import('gnome')
 {{end}}
+{{if language == "c"}}
+cc = meson.get_compiler('c')
+{{end}}
 
 {{if language == "c"}}
 config_h = configuration_data()
@@ -37,6 +39,75 @@ add_project_arguments([
 ], language: 'c')
 {{end}}
 
+{{if language == "c"}}
+project_c_args = []
+test_c_args = [
+  '-Wcast-align',
+  '-Wdeclaration-after-statement',
+  '-Werror=address',
+  '-Werror=array-bounds',
+  '-Werror=empty-body',
+  '-Werror=implicit',
+  '-Werror=implicit-function-declaration',
+  '-Werror=incompatible-pointer-types',
+  '-Werror=init-self',
+  '-Werror=int-conversion',
+  '-Werror=int-to-pointer-cast',
+  '-Werror=main',
+  '-Werror=misleading-indentation',
+  '-Werror=missing-braces',
+  '-Werror=missing-include-dirs',
+  '-Werror=nonnull',
+  '-Werror=overflow',
+  '-Werror=parenthesis',
+  '-Werror=pointer-arith',
+  '-Werror=pointer-to-int-cast',
+  '-Werror=redundant-decls',
+  '-Werror=return-type',
+  '-Werror=sequence-point',
+  '-Werror=shadow',
+  '-Werror=strict-prototypes',
+  '-Werror=trigraphs',
+  '-Werror=undef',
+  '-Werror=write-strings',
+  '-Wformat-nonliteral',
+  '-Wignored-qualifiers',
+  '-Wimplicit-function-declaration',
+  '-Wlogical-op',
+  '-Wmissing-declarations',
+  '-Wmissing-format-attribute',
+  '-Wmissing-include-dirs',
+  '-Wmissing-noreturn',
+  '-Wnested-externs',
+  '-Wno-cast-function-type',
+  '-Wno-dangling-pointer',
+  '-Wno-missing-field-initializers',
+  '-Wno-sign-compare',
+  '-Wno-unused-parameter',
+  '-Wold-style-definition',
+  '-Wpointer-arith',
+  '-Wredundant-decls',
+  '-Wstrict-prototypes',
+  '-Wswitch-default',
+  '-Wswitch-enum',
+  '-Wundef',
+  '-Wuninitialized',
+  '-Wunused',
+  '-fno-strict-aliasing',
+  ['-Werror=format-security', '-Werror=format=2' ],
+]
+if get_option('buildtype') != 'plain'
+  test_c_args += '-fstack-protector-strong'
+endif
+
+foreach arg: test_c_args
+  if cc.has_multi_arguments(arg)
+    project_c_args += arg
+  endif
+endforeach
+
+add_project_arguments(project_c_args, language: 'c')
+{{end}}
 {{if language == "rust"}}
 cargo_sources = files(
   'Cargo.toml',


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