From e68976ab397606c991d54f437a268d2e07196789 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Mon, 26 Jun 2017 16:38:03 -0400 Subject: build: More robust compiler flag checks Don't hardcode platforms but check if things actually link. This should fix cygwin. --- meson.build | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'meson.build') 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') -- cgit 1.4.1