diff --git a/meson.build b/meson.build
index d400fe01eb1891ccdb8229a6477cc950522106a1..3ba6d070444220d2eff9781c6afa49b2ff496b1f 100644
--- a/meson.build
+++ b/meson.build
@@ -38,6 +38,74 @@ if version == 'auto'
   version = git_version_gen.stdout().strip()
 endif
 
+
+warning_cflags = [
+    '-Wall',
+    '-Wextra',
+    '-Warray-bounds',
+    '-Wcast-align',
+    '-Wdeclaration-after-statement',
+    '-Wdouble-promotion',
+    '-Wduplicated-branches',
+    '-Wduplicated-cond',
+    '-Wformat-nonliteral',
+    '-Wformat-security',
+    '-Wformat=2',
+    '-Wimplicit-function-declaration',
+    '-Winit-self',
+    '-Winline',
+    '-Wjump-misses-init',
+    '-Wlogical-op',
+    '-Wmissing-declarations',
+    '-Wmissing-format-attribute',
+    '-Wmissing-include-dirs',
+    '-Wmissing-noreturn',
+    '-Wmissing-prototypes',
+    '-Wnested-externs',
+    '-Wnull-dereference',
+    '-Wold-style-definition',
+    '-Wpacked',
+    '-Wpointer-arith',
+    '-Wredundant-decls',
+    '-Wrestrict',
+    '-Wreturn-type',
+    '-Wshadow',
+    '-Wstrict-aliasing',
+    '-Wstrict-prototypes',
+    '-Wswitch-default',
+    '-Wswitch-enum',
+    '-Wundef',
+    '-Wunused-but-set-variable',
+    '-Wwrite-strings',
+]
+no_warning_cflags = [
+    'declaration-after-statement',
+    'missing-field-initializers',
+    'sign-compare',
+    'unused-parameter',
+]
+# This trips some warnings in the libglnx subproject but not in
+# pressure-vessel itself
+project_warning_cflags = [
+    '-Wsign-compare',
+]
+
+
+c_compiler = meson.get_compiler('c')
+supported_warning_cflags = c_compiler.get_supported_arguments(warning_cflags)
+add_global_arguments(supported_warning_cflags, language : 'c')
+
+foreach flag : no_warning_cflags
+  supported_no_warning_cflags = c_compiler.get_supported_arguments([
+    '-Wno-error=' + flag,
+    '-Wno-' + flag,
+  ])
+  add_global_arguments(supported_no_warning_cflags, language : 'c')
+endforeach
+
+supported_warning_cflags = c_compiler.get_supported_arguments(project_warning_cflags)
+add_project_arguments(supported_warning_cflags, language : 'c')
+
 scripts = [
   'pressure-vessel-wrap.sh',
   'pressure-vessel-test-ui',
diff --git a/src/wrap.c b/src/wrap.c
index 1789185209dea365f09dec264d82759e0c4475ae..604b412b6356e6d27ba4d5597c069060612d9af4 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -364,7 +364,7 @@ write_xauth (char *number, FILE *output)
           local_xa = *xa;
           if (local_xa.number)
             {
-              local_xa.number = "99";
+              local_xa.number = (char *) "99";
               local_xa.number_length = 2;
             }
 
@@ -684,7 +684,6 @@ flatpak_run_add_session_dbus_args (FlatpakBwrap   *app_bwrap)
     }
   else
     {
-      g_autofree char *user_runtime_dir = flatpak_get_real_xdg_runtime_dir ();
       struct stat statbuf;
 
       dbus_session_socket = g_build_filename (user_runtime_dir, "bus", NULL);