[tepl/master.msvc: 1/7] meson: Check for Visual Studio-specific warning items



commit ebb58c8c564bb81a34f18c1e734be968c68255d1
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Tue Apr 28 16:06:08 2020 +0800

    meson: Check for Visual Studio-specific warning items
    
    We want to force-include msvc_recommended_pragmas.h that is shipped with
    Windows builds of GLib so that we can filter out warnings that we don't
    really need to care much about, but also let the ones that we should be
    wary of stand (error) out.
    
    Also use the -utf-8 compiler flag if it is available, as it avoids
    unicode handling issues when attempting to build on East Asian locales.

 meson.build | 102 +++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 59 insertions(+), 43 deletions(-)
---
diff --git a/meson.build b/meson.build
index 4750e0a..685c485 100644
--- a/meson.build
+++ b/meson.build
@@ -1,4 +1,5 @@
 # Convention:
+# Convention:
 # - Local variables in lower_case.
 # - Global variables in UPPER_CASE.
 # See: https://github.com/mesonbuild/meson/issues/2607
@@ -78,50 +79,65 @@ add_project_arguments(
 # even at the maximum level.
 # The following warning_cflags suppose that warning_level=2.
 
-warning_cflags = [
-  '-fno-strict-aliasing',
-  '-Wundef',
-  '-Wnested-externs',
-  '-Wwrite-strings',
-  '-Wpointer-arith',
-  '-Wmissing-declarations',
-  '-Wmissing-prototypes',
-  '-Wstrict-prototypes',
-  '-Wredundant-decls',
-  '-Wno-unused-parameter',
-  '-Wno-missing-field-initializers',
-  '-Wdeclaration-after-statement',
-  '-Wformat=2',
-  '-Wold-style-definition',
-  '-Wcast-align',
-  '-Wformat-nonliteral',
-  '-Wformat-security',
-  '-Wsign-compare',
-  '-Wstrict-aliasing',
-  '-Wshadow',
-  '-Winline',
-  '-Wpacked',
-  '-Wmissing-format-attribute',
-  '-Wmissing-noreturn',
-  '-Winit-self',
-  '-Wredundant-decls',
-  '-Wmissing-include-dirs',
-  '-Wunused-but-set-variable',
-  '-Warray-bounds',
-  '-Wimplicit-function-declaration',
-  '-Wreturn-type',
-  '-Wswitch-enum',
-  '-Wswitch-default',
-  '-Wduplicated-cond',
-  '-Wduplicated-branches',
-  '-Wlogical-op',
-  '-Wrestrict',
-  '-Wnull-dereference',
-  '-Wjump-misses-init',
-  '-Wdouble-promotion'
-]
-
 c_compiler = meson.get_compiler('c')
+
+warning_cflags = []
+
+if c_compiler.get_id() == 'msvc'
+  # Use GLib's msvc_recommended_pragmas.h to filter out
+  # the warnings we don't really need to worry about,
+  # but do make the ones we want to be wary stand out
+  warning_cflags += [
+    '-FImsvc_recommended_pragmas.h',
+    '-utf-8', # Available in Visual Studio 2015 or later,
+              # to prevent unicode handling issues in the
+              # compiler
+  ]
+else
+  warning_cflags += [
+    '-fno-strict-aliasing',
+    '-Wundef',
+    '-Wnested-externs',
+    '-Wwrite-strings',
+    '-Wpointer-arith',
+    '-Wmissing-declarations',
+    '-Wmissing-prototypes',
+    '-Wstrict-prototypes',
+    '-Wredundant-decls',
+    '-Wno-unused-parameter',
+    '-Wno-missing-field-initializers',
+    '-Wdeclaration-after-statement',
+    '-Wformat=2',
+    '-Wold-style-definition',
+    '-Wcast-align',
+    '-Wformat-nonliteral',
+    '-Wformat-security',
+    '-Wsign-compare',
+    '-Wstrict-aliasing',
+    '-Wshadow',
+    '-Winline',
+    '-Wpacked',
+    '-Wmissing-format-attribute',
+    '-Wmissing-noreturn',
+    '-Winit-self',
+    '-Wredundant-decls',
+    '-Wmissing-include-dirs',
+    '-Wunused-but-set-variable',
+    '-Warray-bounds',
+    '-Wimplicit-function-declaration',
+    '-Wreturn-type',
+    '-Wswitch-enum',
+    '-Wswitch-default',
+    '-Wduplicated-cond',
+    '-Wduplicated-branches',
+    '-Wlogical-op',
+    '-Wrestrict',
+    '-Wnull-dereference',
+    '-Wjump-misses-init',
+    '-Wdouble-promotion'
+  ]
+endif
+
 supported_warning_cflags = c_compiler.get_supported_arguments(warning_cflags)
 add_project_arguments(supported_warning_cflags, language: 'c')
 ##### end CFLAGS


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