meson: enable more warnings

Modeled on the autotools build, -W flags are only
added if the compiler supports them.

https://bugzilla.gnome.org/show_bug.cgi?id=793958
diff --git a/gst/printf/meson.build b/gst/printf/meson.build
index 1b42d2a..57ecb61 100644
--- a/gst/printf/meson.build
+++ b/gst/printf/meson.build
@@ -18,6 +18,10 @@
 # Don't need any of this widechar stuff, so just disable it for now
 printf_args += ['-UHAVE_WCHAR_T', '-UHAVE_WCSLEN', '-UHAVE_WINT_T']
 
+if cc.has_argument('-Wno-format-nonliteral')
+  printf_args += ['-Wno-format-nonliteral']
+endif
+
 # Check if 'long long' works and what format can be used to print it
 # jm_AC_TYPE_LONG_LONG
 if cc.compiles('''long long ll = 1LL;
diff --git a/libs/gst/check/libcheck/meson.build b/libs/gst/check/libcheck/meson.build
index 8511064..17d3f01 100644
--- a/libs/gst/check/libcheck/meson.build
+++ b/libs/gst/check/libcheck/meson.build
@@ -65,11 +65,24 @@
   endif
 endif
 
+no_warn_args = []
+foreach arg : [
+  '-Wno-undef',
+  '-Wno-redundant-decls',
+  '-Wno-missing-prototypes',
+  '-Wno-missing-declarations',
+  '-Wno-old-style-definition',
+  '-Wno-declaration-after-statement']
+  if cc.has_argument(arg)
+    no_warn_args += [arg]
+  endif
+endforeach
+
 libcheck = static_library('check',
   libcheck_files,
   include_directories : [configinc, internal_check_h_inc],
   dependencies : [rt_lib, mathlib],
-  c_args: gst_c_args + libcheck_visibility_args +
+  c_args: gst_c_args + libcheck_visibility_args + no_warn_args +
 	  # Don't want libcompat to think we don't have these and substitute
 	  # replacements since we don't check for or define these. See libcompat.h
 	  ['-DHAVE_VSNPRINTF', '-DHAVE_SNPRINTF', '-DHAVE_MALLOC', '-DHAVE_REALLOC'],
diff --git a/meson.build b/meson.build
index 60a0a5d..7aa45de 100644
--- a/meson.build
+++ b/meson.build
@@ -45,7 +45,6 @@
 elif cc.has_argument('-Wl,-Bsymbolic-functions')
   # FIXME: Add an option for this if people ask for it
   add_project_link_arguments('-Wl,-Bsymbolic-functions', language : 'c')
-  # FIXME: Add FATAL_WARNINGS from configure.ac
 endif
 
 # Symbol visibility
@@ -339,6 +338,32 @@
   add_project_arguments(['-Wno-unused'], language: 'c')
 endif
 
+warning_flags = [
+  '-Wmissing-declarations',
+  '-Wmissing-prototypes',
+  '-Wredundant-decls',
+  '-Wundef',
+  '-Wwrite-strings',
+  '-Wformat-nonliteral',
+  '-Wformat-security',
+  '-Wold-style-definition',
+  '-Winit-self',
+  '-Wmissing-include-dirs',
+  '-Waddress',
+  '-Waggregate-return',
+  '-Wno-multichar',
+  '-Wnested-externs',
+  '-Wdeclaration-after-statement',
+  '-Wvla',
+  '-Wpointer-arith',
+]
+
+foreach extra_arg : warning_flags
+  if cc.has_argument (extra_arg)
+    add_project_arguments([extra_arg], language: 'c')
+  endif
+endforeach
+
 # Used by the gstutils test
 gmp_dep = cc.find_library('gmp', required : false)
 cdata.set('HAVE_GMP', gmp_dep.found())