[cairo-commit] 2 commits - meson.build meson-cc-tests/check-unused-result.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Aug 14 07:24:43 UTC 2021


 meson-cc-tests/check-unused-result.c |    9 +++++
 meson.build                          |   55 +++++++++++++++++++++++++++++++++--
 2 files changed, 62 insertions(+), 2 deletions(-)

New commits:
commit 48d606114905dba86d165fd6824f3f0ff73e5120
Merge: 87cf0fc28 ebac15cb0
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Aug 14 07:24:41 2021 +0000

    Merge branch 'meson-warnings' into 'master'
    
    copy all autotools compiler warnings to meson build
    
    See merge request cairo/cairo!215

commit ebac15cb047bfc82d359a679d4bc53a37028ad6a
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Aug 14 07:24:40 2021 +0000

    copy all autotools compiler warnings to meson build

diff --git a/meson-cc-tests/check-unused-result.c b/meson-cc-tests/check-unused-result.c
new file mode 100644
index 000000000..ce7279ec8
--- /dev/null
+++ b/meson-cc-tests/check-unused-result.c
@@ -0,0 +1,9 @@
+__attribute__((__warn_unused_result__)) void f (void) {}
+__attribute__((__warn_unused_result__)) int g;
+
+int main(int c, char **v)
+{
+    (void)c;
+    (void)v;
+    return 0;
+}
diff --git a/meson.build b/meson.build
index ca9d72825..ce7449ffb 100644
--- a/meson.build
+++ b/meson.build
@@ -33,8 +33,61 @@ else
   cairo_libversion = '@0 at .@1 at .@2@'.format(cairo_version_sonum, cairo_version, cairo_version_micro)
 endif
 
+conf = configuration_data()
+
 cc = meson.get_compiler('c')
 
+# Compiler flags
+cflags = []
+if cc.get_id() != 'msvc'
+  cflags += [
+    '-Wall',
+    '-Wextra',
+    '-Wmissing-declarations',
+    '-Werror-implicit-function-declaration',
+    '-Wpointer-arith',
+    '-Wwrite-strings',
+    '-Wsign-compare',
+    '-Wpacked',
+    '-Wswitch-enum',
+    '-Wmissing-format-attribute',
+    '-Wvolatile-register-var',
+    '-Wstrict-aliasing=2',
+    '-Winit-self',
+    '-Wunsafe-loop-optimizations',
+    '-Wno-missing-field-initializers',
+    '-Wno-unused-parameter',
+    '-Wno-attributes',
+    '-Wno-long-long',
+    '-Winline'
+  ]
+
+  cflags += ['-Wno-unused-but-set-variable',
+             '-Wno-enum-conversion'
+  ]
+
+  cflags += [
+    '-fno-strict-aliasing',
+    '-fno-common'
+  ]
+
+  cflags += '-Wp,-D_FORTIFY_SOURCE=2'
+
+  supported_cflags = cc.get_supported_arguments(cflags)
+  add_project_arguments(supported_cflags, language: 'c')
+
+  # We only wish to enable attribute(warn_unused_result) if we can prevent
+  # gcc from generating thousands of warnings about the misapplication of the
+  # attribute to void functions and variables.
+  warn_unused_result = ''
+  if supported_cflags.contains('-Wno-attributes')
+    if cc.compiles(files('meson-cc-tests/check-unused-result.c'), args : ['-Wno-attributes', '-Werror'])
+      warn_unused_result = '__attribute__((__warn_unused_result__))'
+    endif
+  endif
+  conf.set('WARN_UNUSED_RESULT', warn_unused_result)
+endif
+
 if cc.get_id() == 'msvc'
   # Basic usage in the cairo type system that causes spammy and useless warnings
   add_project_arguments('/wd4244', '/wd4146',
@@ -137,8 +190,6 @@ test_deps = []
 internal_deps = []
 extra_link_args = []
 
-conf = configuration_data()
-
 if host_machine.endian() == 'big'
   conf.set('WORDS_BIGENDIAN', 1)
 endif


More information about the cairo-commit mailing list