summary refs log tree commit diff stats
path: root/meson.build
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2017-06-26 16:38:03 -0400
committerPatrick Griffis <tingping@tingping.se>2017-06-26 16:38:03 -0400
commite68976ab397606c991d54f437a268d2e07196789 (patch)
treed7e64ea8d8d42babedea60df5e857c6d3f38c3d1 /meson.build
parent806a0da2584659a69c35112c86a5700a855be665 (diff)
build: More robust compiler flag checks
Don't hardcode platforms but check if things actually link.

This should fix cygwin.
Diffstat (limited to 'meson.build')
-rw-r--r--meson.build39
1 files changed, 23 insertions, 16 deletions
diff --git a/meson.build b/meson.build
index 15eaa390..dbdaee9e 100644
--- a/meson.build
+++ b/meson.build
@@ -98,29 +98,36 @@ test_cflags = [
   '-Werror=missing-include-dirs',
   '-Werror=date-time',
 ]
-if host_machine.system() != 'windows' and get_option('buildtype') != 'plain'
-  test_cflags += '-fstack-protector-strong'
-endif
 foreach cflag : test_cflags
   if cc.has_multi_arguments(cflag)
     global_cflags += cflag
   endif
 endforeach
+if get_option('buildtype') != 'plain'
+  if cc.has_argument('-fstack-protector-strong') and cc.links('''
+     int main (void) {
+       char buffer[16];
+       strcpy(buffer, "foo");
+       return 0;
+     }
+     ''', args: '-fstack-protector-all')
+    global_cflags += '-fstack-protector-strong'
+  endif
+endif
 add_project_arguments(global_cflags, language: 'c')
 
-if host_machine.system() != 'windows'
-  global_ldflags = []
-  test_ldflags = [
-    '-Wl,-z,relro',
-    '-Wl,-z,now',
-  ]
-  foreach ldflag : test_ldflags
-    if cc.has_argument(ldflag)
-      global_ldflags += ldflag
-    endif
-  endforeach
-  add_project_link_arguments(global_ldflags, language: 'c')
-endif
+
+global_ldflags = []
+test_ldflags = [
+  '-Wl,-z,relro',
+  '-Wl,-z,now',
+]
+foreach ldflag : test_ldflags
+  if cc.has_argument(ldflag) and cc.links('int main (void) { return 0; }', args: ldflag)
+    global_ldflags += ldflag
+  endif
+endforeach
+add_project_link_arguments(global_ldflags, language: 'c')
 
 subdir('src')
 if get_option('with-plugin')