Pass _GNU_SOURCE as compiler argument
authorNikolaus Rath <Nikolaus@rath.org>
Mon, 23 Jan 2017 20:06:25 +0000 (12:06 -0800)
committerNikolaus Rath <Nikolaus@rath.org>
Mon, 23 Jan 2017 20:06:25 +0000 (12:06 -0800)
Defining it in the file causes trouble because Meson sometimes
inserts includes before the first line.

meson.build

index 0cce4af71486f1d5239f50d839cdc040ddd827d8..a1e9b80da27b640b02de8e78a6d1731b89673de9 100644 (file)
@@ -13,7 +13,6 @@ cc = meson.get_compiler('c')
 # Default includes when checking for presence of functions and
 # struct members
 include_default = '
-#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
@@ -22,6 +21,7 @@ include_default = '
 #include <sys/stat.h>
 #include <fcntl.h>
 '
+args_default = [ '-D_GNU_SOURCE' ]
 
 cfg.set_quoted('PACKAGE_VERSION', meson.project_version())
 
@@ -31,7 +31,7 @@ test_funcs = [ 'fork', 'fstatat', 'openat', 'readlinkat', 'pipe2',
                'utimensat' ]
 foreach func : test_funcs
     cfg.set('HAVE_' + func.to_upper(),
-        cc.has_function(func, prefix: include_default))
+        cc.has_function(func, prefix: include_default, args: args_default))
 endforeach
 cfg.set('HAVE_SETXATTR', 
         cc.has_function('setxattr', prefix: '#include <sys/xattr.h>'))
@@ -41,16 +41,17 @@ cfg.set('HAVE_ICONV',
 # Test if structs have specific member
 cfg.set('HAVE_STRUCT_STAT_ST_ATIM',
          cc.has_member('struct stat', 'st_atim',
-                       prefix: include_default))
+                       prefix: include_default,
+                       args: args_default))
 cfg.set('HAVE_STRUCT_STAT_ST_ATIMESPEC',
          cc.has_member('struct stat', 'st_atimespec',
-                       prefix: include_default))
+                       prefix: include_default,
+                       args: args_default))
 
 # Write the test results into config.h (stored in build directory)
 configure_file(output: 'config.h',
                configuration : cfg)
 
-
 #
 # Compiler configuration
 #