Merge branch '1044-prlimit-fix' into 'master'
[glib.git] / meson.build
blobfa7357d4021736bec9800d74af77ef3daaef42c8
1 project('glib', 'c', 'cpp',
2   version : '2.57.1',
3   meson_version : '>= 0.47.0',
4   default_options : [
5     'buildtype=debugoptimized',
6     'warning_level=1',
7     'c_std=gnu89'
8   ]
11 cc = meson.get_compiler('c')
12 cxx = meson.get_compiler('cpp')
14 cc_can_run = not meson.is_cross_build() or meson.has_exe_wrapper()
16 if cc.get_id() == 'msvc'
17   # Ignore several spurious warnings for things glib does very commonly
18   # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
19   # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
20   # NOTE: Only add warnings here if you are sure they're spurious
21   add_project_arguments('/wd4035', '/wd4715', '/wd4116',
22     '/wd4046', '/wd4068', '/wo4090', '/FImsvc_recommended_pragmas.h',language : 'c')
23   # Disable SAFESEH with MSVC for plugins and libs that use external deps that
24   # are built with MinGW
25   noseh_link_args = ['/SAFESEH:NO']
26   # Set the input and exec encoding to utf-8, like is the default with GCC
27   add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c')
28 else
29   noseh_link_args = []
30   # -mms-bitfields vs -fnative-struct ?
31 endif
33 host_system = host_machine.system()
35 glib_version = meson.project_version()
36 glib_api_version = '2.0'
37 version_arr = glib_version.split('.')
38 major_version = version_arr[0].to_int()
39 minor_version = version_arr[1].to_int()
40 micro_version = version_arr[2].to_int()
42 interface_age = minor_version.is_odd() ? 0 : micro_version
43 binary_age = 100 * minor_version + micro_version
45 soversion = 0
46 # Maintain compatibility with previous libtool versioning
47 # current = minor * 100 + micro
48 library_version = '@0@.@1@.@2@'.format(soversion, binary_age - interface_age, interface_age)
50 configinc = include_directories('.')
51 glibinc = include_directories('glib')
52 gobjectinc = include_directories('gobject')
53 gmoduleinc = include_directories('gmodule')
54 gioinc = include_directories('gio')
56 glib_prefix = get_option('prefix')
57 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
58 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
59 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
60 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
61 glib_includedir = join_paths(glib_prefix, get_option('includedir'))
62 glib_giomodulesdir = get_option('gio_module_dir')
63 if glib_giomodulesdir == ''
64   glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
65 endif
67 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
69 add_project_arguments('-D_GNU_SOURCE', language: 'c')
71 # Disable strict aliasing;
72 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
73 if cc.has_argument('-fno-strict-aliasing')
74   add_project_arguments('-fno-strict-aliasing', language: 'c')
75 endif
77 ########################
78 # Configuration begins #
79 ########################
80 glib_conf = configuration_data()
81 glibconfig_conf = configuration_data()
83 # accumulated list of defines as we check for them, so we can easily
84 # use them later in test programs (autoconf does this automatically)
85 glib_conf_prefix = ''
87 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
88 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
89 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
90 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
91 glib_conf.set('GLIB_BINARY_AGE', binary_age)
92 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
93 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
94 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
95 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
96 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
97 glib_conf.set_quoted('PACKAGE_URL', '')
98 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
99 glib_conf.set('ENABLE_NLS', 1)
101 # used by the .rc.in files
102 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
104 glib_conf.set('_GNU_SOURCE', 1)
106 if host_system == 'windows'
107   # Poll doesn't work on devices on Windows
108   glib_conf.set('BROKEN_POLL', true)
109 endif
111 # Check for GNU visibility attributes
112 g_have_gnuc_visibility = cc.compiles('''
113   void
114   __attribute__ ((visibility ("hidden")))
115        f_hidden (void)
116   {
117   }
118   void
119   __attribute__ ((visibility ("internal")))
120        f_internal (void)
121   {
122   }
123   void
124   __attribute__ ((visibility ("protected")))
125        f_protected (void)
126   {
127   }
128   void
129   __attribute__ ((visibility ("default")))
130        f_default (void)
131   {
132   }
133   int main (void)
134   {
135     f_hidden();
136     f_internal();
137     f_protected();
138     f_default();
139     return 0;
140   }
141   ''',
142   # Not supported by MSVC, but MSVC also won't support visibility,
143   # so it's OK to pass -Werror explicitly. Replace with
144   # override_options : 'werror=true' once that is supported
145   args: ['-Werror'],
146   name : 'GNU C visibility attributes test')
148 if g_have_gnuc_visibility
149   glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
150 endif
152 # Detect and set symbol visibility
153 glib_hidden_visibility_args = []
154 if get_option('default_library') != 'static'
155   if host_system == 'windows'
156     glib_conf.set('DLL_EXPORT', true)
157     if cc.get_id() == 'msvc'
158       glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
159     elif cc.has_argument('-fvisibility=hidden')
160       glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
161       glib_hidden_visibility_args = ['-fvisibility=hidden']
162     endif
163   elif cc.has_argument('-fvisibility=hidden')
164     glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
165     glib_hidden_visibility_args = ['-fvisibility=hidden']
166   endif
167 endif
169 if host_system == 'windows' and get_option('default_library') == 'static'
170     glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
171     glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
172 endif
174 # FIXME: what about Cygwin (G_WITH_CYGWIN)
175 if host_system == 'windows'
176   glib_os = '''#define G_OS_WIN32
177 #define G_PLATFORM_WIN32'''
178 else
179   glib_os = '#define G_OS_UNIX'
180 endif
181 glibconfig_conf.set('glib_os', glib_os)
183 # We need to know the build type to determine what .lib files we need on Visual Studio
184 # for dependencies that don't normally come with pkg-config files for Visual Studio builds
185 buildtype = get_option('buildtype')
187 glib_debug_cflags = []
188 if buildtype.startswith('debug')
189   glib_debug_cflags += ['-DG_ENABLE_DEBUG']
190 elif buildtype == 'release'
191   glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
192 endif
194 add_project_arguments(glib_debug_cflags, language: 'c')
196 # check for header files
198 headers = [
199   'alloca.h',
200   'crt_externs.h',
201   'dirent.h', # MSC does not come with this by default
202   'float.h',
203   'fstab.h',
204   'grp.h',
205   'inttypes.h',
206   'limits.h',
207   'linux/magic.h',
208   'locale.h',
209   'mach/mach_time.h',
210   'memory.h',
211   'mntent.h',
212   'poll.h',
213   'pwd.h',
214   'sched.h',
215   'stdint.h',
216   'stdlib.h',
217   'string.h',
218   'strings.h',
219   'sys/auxv.h',
220   'sys/event.h',
221   'sys/filio.h',
222   'sys/inotify.h',
223   'sys/mkdev.h',
224   'sys/mntctl.h',
225   'sys/mnttab.h',
226   'sys/mount.h',
227   'sys/param.h',
228   'sys/resource.h',
229   'sys/select.h',
230   'sys/statfs.h',
231   'sys/stat.h',
232   'sys/statvfs.h',
233   'sys/sysctl.h',
234   'sys/time.h', # MSC does not come with this by default
235   'sys/times.h',
236   'sys/types.h',
237   'sys/uio.h',
238   'sys/vfs.h',
239   'sys/vfstab.h',
240   'sys/vmount.h',
241   'sys/wait.h',
242   'termios.h',
243   'unistd.h',
244   'values.h',
245   'xlocale.h',
248 foreach h : headers
249   if cc.has_header(h)
250     define = 'HAVE_' + h.underscorify().to_upper()
251     glib_conf.set(define, 1)
252     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
253   endif
254 endforeach
256 # FIXME: Use cc.check_header from Meson 0.47.
257 # FreeBSD includes a malloc.h which always throw compilation error.
258 if cc.compiles('#include <malloc.h>', name : 'malloc.h')
259   glib_conf.set('HAVE_MALLOC_H', 1)
260   glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
261 endif
263 if cc.has_header('linux/netlink.h')
264   glib_conf.set('HAVE_NETLINK', 1)
265 endif
267 if glib_conf.has('HAVE_LOCALE_H')
268   if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
269     glib_conf.set('HAVE_LC_MESSAGES', 1)
270   endif
271 endif
273 struct_stat_blkprefix = '''
274 #include <sys/types.h>
275 #include <sys/stat.h>
276 #ifdef HAVE_UNISTD_H
277 #include <unistd.h>
278 #endif
279 #ifdef HAVE_SYS_STATFS_H
280 #include <sys/statfs.h>
281 #endif
282 #ifdef HAVE_SYS_PARAM_H
283 #include <sys/param.h>
284 #endif
285 #ifdef HAVE_SYS_MOUNT_H
286 #include <sys/mount.h>
287 #endif
290 struct_members = [
291   [ 'stat', 'st_mtimensec' ],
292   [ 'stat', 'st_mtim.tv_nsec' ],
293   [ 'stat', 'st_atimensec' ],
294   [ 'stat', 'st_atim.tv_nsec' ],
295   [ 'stat', 'st_ctimensec' ],
296   [ 'stat', 'st_ctim.tv_nsec' ],
297   [ 'stat', 'st_birthtime' ],
298   [ 'stat', 'st_birthtimensec' ],
299   [ 'stat', 'st_birthtim' ],
300   [ 'stat', 'st_birthtim.tv_nsec' ],
301   [ 'stat', 'st_blksize', struct_stat_blkprefix ],
302   [ 'stat', 'st_blocks', struct_stat_blkprefix ],
303   [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
304   [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
305   [ 'dirent', 'd_type', '''#include <sys/types.h>
306                            #include <dirent.h>''' ],
307   [ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
308   [ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
309   [ 'tm', 'tm_gmtoff', '#include <time.h>' ],
310   [ 'tm', '__tm_gmtoff', '#include <time.h>' ],
313 foreach m : struct_members
314   header_check_prefix = glib_conf_prefix
315   if m.length() == 3
316     header_check_prefix = header_check_prefix + m[2]
317   else
318     header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
319   endif
320   if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
321     define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
322     glib_conf.set(define, 1)
323     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
324   else
325   endif
326 endforeach
328 # Compiler flags
329 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
330   test_c_args = [
331     '-Wall',
332     '-Wduplicated-branches',
333     '-Wmisleading-indentation',
334     '-Wstrict-prototypes',
335     '-Wunused',
336     # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
337     # building with -Wbad-function-cast.
338     '-Wno-bad-function-cast',
339     '-Werror=declaration-after-statement',
340     '-Werror=format=2',
341     '-Werror=format-security',
342     '-Werror=implicit-function-declaration',
343     '-Werror=init-self',
344     '-Werror=missing-include-dirs',
345     '-Werror=missing-prototypes',
346     '-Werror=pointer-arith',
347   ]
348   test_c_link_args = [
349     '-Wl,-z,nodelete',
350   ]
351   if get_option('bsymbolic_functions')
352     test_c_link_args += ['-Wl,-Bsymbolic-functions']
353   endif
354 else
355   test_c_args = []
356   test_c_link_args = []
357 endif
359 add_project_arguments(cc.get_supported_arguments(test_c_args), language: 'c')
361 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
362 # means we cannot use that flag in add_project_link_arguments(), and must add
363 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
364 # because that is what the autotools build did.
365 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
366 # improve this.
367 glib_link_flags = cc.get_supported_link_arguments(test_c_link_args)
369 # Windows Support (7+)
370 if host_system == 'windows'
371   glib_conf.set('_WIN32_WINNT', '0x0601')
372 endif
374 functions = [
375   'alloca',
376   'endmntent',
377   'endservent',
378   'fallocate',
379   'fchmod',
380   'fchown',
381   'fdwalk',
382   'fsync',
383   'getc_unlocked',
384   'getfsstat',
385   'getgrgid_r',
386   'getmntent_r',
387   'getpwuid_r',
388   'getresuid',
389   'getvfsstat',
390   'gmtime_r',
391   'hasmntopt',
392   'inotify_init1',
393   'issetugid',
394   'kevent',
395   'kqueue',
396   'lchmod',
397   'lchown',
398   'link',
399   'localtime_r',
400   'lstat',
401   'mbrtowc',
402   'memalign',
403   'mmap',
404   'newlocale',
405   'pipe2',
406   'poll',
407   'prlimit',
408   'readlink',
409   'recvmmsg',
410   'sendmmsg',
411   'setenv',
412   'setmntent',
413   'strerror_r',
414   'strnlen',
415   'strsignal',
416   'strtod_l',
417   'strtoll_l',
418   'strtoull_l',
419   'symlink',
420   'timegm',
421   'unsetenv',
422   'uselocale',
423   'utimes',
424   'valloc',
425   'vasprintf',
426   'vsnprintf',
427   'wcrtomb',
428   'wcslen',
429   'wcsnlen',
430   'sysctlbyname',
431   '_NSGetEnviron',
434 if glib_conf.has('HAVE_SYS_STATVFS_H')
435   functions += ['statvfs']
436 else
437   have_func_statvfs = false
438 endif
439 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
440   functions += ['statfs']
441 else
442   have_func_statfs = false
443 endif
445 if host_system == 'windows'
446   iphlpapi_dep = cc.find_library('iphlpapi')
447   iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
448   foreach ifunc : iphlpapi_funcs
449     iphl_prefix =  '''#define _WIN32_WINNT @0@
450       #include <winsock2.h>
451       #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
452     if cc.has_function(ifunc,
453                        prefix : iphl_prefix,
454                        dependencies : iphlpapi_dep)
455       idefine = 'HAVE_' + ifunc.underscorify().to_upper()
456       glib_conf.set(idefine, 1)
457       glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
458       set_variable('have_func_' + ifunc, true)
459     else
460       set_variable('have_func_' + ifunc, false)
461     endif
462   endforeach
463 else
464   functions += ['if_indextoname', 'if_nametoindex']
465 endif
467 # AIX splice is something else
468 if host_system != 'aix'
469   functions += ['splice']
470 endif
472 foreach f : functions
473   if cc.has_function(f)
474     define = 'HAVE_' + f.underscorify().to_upper()
475     glib_conf.set(define, 1)
476     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
477     set_variable('have_func_' + f, true)
478   else
479     set_variable('have_func_' + f, false)
480   endif
481 endforeach
483 # Check that stpcpy() is usable; must use header
484 if cc.has_function('stpcpy', prefix : '#include <string.h>')
485   glib_conf.set('HAVE_STPCPY', 1)
486 endif
488 # Check that posix_memalign() is usable; must use header
489 if cc.has_function('posix_memalign', prefix : '#include <stdlib.h>')
490   glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
491 endif
493 # Check that posix_spawn() is usable; must use header
494 if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
495   glib_conf.set('HAVE_POSIX_SPAWN', 1)
496 endif
498 # Check whether strerror_r returns char *
499 if have_func_strerror_r
500   if cc.compiles('''#define _GNU_SOURCE
501                     #include <string.h>
502                     int func (void) {
503                       char error_string[256];
504                       char *ptr = strerror_r (-2, error_string, 256);
505                       char c = *strerror_r (-2, error_string, 256);
506                       return c != 0 && ptr != (void*) 0L;
507                     }
508                  ''',
509                  name : 'strerror_r() returns char *')
510     glib_conf.set('STRERROR_R_CHAR_P', 1,
511                   description: 'Defined if strerror_r returns char *')
512   endif
513 endif
515 # Special-case these functions that have alternative names on Windows/MSVC
516 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
517   glib_conf.set('HAVE_SNPRINTF', 1)
518   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
519 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
520   hack_define = '1\n#define snprintf _snprintf'
521   glib_conf.set('HAVE_SNPRINTF', hack_define)
522   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
523 endif
525 if cc.has_function('strcasecmp')
526   glib_conf.set('HAVE_STRCASECMP', 1)
527   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
528 elif cc.has_function('_stricmp')
529   hack_define = '1\n#define strcasecmp _stricmp'
530   glib_conf.set('HAVE_STRCASECMP', hack_define)
531   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
532 endif
534 if cc.has_function('strncasecmp')
535   glib_conf.set('HAVE_STRNCASECMP', 1)
536   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
537 elif cc.has_function('_strnicmp')
538   hack_define = '1\n#define strncasecmp _strnicmp'
539   glib_conf.set('HAVE_STRNCASECMP', hack_define)
540   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
541 endif
543 if cc.has_header_symbol('sys/sysmacros.h', 'major')
544   glib_conf.set('MAJOR_IN_SYSMACROS', 1)
545 elif cc.has_header_symbol('sys/mkdev.h', 'major')
546   glib_conf.set('MAJOR_IN_MKDEV', 1)
547 elif cc.has_header_symbol('sys/types.h', 'major')
548   glib_conf.set('MAJOR_IN_TYPES', 1)
549 endif
551 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
552   glib_conf.set('HAVE_RTLD_LAZY', 1)
553 endif
555 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
556   glib_conf.set('HAVE_RTLD_NOW', 1)
557 endif
559 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
560   glib_conf.set('HAVE_RTLD_GLOBAL', 1)
561 endif
563 # Check whether to use statfs or statvfs
564 # Some systems have both statfs and statvfs, pick the most "native" for these
565 if have_func_statfs and have_func_statvfs
566   # on solaris and irix, statfs doesn't even have the f_bavail field
567   if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
568     have_func_statfs = false
569   else
570     # at least on linux, statfs is the actual syscall
571     have_func_statvfs = false
572   endif
573 endif
574 if have_func_statfs
575   glib_conf.set('USE_STATFS', 1)
576   stat_func_to_use = 'statfs'
577 elif have_func_statvfs
578   glib_conf.set('USE_STATVFS', 1)
579   stat_func_to_use = 'statvfs'
580 else
581   stat_func_to_use = 'neither'
582 endif
583 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
585 if host_system == 'linux'
586   if cc.has_function('mkostemp',
587                      prefix: '''#define _GNU_SOURCE
588                                 #include <stdlib.h>''')
589     glib_conf.set('HAVE_MKOSTEMP', 1)
590   endif
591 endif
593 osx_ldflags = []
594 glib_have_os_x_9_or_later = false
595 glib_have_carbon = false
596 glib_have_cocoa = false
597 if host_system == 'darwin'
598   add_languages('objc')
599   objcc = meson.get_compiler('objc')
601   osx_ldflags += ['-Wl,-framework,CoreFoundation']
603   # Mac OS X Carbon support
604   glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
605                                        #include <CoreServices/CoreServices.h>''',
606                                     name : 'Mac OS X Carbon support')
608   if glib_have_carbon
609     glib_conf.set('HAVE_CARBON', true)
610     osx_ldflags += '-Wl,-framework,Carbon'
611     glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
612                                                   #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
613                                                   #error Compiling for minimum OS X version before 10.9
614                                                   #endif''',
615                                                name : 'OS X 9 or later')
616   endif
618   # Mac OS X Cocoa support
619   glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
620                                       #ifdef GNUSTEP_BASE_VERSION
621                                       #error "Detected GNUstep, not Cocoa"
622                                       #endif''',
623                                    name : 'Mac OS X Cocoa support')
625   if glib_have_cocoa
626     glib_conf.set('HAVE_COCOA', true)
627     osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
628   endif
630   # FIXME: libgio mix C and objC source files and there is no way to reliably
631   # know which language flags it's going to use to link. Add to both languages
632   # for now. See https://github.com/mesonbuild/meson/issues/3585.
633   add_project_link_arguments(osx_ldflags, language : ['objc', 'c'])
634 endif
636 # Check for futex(2)
637 if cc.links('''#include <linux/futex.h>
638                #include <sys/syscall.h>
639                #include <unistd.h>
640                int main (int argc, char ** argv) {
641                  syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
642                  return 0;
643                }''', name : 'futex(2) system call')
644   glib_conf.set('HAVE_FUTEX', 1)
645 endif
647 # Check for eventfd(2)
648 if cc.links('''#include <sys/eventfd.h>
649                #include <unistd.h>
650                int main (int argc, char ** argv) {
651                  eventfd (0, EFD_CLOEXEC);
652                  return 0;
653                }''', name : 'eventfd(2) system call')
654   glib_conf.set('HAVE_EVENTFD', 1)
655 endif
657 clock_gettime_test_code = '''
658   #include <time.h>
659   struct timespec t;
660   int main (int argc, char ** argv) {
661     return clock_gettime(CLOCK_REALTIME, &t);
662   }'''
663 librt = []
664 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
665   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
666 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
667   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
668   librt = cc.find_library('rt')
669 endif
671 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
672 if have_func_statfs
673   if cc.compiles(glib_conf_prefix + '''
674                  #include <unistd.h>
675                         #ifdef HAVE_SYS_PARAM_H
676                         #include <sys/param.h>
677                         #endif
678                         #ifdef HAVE_SYS_VFS_H
679                         #include <sys/vfs.h>
680                         #endif
681                         #ifdef HAVE_SYS_MOUNT_H
682                         #include <sys/mount.h>
683                         #endif
684                         #ifdef HAVE_SYS_STATFS_H
685                         #include <sys/statfs.h>
686                         #endif
687                         void some_func (void) {
688                           struct statfs st;
689                           statfs("/", &st);
690                         }''', name : 'number of arguments to statfs() (n=2)')
691     glib_conf.set('STATFS_ARGS', 2)
692   elif cc.compiles(glib_conf_prefix + '''
693                    #include <unistd.h>
694                           #ifdef HAVE_SYS_PARAM_H
695                           #include <sys/param.h>
696                           #endif
697                           #ifdef HAVE_SYS_VFS_H
698                           #include <sys/vfs.h>
699                           #endif
700                           #ifdef HAVE_SYS_MOUNT_H
701                           #include <sys/mount.h>
702                           #endif
703                           #ifdef HAVE_SYS_STATFS_H
704                           #include <sys/statfs.h>
705                           #endif
706                           void some_func (void) {
707                             struct statfs st;
708                             statfs("/", &st, sizeof (st), 0);
709                           }''', name : 'number of arguments to statfs() (n=4)')
710     glib_conf.set('STATFS_ARGS', 4)
711   else
712     error('Unable to determine number of arguments to statfs()')
713   endif
714 endif
716 # open takes O_DIRECTORY as an option
717 #AC_MSG_CHECKING([])
718 if cc.compiles('''#include <fcntl.h>
719                   #include <sys/types.h>
720                   #include <sys/stat.h>],
721                   void some_func (void) {
722                     open(0, O_DIRECTORY, 0);
723                   }''', name : 'open() option O_DIRECTORY')
724   glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
725 endif
727 # Check whether there is a vsnprintf() function with C99 semantics installed.
728 # AC_FUNC_VSNPRINTF_C99
729 # Check whether there is a snprintf() function with C99 semantics installed.
730 # AC_FUNC_SNPRINTF_C99
732 have_good_vsnprintf = false
733 have_good_snprintf = false
735 if host_system == 'windows' and cc.get_id() == 'msvc'
736   # Unfortunately the Visual Studio 2015+ implementations of C99-style
737   # snprintf and vsnprintf don't seem to be quite good enough.
738   # (Sorry, I don't know exactly what is the problem,
739   # but it is related to floating point formatting and decimal point vs. comma.)
740   # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
741   # rigorous enough to notice, though.
742   glib_conf.set('HAVE_C99_SNPRINTF', false)
743   glib_conf.set('HAVE_C99_VSNPRINTF', false)
744 else
745   vsnprintf_c99_test_code = '''
746 #include <stdio.h>
747 #include <stdarg.h>
750 doit(char * s, ...)
752   char buffer[32];
753   va_list args;
754   int r;
756   va_start(args, s);
757   r = vsnprintf(buffer, 5, s, args);
758   va_end(args);
760   if (r != 7)
761     exit(1);
763   /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
764      implementation. The above will return 7 but if you replace
765      the size of the buffer with 0, it borks! */
766   va_start(args, s);
767   r = vsnprintf(buffer, 0, s, args);
768   va_end(args);
770   if (r != 7)
771     exit(1);
773   exit(0);
777 main(void)
779   doit("1234567");
780   exit(1);
781 }'''
783   if cc_can_run
784     rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
785     if rres.compiled() and rres.returncode() == 0
786       glib_conf.set('HAVE_C99_VSNPRINTF', 1)
787       have_good_vsnprintf = true
788     endif
789   else
790       have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
791       glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
792   endif
794   snprintf_c99_test_code = '''
795 #include <stdio.h>
796 #include <stdarg.h>
799 doit()
801   char buffer[32];
802   va_list args;
803   int r;
805   r = snprintf(buffer, 5, "1234567");
807   if (r != 7)
808     exit(1);
810   r = snprintf(buffer, 0, "1234567");
812   if (r != 7)
813     exit(1);
815   r = snprintf(NULL, 0, "1234567");
817   if (r != 7)
818     exit(1);
820   exit(0);
824 main(void)
826   doit();
827   exit(1);
828 }'''
830   if cc_can_run
831     rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
832     if rres.compiled() and rres.returncode() == 0
833       glib_conf.set('HAVE_C99_SNPRINTF', 1)
834       have_good_snprintf = true
835     endif
836   else
837       have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
838       glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
839   endif
840 endif
842 if host_system == 'windows'
843   glib_conf.set_quoted('EXEEXT', '.exe')
844 else
845   glib_conf.set('EXEEXT', '')
846 endif
848 if have_good_vsnprintf and have_good_snprintf
849   # Our printf is 'good' only if vsnpintf()/snprintf() supports C99 well enough
850   glib_conf.set('HAVE_GOOD_PRINTF', 1) # FIXME: Check for HAVE_UNIX98_PRINTF?
851 else
852   glib_conf.set('HAVE_VASPRINTF', 1)
853 endif
855 # Check whether the printf() family supports Unix98 %n$ positional parameters
856 # AC_FUNC_PRINTF_UNIX98
857 # Nothing uses HAVE_UNIX98_PRINTF
860 # Check for nl_langinfo and CODESET
861 # FIXME: Check for HAVE_BIND_TEXTDOMAIN_CODESET
862 if cc.links('''#include <langinfo.h>
863                int main (int argc, char ** argv) {
864                  char *codeset = nl_langinfo (CODESET);
865                  return 0;
866                }''', name : 'nl_langinfo and CODESET')
867   glib_conf.set('HAVE_LANGINFO_CODESET', 1)
868   glib_conf.set('HAVE_CODESET', 1)
869 endif
871 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
872 if cc.links('''#include <langinfo.h>
873                int main (int argc, char ** argv) {
874                  char *str;
875                  str = nl_langinfo (PM_STR);
876                  str = nl_langinfo (D_T_FMT);
877                  str = nl_langinfo (D_FMT);
878                  str = nl_langinfo (T_FMT);
879                  str = nl_langinfo (T_FMT_AMPM);
880                  str = nl_langinfo (MON_1);
881                  str = nl_langinfo (ABMON_12);
882                  str = nl_langinfo (DAY_1);
883                  str = nl_langinfo (ABDAY_7);
884                  return 0;
885                }''', name : 'nl_langinfo (PM_STR)')
886   glib_conf.set('HAVE_LANGINFO_TIME', 1)
887 endif
888 if cc.links('''#include <langinfo.h>
889                int main (int argc, char ** argv) {
890                  char *str;
891                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
892                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
893                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
894                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
895                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
896                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
897                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
898                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
899                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
900                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
901                  return 0;
902                }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
903   glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
904 endif
906 # Check for nl_langinfo and alternative month names
907 if cc.links('''#ifndef _GNU_SOURCE
908               # define _GNU_SOURCE
909               #endif
910               #include <langinfo.h>
911                int main (int argc, char ** argv) {
912                  char *str;
913                  str = nl_langinfo (ALTMON_1);
914                  str = nl_langinfo (ALTMON_2);
915                  str = nl_langinfo (ALTMON_3);
916                  str = nl_langinfo (ALTMON_4);
917                  str = nl_langinfo (ALTMON_5);
918                  str = nl_langinfo (ALTMON_6);
919                  str = nl_langinfo (ALTMON_7);
920                  str = nl_langinfo (ALTMON_8);
921                  str = nl_langinfo (ALTMON_9);
922                  str = nl_langinfo (ALTMON_10);
923                  str = nl_langinfo (ALTMON_11);
924                  str = nl_langinfo (ALTMON_12);
925                  return 0;
926                }''', name : 'nl_langinfo (ALTMON_n)')
927   glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
928 endif
930 # Check for nl_langinfo and abbreviated alternative month names
931 if cc.links('''#ifndef _GNU_SOURCE
932               # define _GNU_SOURCE
933               #endif
934               #include <langinfo.h>
935                int main (int argc, char ** argv) {
936                  char *str;
937                  str = nl_langinfo (_NL_ALTMON_1);
938                  str = nl_langinfo (_NL_ALTMON_2);
939                  str = nl_langinfo (_NL_ALTMON_3);
940                  str = nl_langinfo (_NL_ALTMON_4);
941                  str = nl_langinfo (_NL_ALTMON_5);
942                  str = nl_langinfo (_NL_ALTMON_6);
943                  str = nl_langinfo (_NL_ALTMON_7);
944                  str = nl_langinfo (_NL_ALTMON_8);
945                  str = nl_langinfo (_NL_ALTMON_9);
946                  str = nl_langinfo (_NL_ALTMON_10);
947                  str = nl_langinfo (_NL_ALTMON_11);
948                  str = nl_langinfo (_NL_ALTMON_12);
949                  return 0;
950                }''', name : 'nl_langinfo (_NL_ALTMON_n)')
951   glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
952 endif
954 # Check if C compiler supports the 'signed' keyword
955 if not cc.compiles('''signed char x;''', name : 'signed')
956   glib_conf.set('signed', '/* NOOP */')
957 endif
959 # Check if the ptrdiff_t type exists
960 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
961   glib_conf.set('HAVE_PTRDIFF_T', 1)
962 endif
964 # Check for sig_atomic_t type
965 if cc.links('''#include <signal.h>
966                #include <sys/types.h>
967                sig_atomic_t val = 42;
968                int main (int argc, char ** argv) {
969                  return val == 42 ? 0 : 1;
970                }''', name : 'sig_atomic_t')
971   glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
972 endif
974 # Check if 'long long' works
975 # jm_AC_TYPE_LONG_LONG
976 if cc.compiles('''long long ll = 1LL;
977                   int i = 63;
978                   int some_func (void) {
979                     long long llmax = (long long) -1;
980                     return ll << i | ll >> i | llmax / ll | llmax % ll;
981                   }''', name : 'long long')
982   glib_conf.set('HAVE_LONG_LONG', 1)
983   have_long_long = true
984 else
985   have_long_long = false
986 endif
988 # Test whether the compiler supports the 'long double' type.
989 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it.  */
990                   long double foo = 0.0;
991                   /* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
992                   int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
993                name : 'long double')
994   glib_conf.set('HAVE_LONG_DOUBLE', 1)
995 endif
997 # Test whether <stddef.h> has the 'wchar_t' type.
998 if cc.has_header_symbol('stddef.h', 'wchar_t')
999   glib_conf.set('HAVE_WCHAR_T', 1)
1000 endif
1002 # Test whether <wchar.h> has the 'wint_t' type.
1003 if cc.has_header_symbol('wchar.h', 'wint_t')
1004   glib_conf.set('HAVE_WINT_T', 1)
1005 endif
1007 found_uintmax_t = false
1009 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
1010 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1011 # jm_AC_HEADER_INTTYPES_H
1012 if cc.compiles('''#include <sys/types.h>
1013                   #include <inttypes.h>
1014                   void some_func (void) {
1015                     uintmax_t i = (uintmax_t) -1;
1016                   }''', name : 'uintmax_t in inttypes.h')
1017   glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1018   found_uintmax_t = true
1019 endif
1021 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1022 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1023 # jm_AC_HEADER_STDINT_H
1024 if cc.compiles('''#include <sys/types.h>
1025                   #include <stdint.h>
1026                   void some_func (void) {
1027                     uintmax_t i = (uintmax_t) -1;
1028                   }''', name : 'uintmax_t in stdint.h')
1029   glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1030   found_uintmax_t = true
1031 endif
1033 # Define intmax_t to 'long' or 'long long'
1034 # if it is not already defined in <stdint.h> or <inttypes.h>.
1035 # For simplicity, we assume that a header file defines 'intmax_t' if and
1036 # only if it defines 'uintmax_t'.
1037 if found_uintmax_t
1038   glib_conf.set('HAVE_INTMAX_T', 1)
1039 elif have_long_long
1040   glib_conf.set('intmax_t', 'long long')
1041 else
1042   glib_conf.set('intmax_t', 'long')
1043 endif
1045 char_size = cc.sizeof('char')
1046 short_size = cc.sizeof('short')
1047 int_size = cc.sizeof('int')
1048 voidp_size = cc.sizeof('void*')
1049 long_size = cc.sizeof('long')
1050 if have_long_long
1051   long_long_size = cc.sizeof('long long')
1052 else
1053   long_long_size = 0
1054 endif
1055 sizet_size = cc.sizeof('size_t')
1056 if cc.get_id() == 'msvc'
1057   ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1058 else
1059   ssizet_size = cc.sizeof('ssize_t')
1060 endif
1062 int64_m = 'll'
1063 char_align = cc.alignment('char')
1064 short_align = cc.alignment('short')
1065 int_align = cc.alignment('int')
1066 voidp_align = cc.alignment('void*')
1067 long_align = cc.alignment('long')
1068 long_long_align = cc.alignment('long long')
1069 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1070 # be 64-bit in C99, and it is available on all supported compilers
1071 sizet_align = cc.alignment('size_t')
1073 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1075 glib_conf.set('SIZEOF_CHAR', char_size)
1076 glib_conf.set('SIZEOF_INT', int_size)
1077 glib_conf.set('SIZEOF_SHORT', short_size)
1078 glib_conf.set('SIZEOF_LONG', long_size)
1079 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1080 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1081 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1082 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1084 if short_size == 2
1085   gint16 = 'short'
1086   gint16_modifier='h'
1087   gint16_format='hi'
1088   guint16_format='hu'
1089 elif int_size == 2
1090   gint16 = 'int'
1091   gint16_modifier=''
1092   gint16_format='i'
1093   guint16_format='u'
1094 else
1095   error('Compiler provides no native 16-bit integer type')
1096 endif
1097 glibconfig_conf.set('gint16', gint16)
1098 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1099 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1100 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1102 if short_size == 4
1103   gint32 = 'short'
1104   gint32_modifier='h'
1105   gint32_format='hi'
1106   guint32_format='hu'
1107   guint32_align = short_align
1108 elif int_size == 4
1109   gint32 = 'int'
1110   gint32_modifier=''
1111   gint32_format='i'
1112   guint32_format='u'
1113   guint32_align = int_align
1114 elif long_size == 4
1115   gint32 = 'long'
1116   gint32_modifier='l'
1117   gint32_format='li'
1118   guint32_format='lu'
1119   guint32_align = long_align
1120 else
1121   error('Compiler provides no native 32-bit integer type')
1122 endif
1123 glibconfig_conf.set('gint32', gint32)
1124 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1125 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1126 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1127 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1129 if int_size == 8
1130   gint64 = 'int'
1131   gint64_modifier=''
1132   gint64_format='i'
1133   guint64_format='u'
1134   glib_extension=''
1135   gint64_constant='(val)'
1136   guint64_constant='(val)'
1137   guint64_align = int_align
1138 elif long_size == 8
1139   gint64 = 'long'
1140   glib_extension=''
1141   gint64_modifier='l'
1142   gint64_format='li'
1143   guint64_format='lu'
1144   gint64_constant='(val##L)'
1145   guint64_constant='(val##UL)'
1146   guint64_align = long_align
1147 elif long_long_size == 8
1148   gint64 = 'long long'
1149   glib_extension='G_GNUC_EXTENSION '
1150   gint64_modifier=int64_m
1151   gint64_format=int64_m + 'i'
1152   guint64_format=int64_m + 'u'
1153   gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1154   guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1155   guint64_align = long_long_align
1156 else
1157   error('Compiler provides no native 64-bit integer type')
1158 endif
1159 glibconfig_conf.set('glib_extension', glib_extension)
1160 glibconfig_conf.set('gint64', gint64)
1161 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1162 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1163 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1164 glibconfig_conf.set('gint64_constant', gint64_constant)
1165 glibconfig_conf.set('guint64_constant', guint64_constant)
1166 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1168 if host_system == 'windows'
1169   glibconfig_conf.set('g_pid_type', 'void*')
1170   glibconfig_conf.set_quoted('g_pid_format', 'p')
1171   if host_machine.cpu_family() == 'x86_64'
1172     glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1173   else
1174     glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1175   endif
1176   glibconfig_conf.set('g_dir_separator', '\\\\')
1177   glibconfig_conf.set('g_searchpath_separator', ';')
1178 else
1179   glibconfig_conf.set('g_pid_type', 'int')
1180   glibconfig_conf.set_quoted('g_pid_format', 'i')
1181   glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1182   glibconfig_conf.set('g_dir_separator', '/')
1183   glibconfig_conf.set('g_searchpath_separator', ':')
1184 endif
1186 if sizet_size == short_size
1187   glibconfig_conf.set('glib_size_type_define', 'short')
1188   glibconfig_conf.set_quoted('gsize_modifier', 'h')
1189   glibconfig_conf.set_quoted('gssize_modifier', 'h')
1190   glibconfig_conf.set_quoted('gsize_format', 'hu')
1191   glibconfig_conf.set_quoted('gssize_format', 'hi')
1192   glibconfig_conf.set('glib_msize_type', 'SHRT')
1193 elif sizet_size == int_size
1194   glibconfig_conf.set('glib_size_type_define', 'int')
1195   glibconfig_conf.set_quoted('gsize_modifier', '')
1196   glibconfig_conf.set_quoted('gssize_modifier', '')
1197   glibconfig_conf.set_quoted('gsize_format', 'u')
1198   glibconfig_conf.set_quoted('gssize_format', 'i')
1199   glibconfig_conf.set('glib_msize_type', 'INT')
1200 elif sizet_size == long_size
1201   glibconfig_conf.set('glib_size_type_define', 'long')
1202   glibconfig_conf.set_quoted('gsize_modifier', 'l')
1203   glibconfig_conf.set_quoted('gssize_modifier', 'l')
1204   glibconfig_conf.set_quoted('gsize_format', 'lu')
1205   glibconfig_conf.set_quoted('gssize_format', 'li')
1206   glibconfig_conf.set('glib_msize_type', 'LONG')
1207 elif sizet_size == long_long_size
1208   glibconfig_conf.set('glib_size_type_define', 'long long')
1209   glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1210   glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1211   glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1212   glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1213   glibconfig_conf.set('glib_msize_type', 'INT64')
1214 else
1215   error('Could not determine size of size_t.')
1216 endif
1218 if voidp_size == int_size
1219   glibconfig_conf.set('glib_intptr_type_define', 'int')
1220   glibconfig_conf.set_quoted('gintptr_modifier', '')
1221   glibconfig_conf.set_quoted('gintptr_format', 'i')
1222   glibconfig_conf.set_quoted('guintptr_format', 'u')
1223   glibconfig_conf.set('glib_gpi_cast', '(gint)')
1224   glibconfig_conf.set('glib_gpui_cast', '(guint)')
1225 elif voidp_size == long_size
1226   glibconfig_conf.set('glib_intptr_type_define', 'long')
1227   glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1228   glibconfig_conf.set_quoted('gintptr_format', 'li')
1229   glibconfig_conf.set_quoted('guintptr_format', 'lu')
1230   glibconfig_conf.set('glib_gpi_cast', '(glong)')
1231   glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1232 elif voidp_size == long_long_size
1233   glibconfig_conf.set('glib_intptr_type_define', 'long long')
1234   glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1235   glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1236   glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1237   glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1238   glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1239 else
1240   error('Could not determine size of void *')
1241 endif
1243 if long_size != 8 and long_long_size != 8 and int_size != 8
1244   error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1245 endif
1247 glibconfig_conf.set('gintbits', int_size * 8)
1248 glibconfig_conf.set('glongbits', long_size * 8)
1249 glibconfig_conf.set('gsizebits', sizet_size * 8)
1250 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1252 # FIXME: maybe meson should tell us the libsuffix?
1253 if host_system == 'windows'
1254   g_module_suffix = 'dll'
1255 elif host_system == 'darwin'
1256   g_module_suffix = 'dylib'
1257 else
1258   g_module_suffix = 'so'
1259 endif
1260 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1262 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1263 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1264 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1265 glibconfig_conf.set('GLIB_VERSION', glib_version)
1267 glibconfig_conf.set('glib_void_p', voidp_size)
1268 glibconfig_conf.set('glib_long', long_size)
1269 glibconfig_conf.set('glib_size_t', sizet_size)
1270 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1271 if host_machine.endian() == 'big'
1272   glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1273   glibconfig_conf.set('g_bs_native', 'BE')
1274   glibconfig_conf.set('g_bs_alien', 'LE')
1275 else
1276   glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1277   glibconfig_conf.set('g_bs_native', 'LE')
1278   glibconfig_conf.set('g_bs_alien', 'BE')
1279 endif
1281 # === va_copy checks ===
1282 # we currently check for all three va_copy possibilities, so we get
1283 # all results in config.log for bug reports.
1285 va_copy_func = ''
1286 foreach try_func : [ '__va_copy', 'va_copy' ]
1287   if cc.compiles('''#include <stdarg.h>
1288                     #include <stdlib.h>
1289                     #ifdef _MSC_VER
1290                     # include "msvc_recommended_pragmas.h"
1291                     #endif
1292                     void f (int i, ...) {
1293                     va_list args1, args2;
1294                     va_start (args1, i);
1295                     @0@ (args2, args1);
1296                     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1297                       exit (1);
1298                     va_end (args1); va_end (args2);
1299                     }
1300                     int main() {
1301                       f (0, 42);
1302                       return 0;
1303                     }'''.format(try_func),
1304                     name : try_func + ' check')
1305     va_copy_func = try_func
1306   endif
1307 endforeach
1308 if va_copy_func != ''
1309   glib_conf.set('G_VA_COPY', va_copy_func)
1310   glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1311 else
1312   glib_vacopy = '/* #undef G_VA_COPY */'
1313 endif
1315 va_list_val_copy_prog = '''
1316   #include <stdarg.h>
1317   #include <stdlib.h>
1318   void f (int i, ...) {
1319     va_list args1, args2;
1320     va_start (args1, i);
1321     args2 = args1;
1322     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1323       exit (1);
1324     va_end (args1); va_end (args2);
1325   }
1326   int main() {
1327     f (0, 42);
1328     return 0;
1329   }'''
1331 if cc_can_run
1332   rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1333   glib_va_val_copy = rres.returncode() == 0
1334 else
1335   glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
1336 endif
1337 if not glib_va_val_copy
1338   glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1339   glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1340 endif
1341 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1343 # check for flavours of varargs macros
1344 g_have_iso_c_varargs = cc.compiles('''
1345   void some_func (void) {
1346     int a(int p1, int p2, int p3);
1347     #define call_a(...) a(1,__VA_ARGS__)
1348     call_a(2,3);
1349   }''', name : 'ISO C99 varargs macros in C')
1351 if g_have_iso_c_varargs
1352   glibconfig_conf.set('g_have_iso_c_varargs', '''
1353 #ifndef __cplusplus
1354 # define G_HAVE_ISO_VARARGS 1
1355 #endif''')
1356 endif
1358 g_have_iso_cxx_varargs = cxx.compiles('''
1359   void some_func (void) {
1360     int a(int p1, int p2, int p3);
1361     #define call_a(...) a(1,__VA_ARGS__)
1362     call_a(2,3);
1363   }''', name : 'ISO C99 varargs macros in C++')
1365 if g_have_iso_cxx_varargs
1366   glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1367 #ifdef __cplusplus
1368 # define G_HAVE_ISO_VARARGS 1
1369 #endif''')
1370 endif
1372 g_have_gnuc_varargs = cc.compiles('''
1373   void some_func (void) {
1374     int a(int p1, int p2, int p3);
1375     #define call_a(params...) a(1,params)
1376     call_a(2,3);
1377   }''', name : 'GNUC varargs macros')
1379 if cc.has_header('alloca.h')
1380   glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1381 endif
1382 has_syspoll = cc.has_header('sys/poll.h')
1383 has_systypes = cc.has_header('sys/types.h')
1384 if has_syspoll
1385   glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1386 endif
1387 has_winsock2 = cc.has_header('winsock2.h')
1389 if has_syspoll and has_systypes
1390   poll_includes = '''
1391       #include<sys/poll.h>
1392       #include<sys/types.h>'''
1393 elif has_winsock2
1394   poll_includes = '''
1395       #define _WIN32_WINNT @0@
1396       #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1397 else
1398   # FIXME?
1399   error('FIX POLL* defines')
1400 endif
1402 poll_defines = [
1403   [ 'POLLIN', 'g_pollin', 1 ],
1404   [ 'POLLOUT', 'g_pollout', 4 ],
1405   [ 'POLLPRI', 'g_pollpri', 2 ],
1406   [ 'POLLERR', 'g_pollerr', 8 ],
1407   [ 'POLLHUP', 'g_pollhup', 16 ],
1408   [ 'POLLNVAL', 'g_pollnval', 32 ],
1411 if has_syspoll and has_systypes
1412   foreach d : poll_defines
1413     val = cc.compute_int(d[0], prefix: poll_includes)
1414     glibconfig_conf.set(d[1], val)
1415   endforeach
1416 elif has_winsock2
1417   # Due to a missed bug in configure.ac the poll test
1418   # never succeeded on Windows and used some pre-defined
1419   # values as a fallback. Keep using them to maintain
1420   # ABI compatibility with autotools builds of glibs
1421   # and with *any* glib-using code compiled against them,
1422   # since these values end up in a public header glibconfig.h.
1423   foreach d : poll_defines
1424     glibconfig_conf.set(d[1], d[2])
1425   endforeach
1426 endif
1428 # Internet address families
1429 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1430 if host_system == 'windows'
1431   inet_includes = '''
1432       #include <winsock2.h>'''
1433 else
1434   inet_includes = '''
1435       #include <sys/types.h>
1436       #include <sys/socket.h>'''
1437 endif
1439 inet_defines = [
1440   [ 'AF_UNIX', 'g_af_unix' ],
1441   [ 'AF_INET', 'g_af_inet' ],
1442   [ 'AF_INET6', 'g_af_inet6' ],
1443   [ 'MSG_OOB', 'g_msg_oob' ],
1444   [ 'MSG_PEEK', 'g_msg_peek' ],
1445   [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1447 foreach d : inet_defines
1448   val = cc.compute_int(d[0], prefix: inet_includes)
1449   glibconfig_conf.set(d[1], val)
1450 endforeach
1452 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', true) # FIXME!
1454 # We need a more robust approach here...
1455 host_cpu_family = host_machine.cpu_family()
1456 if host_cpu_family == 'x86' or host_cpu_family == 'x86_64' or host_cpu_family == 's390' or host_cpu_family == 's390x' or host_cpu_family.startswith('arm') or host_cpu_family.startswith('crisv32') or host_cpu_family.startswith('etrax')
1457   glib_memory_barrier_needed = false
1458 elif host_cpu_family.startswith('sparc') or host_cpu_family.startswith('alpha') or host_cpu_family.startswith('powerpc') or host_cpu_family == 'ia64'
1459   glib_memory_barrier_needed = true
1460 else
1461   warning('Unknown host cpu: ' + host_cpu_family)
1462   glib_memory_barrier_needed = true
1463 endif
1464 glibconfig_conf.set('G_ATOMIC_OP_MEMORY_BARRIER_NEEDED', glib_memory_barrier_needed)
1466 # We need to decide at configure time if GLib will use real atomic
1467 # operations ("lock free") or emulated ones with a mutex.  This is
1468 # because we must put this information in glibconfig.h so we know if
1469 # it is safe or not to inline using compiler intrinsics directly from
1470 # the header.
1472 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1473 # user is interested in knowing if they can use the atomic ops across
1474 # processes.
1476 # We can currently support the atomic ops natively when building GLib
1477 # with recent versions of GCC or MSVC.
1479 # Note that the atomic ops are only available with GCC on x86 when
1480 # using -march=i486 or higher.  If we detect that the atomic ops are
1481 # not available but would be available given the right flags, we want
1482 # to abort and advise the user to fix their CFLAGS.  It's better to do
1483 # that then to silently fall back on emulated atomic ops just because
1484 # the user had the wrong build environment.
1485 atomictest = '''int main() {
1486   volatile int atomic = 2;
1487   __sync_bool_compare_and_swap (&atomic, 2, 3);
1488   return 0;
1492 atomicdefine = '''
1493 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1494 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1495 #endif
1498 # We know that we can always use real ("lock free") atomic operations with MSVC
1499 if cc.get_id() == 'msvc' or cc.links(atomictest, name : 'atomic ops')
1500   have_atomic_lock_free = true
1501   if host_system == 'android' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1502     # When building for armv5 on Android, gcc 4.9 provides
1503     # __sync_bool_compare_and_swap but doesn't define
1504     # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1505     glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1506   endif
1507 else
1508   have_atomic_lock_free = false
1509   if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1510     error('GLib must be built with -march=i486 or later.')
1511   endif
1512 endif
1513 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1515 # === Threads ===
1517 # Determination of thread implementation
1518 if host_system == 'windows' and not get_option('force_posix_threads')
1519   thread_dep = []
1520   threads_implementation = 'win32'
1521   glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1522   glib_conf.set('THREADS_WIN32', 1)
1523 else
1524   thread_dep = dependency('threads')
1525   threads_implementation = 'posix'
1526   pthread_prefix = '''
1527       #ifndef _GNU_SOURCE
1528       # define _GNU_SOURCE
1529       #endif
1530       #include <pthread.h>'''
1531   glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1532   glib_conf.set('THREADS_POSIX', 1)
1533   if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1534     glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1535   endif
1536   if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1537     glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1538   endif
1539   if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1540     glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1541   endif
1542   if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1543     glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1544   endif
1545   # Assume that pthread_setname_np is available in some form; same as configure
1546   if cc.links(pthread_prefix + '''
1547               int main() {
1548                 pthread_setname_np("example");
1549                 return 0;
1550               }''',
1551               name : 'pthread_setname_np(const char*)',
1552               dependencies : thread_dep)
1553     # macOS and iOS
1554     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1555   elif cc.links(pthread_prefix + '''
1556                 int main() {
1557                   pthread_setname_np(pthread_self(), "example");
1558                   return 0;
1559                 }''',
1560                 name : 'pthread_setname_np(pthread_t, const char*)',
1561                 dependencies : thread_dep)
1562     # Linux, Solaris, etc.
1563     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1564   endif
1565 endif
1567 # FIXME: we should make it print the result and always return 0, so that
1568 # the output in meson shows up as green
1569 stack_grows_check_prog = '''
1570   volatile int *a = 0, *b = 0;
1571   void f (int i) {
1572     volatile int x = 5;
1573     if (i == 0)
1574       b = &x;
1575     else
1576       f (i - 1);
1577   }
1578   int main () {
1579     volatile int y = 7;
1580     a = &y;
1581     f (100);
1582     return b > a ? 0 : 1;
1583   }'''
1585 if cc_can_run
1586   rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
1587   growing_stack = rres.returncode() == 0
1588 else
1589   growing_stack = meson.get_cross_property('growing_stack', false)
1590 endif
1592 glibconfig_conf.set('G_HAVE_GROWING_STACK', growing_stack)
1594 # Tests for iconv
1596 # USE_LIBICONV_GNU: Using GNU libiconv
1597 # USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library
1599 # We should never use the MinGW C library's iconv. On Windows we use the
1600 # GNU implementation that ships with MinGW.
1602 # On Windows, just always use the built-in implementation
1603 if host_system == 'windows'
1604   libiconv = []
1605   glib_conf.set('USE_LIBICONV_NATIVE', true)
1606 else
1607   found_iconv = false
1608   iconv_opt = get_option('iconv')
1609   if iconv_opt == 'libc'
1610     if cc.has_function('iconv_open')
1611       libiconv = []
1612       found_iconv = true
1613     endif
1614   elif iconv_opt == 'gnu'
1615     if cc.has_header_symbol('iconv.h', 'libiconv_open')
1616       glib_conf.set('USE_LIBICONV_GNU', true)
1617       libiconv = [cc.find_library('iconv')]
1618       found_iconv = true
1619     endif
1620   elif iconv_opt == 'native'
1621     if cc.has_header_symbol('iconv.h', 'iconv_open')
1622       glib_conf.set('USE_LIBICONV_NATIVE', true)
1623       libiconv = [cc.find_library('iconv')]
1624       found_iconv = true
1625     endif
1626   endif
1628   if not found_iconv
1629     error('iconv implementation "@0@" not found'.format(iconv_opt))
1630   endif
1632 endif
1634 if get_option('internal_pcre')
1635   pcre = []
1636   use_system_pcre = false
1637 else
1638   pcre = dependency('libpcre', version: '>= 8.31', required : false) # Should check for Unicode support, too. FIXME
1639   if not pcre.found()
1640     if cc.get_id() == 'msvc'
1641     # MSVC: Search for the PCRE library by the configuration, which corresponds
1642     # to the output of CMake builds of PCRE.  Note that debugoptimized
1643     # is really a Release build with .PDB files.
1644       if buildtype == 'debug'
1645         pcre = cc.find_library('pcred', required : false)
1646       else
1647         pcre = cc.find_library('pcre', required : false)
1648       endif
1649     endif
1650   endif
1651   use_system_pcre = pcre.found()
1652 endif
1653 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1655 use_pcre_static_flag = false
1657 if host_system == 'windows'
1658   if not use_system_pcre
1659     use_pcre_static_flag = true
1660   else
1661     pcre_static = cc.links('''#define PCRE_STATIC
1662                               #include <pcre.h>
1663                               int main() {
1664                                 void *p = NULL;
1665                                 pcre_free(p);
1666                                 return 0;
1667                               }''',
1668                            dependencies: pcre,
1669                            name : 'Windows system PCRE is a static build')
1670     if pcre_static
1671       use_pcre_static_flag = true
1672     endif
1673   endif
1674 endif
1676 libm = cc.find_library('m', required : false)
1677 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
1678 if cc.get_id() != 'msvc'
1679   libz_dep = dependency('zlib', fallback : ['zlib', 'zlib_dep'])
1680 else
1681   # MSVC: Don't use the bundled ZLib sources until we are sure that we can't
1682   # find the ZLib .lib
1683   libz_dep = dependency('zlib', required : false)
1685   # MSVC: Search for the ZLib .lib, which corresponds to the results of
1686   # of using ZLib's win32/makefile.msc.
1687   if not libz_dep.found()
1688     libz_dep = cc.find_library('zlib1', required : false)
1689     if not libz_dep.found()
1690       libz_dep = cc.find_library('zlib', required : false)
1691       if not libz_dep.found()
1692         libz_dep = subproject('zlib').get_variable('zlib_dep')
1693       endif
1694     endif
1695   endif
1696 endif
1698 # First check in libc, fallback to libintl, and as last chance build
1699 # proxy-libintl subproject.
1700 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
1701 # implementations. This could be extended if issues are found in some platforms.
1702 if cc.has_function('ngettext')
1703   libintl = []
1704 else
1705   libintl = cc.find_library('intl', required : false)
1706   if not libintl.found()
1707     libintl = subproject('proxy-libintl').get_variable('intl_dep')
1708   endif
1709 endif
1711 # We require gettext to always be present
1712 glib_conf.set('HAVE_DCGETTEXT', 1)
1713 glib_conf.set('HAVE_GETTEXT', 1)
1715 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
1716 # xgettext is optional (on Windows for instance)
1717 xgettext = find_program('xgettext', required : false)
1719 # libmount is only used by gio, but we need to fetch the libs to generate the
1720 # pkg-config file below
1721 libmount_dep = []
1722 if host_system == 'linux' and get_option('libmount')
1723   libmount_dep = [dependency('mount', version : '>=2.23', required : true)]
1724   glib_conf.set('HAVE_LIBMOUNT', 1)
1725 endif
1727 if host_system == 'windows'
1728   winsock2 = cc.find_library('ws2_32')
1729 endif
1731 selinux_dep = []
1732 if host_system == 'linux' and get_option('selinux')
1733   selinux_dep = [dependency('libselinux')]
1734   glib_conf.set('HAVE_SELINUX', 1)
1735 endif
1737 xattr_dep = []
1738 if host_system != 'windows' and get_option('xattr')
1739   # either glibc or libattr can provide xattr support
1740   # for both of them, we check for getxattr being in
1741   # the library and a valid xattr header.
1743   # try glibc
1744   if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
1745     glib_conf.set('HAVE_SYS_XATTR_H', 1)
1746     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
1747   #failure. try libattr
1748   elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
1749     glib_conf.set('HAVE_ATTR_XATTR_H', 1)
1750     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
1751     xattr_dep = [cc.find_library('xattr')]
1752   else
1753     error('No getxattr implementation found in C library or libxattr')
1754   endif
1756   glib_conf.set('HAVE_XATTR', 1)
1757   if cc.compiles(glib_conf_prefix + '''
1758                  #include <stdio.h>
1759                  #ifdef HAVE_SYS_TYPES_H
1760                  #include <sys/types.h>
1761                  #endif
1762                  #ifdef HAVE_SYS_XATTR_H
1763                  #include <sys/xattr.h>
1764                  #elif HAVE_ATTR_XATTR_H
1765                  #include <attr/xattr.h>
1766                  #endif
1768                  int main (void) {
1769                    ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
1770                    return len;
1771                  }''',
1772                  name : 'XATTR_NOFOLLOW')
1773     glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
1774   endif
1775 endif
1777 # Test if we have strlcpy/strlcat with a compatible implementation:
1778 # https://bugzilla.gnome.org/show_bug.cgi?id=53933
1779 if cc_can_run
1780   rres = cc.run('''#include <stdlib.h>
1781                    #include <string.h>
1782                    int main() {
1783                      char p[10];
1784                      (void) strlcpy (p, "hi", 10);
1785                      if (strlcat (p, "bye", 0) != 3)
1786                        return 1;
1787                      return 0;
1788                    }''',
1789                 name : 'OpenBSD strlcpy/strlcat')
1790   if rres.compiled() and rres.returncode() == 0
1791     glib_conf.set('HAVE_STRLCPY', 1)
1792   endif
1793 elif meson.get_cross_property('have_strlcpy', false)
1794   glib_conf.set('HAVE_STRLCPY', 1)
1795 endif
1797 python = import('python3').find_python()
1799 # Determine which user environment-dependent files that we want to install
1800 have_bash = find_program('bash', required : false).found() # For completion scripts
1801 have_m4 = find_program('m4', required : false).found() # For m4 macros
1802 have_sh = find_program('sh', required : false).found() # For glib-gettextize
1804 # FIXME: defines in config.h that are not actually used anywhere
1805 # (we add them for now to minimise the diff)
1806 glib_conf.set('HAVE_DLFCN_H', 1)
1807 glib_conf.set('STDC_HEADERS', 1)
1808 glib_conf.set('SIZEOF___INT64', 8)
1810 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
1811 if host_system == 'sunos'
1812   glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
1813   glib_conf.set('_XOPEN_SOURCE', 2)
1814   glib_conf.set('__EXTENSIONS__',1)
1815 endif
1817 # Sadly Meson does not expose this value:
1818 # https://github.com/mesonbuild/meson/pull/3460
1819 if host_system == 'windows'
1820   # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
1821   # with no explanation. Do the same here for now but this could be revisited if
1822   # if causes issues.
1823   export_dynamic_ldflags = []
1824 elif host_system == 'cygwin'
1825   export_dynamic_ldflags = ['-Wl,--export-all-symbols']
1826 elif host_system == 'darwin'
1827   export_dynamic_ldflags = []
1828 else
1829   export_dynamic_ldflags = ['-Wl,--export-dynamic']
1830 endif
1832 win32_cflags = []
1833 win32_ldflags = []
1834 if host_system == 'windows' and cc.get_id() != 'msvc'
1835   # Ensure MSVC-compatible struct packing convention is used when
1836   # compiling for Win32 with gcc. It is used for the whole project and exposed
1837   # in glib-2.0.pc.
1838   win32_cflags = ['-mms-bitfields']
1839   add_project_arguments(win32_cflags, language : 'c')
1841   # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
1842   win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi']
1843 elif host_system == 'cygwin'
1844   win32_ldflags = ['-luser32', '-lkernel32']
1845 endif
1847 # Tracing: dtrace
1848 want_dtrace = get_option('dtrace')
1849 enable_dtrace = false
1851 # Since dtrace support is opt-in we just error out if it was requested but
1852 # is not available. We don't bother with autodetection yet.
1853 if want_dtrace
1854   if glib_have_carbon
1855     error('GLib dtrace support not yet compatible with macOS dtrace')
1856   endif
1857   dtrace = find_program('dtrace', required : true) # error out if not found
1858   if not cc.has_header('sys/sdt.h')
1859     error('dtrace support needs sys/sdt.h header')
1860   endif
1861   # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
1862   dtrace_obj_gen = generator(dtrace,
1863     output : '@BASENAME@.o',
1864     arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1865   # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
1866   #               -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
1867   dtrace_hdr_gen = generator(dtrace,
1868     output : '@BASENAME@.h',
1869     arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1870   glib_conf.set('HAVE_DTRACE', 1)
1871   enable_dtrace = true
1872 endif
1874 # systemtap
1875 want_systemtap = get_option('systemtap')
1876 enable_systemtap = false
1878 if want_systemtap and enable_dtrace
1879   tapset_install_dir = get_option('tapset_install_dir')
1880   if tapset_install_dir == ''
1881     tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
1882   endif
1883   stp_cdata = configuration_data()
1884   stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
1885   stp_cdata.set('LT_CURRENT', minor_version * 100)
1886   stp_cdata.set('LT_REVISION', micro_version)
1887   enable_systemtap = true
1888 endif
1891 pkg = import('pkgconfig')
1892 windows = import('windows')
1893 subdir('glib')
1894 subdir('gobject')
1895 subdir('gthread')
1896 subdir('gmodule')
1897 subdir('gio')
1898 if xgettext.found()
1899   subdir('po')
1900 endif
1901 subdir('tests')
1903 # Install glib-gettextize executable, if a UNIX-style shell is found
1904 if have_sh
1905   # These should not contain " quotes around the values
1906   gettexize_conf = configuration_data()
1907   gettexize_conf.set('PACKAGE', 'glib')
1908   gettexize_conf.set('VERSION', meson.project_version())
1909   gettexize_conf.set('prefix', glib_prefix)
1910   gettexize_conf.set('datarootdir', glib_datadir)
1911   gettexize_conf.set('datadir', glib_datadir)
1912   configure_file(input : 'glib-gettextize.in',
1913     install : true,
1914     install_dir : 'bin',
1915     output : 'glib-gettextize',
1916     configuration : gettexize_conf)
1917 endif
1919 if have_m4
1920   # Install m4 macros that other projects use
1921   install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
1922     install_dir : join_paths(get_option('datadir'), 'aclocal'))
1923 endif
1925 if host_system != 'windows'
1926   # Install Valgrind suppression file (except on Windows,
1927   # as Valgrind is currently not supported on Windows)
1928   install_data('glib.supp',
1929     install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
1930 endif
1932 configure_file(output : 'config.h', configuration : glib_conf)
1934 if host_system == 'windows'
1935   install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
1936 endif
1938 if get_option('man')
1939   xsltproc = find_program('xsltproc', required : true)
1940   xsltproc_command = [
1941     xsltproc,
1942     '--nonet',
1943     '--stringparam', 'man.output.quietly', '1',
1944     '--stringparam', 'funcsynopsis.style', 'ansi',
1945     '--stringparam', 'man.th.extra1.suppress', '1',
1946     '--stringparam', 'man.authors.section.enabled', '0',
1947     '--stringparam', 'man.copyright.section.enabled', '0',
1948     '-o', '@OUTPUT@',
1949     'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
1950     '@INPUT@',
1951   ]
1952   man1_dir = get_option('mandir') + '/man1'
1953 endif
1955 gnome = import('gnome')
1956 subdir('docs/reference/glib')
1957 subdir('docs/reference/gobject')
1958 subdir('docs/reference/gio')