Merge branch 'lrn/binary-tests' into 'master'
[glib.git] / meson.build
blob6abc2e6e2dd28bc3549fd3dbd1e52406ae901a04
1 project('glib', 'c', 'cpp',
2   version : '2.57.1',
3   meson_version : '>= 0.46.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', 'http://bugzilla.gnome.org/enter_bug.cgi?product=glib')
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>''' ],
309 foreach m : struct_members
310   header_check_prefix = glib_conf_prefix
311   if m.length() == 3
312     header_check_prefix = header_check_prefix + m[2]
313   else
314     header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
315   endif
316   if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
317     define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
318     glib_conf.set(define, 1)
319     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
320   else
321   endif
322 endforeach
324 # Compiler flags
325 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
326   test_c_args = [
327     '-Wall',
328     '-Wduplicated-branches',
329     '-Wmisleading-indentation',
330     '-Wstrict-prototypes',
331     '-Wunused',
332     '-Werror=declaration-after-statement',
333     '-Werror=format=2',
334     '-Werror=format-security',
335     '-Werror=implicit-function-declaration',
336     '-Werror=init-self',
337     '-Werror=missing-include-dirs',
338     '-Werror=missing-prototypes',
339     '-Werror=pointer-arith',
340   ]
341   test_c_link_args = [
342     '-Wl,-z,nodelete',
343   ]
344   if get_option('bsymbolic_functions')
345     test_c_link_args += ['-Wl,-Bsymbolic-functions']
346   endif
347 else
348   test_c_args = []
349   test_c_link_args = []
350 endif
352 add_project_arguments(cc.get_supported_arguments(test_c_args), language: 'c')
354 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
355 # means we cannot use that flag in add_project_link_arguments(), and must add
356 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
357 # because that is what the autotools build did.
358 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
359 # improve this.
360 glib_link_flags = cc.get_supported_link_arguments(test_c_link_args)
362 # Windows Support (7+)
363 if host_system == 'windows'
364   glib_conf.set('_WIN32_WINNT', '0x0601')
365 endif
367 functions = [
368   'alloca',
369   'endmntent',
370   'endservent',
371   'fallocate',
372   'fchmod',
373   'fchown',
374   'fdwalk',
375   'fsync',
376   'getc_unlocked',
377   'getfsstat',
378   'getgrgid_r',
379   'getmntent_r',
380   'getpwuid_r',
381   'getresuid',
382   'getvfsstat',
383   'gmtime_r',
384   'hasmntopt',
385   'inotify_init1',
386   'issetugid',
387   'kevent',
388   'kqueue',
389   'lchmod',
390   'lchown',
391   'link',
392   'localtime_r',
393   'lstat',
394   'mbrtowc',
395   'memalign',
396   'mmap',
397   'newlocale',
398   'pipe2',
399   'poll',
400   'prlimit',
401   'readlink',
402   'recvmmsg',
403   'sendmmsg',
404   'setenv',
405   'setmntent',
406   'strerror_r',
407   'strnlen',
408   'strsignal',
409   'strtod_l',
410   'strtoll_l',
411   'strtoull_l',
412   'symlink',
413   'timegm',
414   'unsetenv',
415   'uselocale',
416   'utimes',
417   'valloc',
418   'vasprintf',
419   'vsnprintf',
420   'wcrtomb',
421   'wcslen',
422   'wcsnlen',
425 if glib_conf.has('HAVE_SYS_STATVFS_H')
426   functions += ['statvfs']
427 else
428   have_func_statvfs = false
429 endif
430 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
431   functions += ['statfs']
432 else
433   have_func_statfs = false
434 endif
436 if host_system == 'windows'
437   iphlpapi_dep = cc.find_library('iphlpapi')
438   iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
439   foreach ifunc : iphlpapi_funcs
440     iphl_prefix =  '''#define _WIN32_WINNT @0@
441       #include <winsock2.h>
442       #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
443     if cc.has_function(ifunc,
444                        prefix : iphl_prefix,
445                        dependencies : iphlpapi_dep)
446       idefine = 'HAVE_' + ifunc.underscorify().to_upper()
447       glib_conf.set(idefine, 1)
448       glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
449       set_variable('have_func_' + ifunc, true)
450     else
451       set_variable('have_func_' + ifunc, false)
452     endif
453   endforeach
454 else
455   functions += ['if_indextoname', 'if_nametoindex']
456 endif
458 # AIX splice is something else
459 if host_system != 'aix'
460   functions += ['splice']
461 endif
463 foreach f : functions
464   if cc.has_function(f)
465     define = 'HAVE_' + f.underscorify().to_upper()
466     glib_conf.set(define, 1)
467     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
468     set_variable('have_func_' + f, true)
469   else
470     set_variable('have_func_' + f, false)
471   endif
472 endforeach
474 # Check that stpcpy() is usable; must use header
475 if cc.has_function('stpcpy', prefix : '#include <string.h>')
476   glib_conf.set('HAVE_STPCPY', 1)
477 endif
479 # Check that posix_memalign() is usable; must use header
480 if cc.has_function('posix_memalign', prefix : '#include <stdlib.h>')
481   glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
482 endif
484 # Check whether strerror_r returns char *
485 if have_func_strerror_r
486   if cc.compiles('''#define _GNU_SOURCE
487                     #include <string.h>
488                     int func (void) {
489                       char error_string[256];
490                       char *ptr = strerror_r (-2, error_string, 256);
491                       char c = *strerror_r (-2, error_string, 256);
492                       return c != 0 && ptr != (void*) 0L;
493                     }
494                  ''',
495                  name : 'strerror_r() returns char *')
496     glib_conf.set('STRERROR_R_CHAR_P', 1,
497                   description: 'Defined if strerror_r returns char *')
498   endif
499 endif
501 # Special-case these functions that have alternative names on Windows/MSVC
502 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
503   glib_conf.set('HAVE_SNPRINTF', 1)
504   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
505 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
506   hack_define = '1\n#define snprintf _snprintf'
507   glib_conf.set('HAVE_SNPRINTF', hack_define)
508   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
509 endif
511 if cc.has_function('strcasecmp')
512   glib_conf.set('HAVE_STRCASECMP', 1)
513   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
514 elif cc.has_function('_stricmp')
515   hack_define = '1\n#define strcasecmp _stricmp'
516   glib_conf.set('HAVE_STRCASECMP', hack_define)
517   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
518 endif
520 if cc.has_function('strncasecmp')
521   glib_conf.set('HAVE_STRNCASECMP', 1)
522   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
523 elif cc.has_function('_strnicmp')
524   hack_define = '1\n#define strncasecmp _strnicmp'
525   glib_conf.set('HAVE_STRNCASECMP', hack_define)
526   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
527 endif
529 if cc.has_header_symbol('sys/sysmacros.h', 'major')
530   glib_conf.set('MAJOR_IN_SYSMACROS', 1)
531 elif cc.has_header_symbol('sys/mkdev.h', 'major')
532   glib_conf.set('MAJOR_IN_MKDEV', 1)
533 elif cc.has_header_symbol('sys/types.h', 'major')
534   glib_conf.set('MAJOR_IN_TYPES', 1)
535 endif
537 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
538   glib_conf.set('HAVE_RTLD_LAZY', 1)
539 endif
541 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
542   glib_conf.set('HAVE_RTLD_NOW', 1)
543 endif
545 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
546   glib_conf.set('HAVE_RTLD_GLOBAL', 1)
547 endif
549 # Check whether to use statfs or statvfs
550 # Some systems have both statfs and statvfs, pick the most "native" for these
551 if have_func_statfs and have_func_statvfs
552   # on solaris and irix, statfs doesn't even have the f_bavail field
553   if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
554     have_func_statfs = false
555   else
556     # at least on linux, statfs is the actual syscall
557     have_func_statvfs = false
558   endif
559 endif
560 if have_func_statfs
561   glib_conf.set('USE_STATFS', 1)
562   stat_func_to_use = 'statfs'
563 elif have_func_statvfs
564   glib_conf.set('USE_STATVFS', 1)
565   stat_func_to_use = 'statvfs'
566 else
567   stat_func_to_use = 'neither'
568 endif
569 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
571 if host_system == 'linux'
572   if cc.has_function('mkostemp',
573                      prefix: '''#define _GNU_SOURCE
574                                 #include <stdlib.h>''')
575     glib_conf.set('HAVE_MKOSTEMP', 1)
576   endif
577 endif
579 osx_ldflags = []
580 glib_have_os_x_9_or_later = false
581 glib_have_carbon = false
582 glib_have_cocoa = false
583 if host_system == 'darwin'
584   add_languages('objc')
585   objcc = meson.get_compiler('objc')
587   osx_ldflags += ['-Wl,-framework,CoreFoundation']
589   # Mac OS X Carbon support
590   glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
591                                        #include <CoreServices/CoreServices.h>''',
592                                     name : 'Mac OS X Carbon support')
594   if glib_have_carbon
595     glib_conf.set('HAVE_CARBON', true)
596     osx_ldflags += '-Wl,-framework,Carbon'
597     glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
598                                                   #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
599                                                   #error Compiling for minimum OS X version before 10.9
600                                                   #endif''',
601                                                name : 'OS X 9 or later')
602   endif
604   # Mac OS X Cocoa support
605   glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
606                                       #ifdef GNUSTEP_BASE_VERSION
607                                       #error "Detected GNUstep, not Cocoa"
608                                       #endif''',
609                                    name : 'Mac OS X Cocoa support')
611   if glib_have_cocoa
612     glib_conf.set('HAVE_COCOA', true)
613     osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
614   endif
616   # FIXME: libgio mix C and objC source files and there is no way to reliably
617   # know which language flags it's going to use to link. Add to both languages
618   # for now. See https://github.com/mesonbuild/meson/issues/3585.
619   add_project_link_arguments(osx_ldflags, language : ['objc', 'c'])
620 endif
622 # Check for futex(2)
623 if cc.links('''#include <linux/futex.h>
624                #include <sys/syscall.h>
625                #include <unistd.h>
626                int main (int argc, char ** argv) {
627                  syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
628                  return 0;
629                }''', name : 'futex(2) system call')
630   glib_conf.set('HAVE_FUTEX', 1)
631 endif
633 # Check for eventfd(2)
634 if cc.links('''#include <sys/eventfd.h>
635                #include <unistd.h>
636                int main (int argc, char ** argv) {
637                  eventfd (0, EFD_CLOEXEC);
638                  return 0;
639                }''', name : 'eventfd(2) system call')
640   glib_conf.set('HAVE_EVENTFD', 1)
641 endif
643 clock_gettime_test_code = '''
644   #include <time.h>
645   struct timespec t;
646   int main (int argc, char ** argv) {
647     return clock_gettime(CLOCK_REALTIME, &t);
648   }'''
649 librt = []
650 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
651   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
652 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
653   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
654   librt = cc.find_library('rt')
655 endif
657 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
658 if have_func_statfs
659   if cc.compiles(glib_conf_prefix + '''
660                  #include <unistd.h>
661                         #ifdef HAVE_SYS_PARAM_H
662                         #include <sys/param.h>
663                         #endif
664                         #ifdef HAVE_SYS_VFS_H
665                         #include <sys/vfs.h>
666                         #endif
667                         #ifdef HAVE_SYS_MOUNT_H
668                         #include <sys/mount.h>
669                         #endif
670                         #ifdef HAVE_SYS_STATFS_H
671                         #include <sys/statfs.h>
672                         #endif
673                         void some_func (void) {
674                           struct statfs st;
675                           statfs("/", &st);
676                         }''', name : 'number of arguments to statfs() (n=2)')
677     glib_conf.set('STATFS_ARGS', 2)
678   elif cc.compiles(glib_conf_prefix + '''
679                    #include <unistd.h>
680                           #ifdef HAVE_SYS_PARAM_H
681                           #include <sys/param.h>
682                           #endif
683                           #ifdef HAVE_SYS_VFS_H
684                           #include <sys/vfs.h>
685                           #endif
686                           #ifdef HAVE_SYS_MOUNT_H
687                           #include <sys/mount.h>
688                           #endif
689                           #ifdef HAVE_SYS_STATFS_H
690                           #include <sys/statfs.h>
691                           #endif
692                           void some_func (void) {
693                             struct statfs st;
694                             statfs("/", &st, sizeof (st), 0);
695                           }''', name : 'number of arguments to statfs() (n=4)')
696     glib_conf.set('STATFS_ARGS', 4)
697   else
698     error('Unable to determine number of arguments to statfs()')
699   endif
700 endif
702 # open takes O_DIRECTORY as an option
703 #AC_MSG_CHECKING([])
704 if cc.compiles('''#include <fcntl.h>
705                   #include <sys/types.h>
706                   #include <sys/stat.h>],
707                   void some_func (void) {
708                     open(0, O_DIRECTORY, 0);
709                   }''', name : 'open() option O_DIRECTORY')
710   glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
711 endif
713 # Check whether there is a vsnprintf() function with C99 semantics installed.
714 # AC_FUNC_VSNPRINTF_C99
715 # Check whether there is a snprintf() function with C99 semantics installed.
716 # AC_FUNC_SNPRINTF_C99
718 have_good_vsnprintf = false
719 have_good_snprintf = false
721 if host_system == 'windows' and cc.get_id() == 'msvc'
722   # Unfortunately the Visual Studio 2015+ implementations of C99-style
723   # snprintf and vsnprintf don't seem to be quite good enough.
724   # (Sorry, I don't know exactly what is the problem,
725   # but it is related to floating point formatting and decimal point vs. comma.)
726   # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
727   # rigorous enough to notice, though.
728   glib_conf.set('HAVE_C99_SNPRINTF', false)
729   glib_conf.set('HAVE_C99_VSNPRINTF', false)
730 else
731   vsnprintf_c99_test_code = '''
732 #include <stdio.h>
733 #include <stdarg.h>
736 doit(char * s, ...)
738   char buffer[32];
739   va_list args;
740   int r;
742   va_start(args, s);
743   r = vsnprintf(buffer, 5, s, args);
744   va_end(args);
746   if (r != 7)
747     exit(1);
749   /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
750      implementation. The above will return 7 but if you replace
751      the size of the buffer with 0, it borks! */
752   va_start(args, s);
753   r = vsnprintf(buffer, 0, s, args);
754   va_end(args);
756   if (r != 7)
757     exit(1);
759   exit(0);
763 main(void)
765   doit("1234567");
766   exit(1);
767 }'''
769   if cc_can_run
770     rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
771     if rres.compiled() and rres.returncode() == 0
772       glib_conf.set('HAVE_C99_VSNPRINTF', 1)
773       have_good_vsnprintf = true
774     endif
775   else
776       have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
777       glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
778   endif
780   snprintf_c99_test_code = '''
781 #include <stdio.h>
782 #include <stdarg.h>
785 doit()
787   char buffer[32];
788   va_list args;
789   int r;
791   r = snprintf(buffer, 5, "1234567");
793   if (r != 7)
794     exit(1);
796   r = snprintf(buffer, 0, "1234567");
798   if (r != 7)
799     exit(1);
801   r = snprintf(NULL, 0, "1234567");
803   if (r != 7)
804     exit(1);
806   exit(0);
810 main(void)
812   doit();
813   exit(1);
814 }'''
816   if cc_can_run
817     rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
818     if rres.compiled() and rres.returncode() == 0
819       glib_conf.set('HAVE_C99_SNPRINTF', 1)
820       have_good_snprintf = true
821     endif
822   else
823       have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
824       glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
825   endif
826 endif
828 if host_system == 'windows'
829   glib_conf.set_quoted('EXEEXT', '.exe')
830 else
831   glib_conf.set('EXEEXT', '')
832 endif
834 if have_good_vsnprintf and have_good_snprintf
835   # Our printf is 'good' only if vsnpintf()/snprintf() supports C99 well enough
836   glib_conf.set('HAVE_GOOD_PRINTF', 1) # FIXME: Check for HAVE_UNIX98_PRINTF?
837 else
838   glib_conf.set('HAVE_VASPRINTF', 1)
839 endif
841 # Check whether the printf() family supports Unix98 %n$ positional parameters
842 # AC_FUNC_PRINTF_UNIX98
843 # Nothing uses HAVE_UNIX98_PRINTF
846 # Check for nl_langinfo and CODESET
847 # FIXME: Check for HAVE_BIND_TEXTDOMAIN_CODESET
848 if cc.links('''#include <langinfo.h>
849                int main (int argc, char ** argv) {
850                  char *codeset = nl_langinfo (CODESET);
851                  return 0;
852                }''', name : 'nl_langinfo and CODESET')
853   glib_conf.set('HAVE_LANGINFO_CODESET', 1)
854   glib_conf.set('HAVE_CODESET', 1)
855 endif
857 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
858 if cc.links('''#include <langinfo.h>
859                int main (int argc, char ** argv) {
860                  char *str;
861                  str = nl_langinfo (PM_STR);
862                  str = nl_langinfo (D_T_FMT);
863                  str = nl_langinfo (D_FMT);
864                  str = nl_langinfo (T_FMT);
865                  str = nl_langinfo (T_FMT_AMPM);
866                  str = nl_langinfo (MON_1);
867                  str = nl_langinfo (ABMON_12);
868                  str = nl_langinfo (DAY_1);
869                  str = nl_langinfo (ABDAY_7);
870                  return 0;
871                }''', name : 'nl_langinfo (PM_STR)')
872   glib_conf.set('HAVE_LANGINFO_TIME', 1)
873 endif
874 if cc.links('''#include <langinfo.h>
875                int main (int argc, char ** argv) {
876                  char *str;
877                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
878                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
879                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
880                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
881                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
882                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
883                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
884                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
885                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
886                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
887                  return 0;
888                }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
889   glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
890 endif
892 # Check for nl_langinfo and alternative month names
893 if cc.links('''#ifndef _GNU_SOURCE
894               # define _GNU_SOURCE
895               #endif
896               #include <langinfo.h>
897                int main (int argc, char ** argv) {
898                  char *str;
899                  str = nl_langinfo (ALTMON_1);
900                  str = nl_langinfo (ALTMON_2);
901                  str = nl_langinfo (ALTMON_3);
902                  str = nl_langinfo (ALTMON_4);
903                  str = nl_langinfo (ALTMON_5);
904                  str = nl_langinfo (ALTMON_6);
905                  str = nl_langinfo (ALTMON_7);
906                  str = nl_langinfo (ALTMON_8);
907                  str = nl_langinfo (ALTMON_9);
908                  str = nl_langinfo (ALTMON_10);
909                  str = nl_langinfo (ALTMON_11);
910                  str = nl_langinfo (ALTMON_12);
911                  return 0;
912                }''', name : 'nl_langinfo (ALTMON_n)')
913   glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
914 endif
916 # Check for nl_langinfo and abbreviated alternative month names
917 if cc.links('''#ifndef _GNU_SOURCE
918               # define _GNU_SOURCE
919               #endif
920               #include <langinfo.h>
921                int main (int argc, char ** argv) {
922                  char *str;
923                  str = nl_langinfo (_NL_ALTMON_1);
924                  str = nl_langinfo (_NL_ALTMON_2);
925                  str = nl_langinfo (_NL_ALTMON_3);
926                  str = nl_langinfo (_NL_ALTMON_4);
927                  str = nl_langinfo (_NL_ALTMON_5);
928                  str = nl_langinfo (_NL_ALTMON_6);
929                  str = nl_langinfo (_NL_ALTMON_7);
930                  str = nl_langinfo (_NL_ALTMON_8);
931                  str = nl_langinfo (_NL_ALTMON_9);
932                  str = nl_langinfo (_NL_ALTMON_10);
933                  str = nl_langinfo (_NL_ALTMON_11);
934                  str = nl_langinfo (_NL_ALTMON_12);
935                  return 0;
936                }''', name : 'nl_langinfo (_NL_ALTMON_n)')
937   glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
938 endif
940 # Check if C compiler supports the 'signed' keyword
941 if not cc.compiles('''signed char x;''', name : 'signed')
942   glib_conf.set('signed', '/* NOOP */')
943 endif
945 # Check if the ptrdiff_t type exists
946 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
947   glib_conf.set('HAVE_PTRDIFF_T', 1)
948 endif
950 # Check for sig_atomic_t type
951 if cc.links('''#include <signal.h>
952                #include <sys/types.h>
953                sig_atomic_t val = 42;
954                int main (int argc, char ** argv) {
955                  return val == 42 ? 0 : 1;
956                }''', name : 'sig_atomic_t')
957   glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
958 endif
960 # Check if 'long long' works
961 # jm_AC_TYPE_LONG_LONG
962 if cc.compiles('''long long ll = 1LL;
963                   int i = 63;
964                   int some_func (void) {
965                     long long llmax = (long long) -1;
966                     return ll << i | ll >> i | llmax / ll | llmax % ll;
967                   }''', name : 'long long')
968   glib_conf.set('HAVE_LONG_LONG', 1)
969   have_long_long = true
970 else
971   have_long_long = false
972 endif
974 # Test whether the compiler supports the 'long double' type.
975 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it.  */
976                   long double foo = 0.0;
977                   /* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
978                   int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
979                name : 'long double')
980   glib_conf.set('HAVE_LONG_DOUBLE', 1)
981 endif
983 # Test whether <stddef.h> has the 'wchar_t' type.
984 if cc.has_header_symbol('stddef.h', 'wchar_t')
985   glib_conf.set('HAVE_WCHAR_T', 1)
986 endif
988 # Test whether <wchar.h> has the 'wint_t' type.
989 if cc.has_header_symbol('wchar.h', 'wint_t')
990   glib_conf.set('HAVE_WINT_T', 1)
991 endif
993 found_uintmax_t = false
995 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
996 # doesn't clash with <sys/types.h>, and declares uintmax_t.
997 # jm_AC_HEADER_INTTYPES_H
998 if cc.compiles('''#include <sys/types.h>
999                   #include <inttypes.h>
1000                   void some_func (void) {
1001                     uintmax_t i = (uintmax_t) -1;
1002                   }''', name : 'uintmax_t in inttypes.h')
1003   glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1004   found_uintmax_t = true
1005 endif
1007 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1008 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1009 # jm_AC_HEADER_STDINT_H
1010 if cc.compiles('''#include <sys/types.h>
1011                   #include <stdint.h>
1012                   void some_func (void) {
1013                     uintmax_t i = (uintmax_t) -1;
1014                   }''', name : 'uintmax_t in stdint.h')
1015   glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1016   found_uintmax_t = true
1017 endif
1019 # Define intmax_t to 'long' or 'long long'
1020 # if it is not already defined in <stdint.h> or <inttypes.h>.
1021 # For simplicity, we assume that a header file defines 'intmax_t' if and
1022 # only if it defines 'uintmax_t'.
1023 if found_uintmax_t
1024   glib_conf.set('HAVE_INTMAX_T', 1)
1025 elif have_long_long
1026   glib_conf.set('intmax_t', 'long long')
1027 else
1028   glib_conf.set('intmax_t', 'long')
1029 endif
1031 char_size = cc.sizeof('char')
1032 short_size = cc.sizeof('short')
1033 int_size = cc.sizeof('int')
1034 voidp_size = cc.sizeof('void*')
1035 long_size = cc.sizeof('long')
1036 if have_long_long
1037   long_long_size = cc.sizeof('long long')
1038 else
1039   long_long_size = 0
1040 endif
1041 sizet_size = cc.sizeof('size_t')
1042 if cc.get_id() == 'msvc'
1043   ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1044 else
1045   ssizet_size = cc.sizeof('ssize_t')
1046 endif
1048 int64_m = 'll'
1049 char_align = cc.alignment('char')
1050 short_align = cc.alignment('short')
1051 int_align = cc.alignment('int')
1052 voidp_align = cc.alignment('void*')
1053 long_align = cc.alignment('long')
1054 long_long_align = cc.alignment('long long')
1055 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1056 # be 64-bit in C99, and it is available on all supported compilers
1057 sizet_align = cc.alignment('size_t')
1059 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1061 glib_conf.set('SIZEOF_CHAR', char_size)
1062 glib_conf.set('SIZEOF_INT', int_size)
1063 glib_conf.set('SIZEOF_SHORT', short_size)
1064 glib_conf.set('SIZEOF_LONG', long_size)
1065 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1066 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1067 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1068 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1070 if short_size == 2
1071   gint16 = 'short'
1072   gint16_modifier='h'
1073   gint16_format='hi'
1074   guint16_format='hu'
1075 elif int_size == 2
1076   gint16 = 'int'
1077   gint16_modifier=''
1078   gint16_format='i'
1079   guint16_format='u'
1080 else
1081   error('Compiler provides no native 16-bit integer type')
1082 endif
1083 glibconfig_conf.set('gint16', gint16)
1084 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1085 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1086 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1088 if short_size == 4
1089   gint32 = 'short'
1090   gint32_modifier='h'
1091   gint32_format='hi'
1092   guint32_format='hu'
1093   guint32_align = short_align
1094 elif int_size == 4
1095   gint32 = 'int'
1096   gint32_modifier=''
1097   gint32_format='i'
1098   guint32_format='u'
1099   guint32_align = int_align
1100 elif long_size == 4
1101   gint32 = 'long'
1102   gint32_modifier='l'
1103   gint32_format='li'
1104   guint32_format='lu'
1105   guint32_align = long_align
1106 else
1107   error('Compiler provides no native 32-bit integer type')
1108 endif
1109 glibconfig_conf.set('gint32', gint32)
1110 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1111 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1112 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1113 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1115 if int_size == 8
1116   gint64 = 'int'
1117   gint64_modifier=''
1118   gint64_format='i'
1119   guint64_format='u'
1120   glib_extension=''
1121   gint64_constant='(val)'
1122   guint64_constant='(val)'
1123   guint64_align = int_align
1124 elif long_size == 8
1125   gint64 = 'long'
1126   glib_extension=''
1127   gint64_modifier='l'
1128   gint64_format='li'
1129   guint64_format='lu'
1130   gint64_constant='(val##L)'
1131   guint64_constant='(val##UL)'
1132   guint64_align = long_align
1133 elif long_long_size == 8
1134   gint64 = 'long long'
1135   glib_extension='G_GNUC_EXTENSION '
1136   gint64_modifier=int64_m
1137   gint64_format=int64_m + 'i'
1138   guint64_format=int64_m + 'u'
1139   gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1140   guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1141   guint64_align = long_long_align
1142 else
1143   error('Compiler provides no native 64-bit integer type')
1144 endif
1145 glibconfig_conf.set('glib_extension', glib_extension)
1146 glibconfig_conf.set('gint64', gint64)
1147 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1148 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1149 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1150 glibconfig_conf.set('gint64_constant', gint64_constant)
1151 glibconfig_conf.set('guint64_constant', guint64_constant)
1152 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1154 if host_system == 'windows'
1155   glibconfig_conf.set('g_pid_type', 'void*')
1156   glibconfig_conf.set_quoted('g_pid_format', 'p')
1157   if host_machine.cpu_family() == 'x86_64'
1158     glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1159   else
1160     glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1161   endif
1162   glibconfig_conf.set('g_dir_separator', '\\\\')
1163   glibconfig_conf.set('g_searchpath_separator', ';')
1164 else
1165   glibconfig_conf.set('g_pid_type', 'int')
1166   glibconfig_conf.set_quoted('g_pid_format', 'i')
1167   glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1168   glibconfig_conf.set('g_dir_separator', '/')
1169   glibconfig_conf.set('g_searchpath_separator', ':')
1170 endif
1172 if sizet_size == short_size
1173   glibconfig_conf.set('glib_size_type_define', 'short')
1174   glibconfig_conf.set_quoted('gsize_modifier', 'h')
1175   glibconfig_conf.set_quoted('gssize_modifier', 'h')
1176   glibconfig_conf.set_quoted('gsize_format', 'hu')
1177   glibconfig_conf.set_quoted('gssize_format', 'hi')
1178   glibconfig_conf.set('glib_msize_type', 'SHRT')
1179 elif sizet_size == int_size
1180   glibconfig_conf.set('glib_size_type_define', 'int')
1181   glibconfig_conf.set_quoted('gsize_modifier', '')
1182   glibconfig_conf.set_quoted('gssize_modifier', '')
1183   glibconfig_conf.set_quoted('gsize_format', 'u')
1184   glibconfig_conf.set_quoted('gssize_format', 'i')
1185   glibconfig_conf.set('glib_msize_type', 'INT')
1186 elif sizet_size == long_size
1187   glibconfig_conf.set('glib_size_type_define', 'long')
1188   glibconfig_conf.set_quoted('gsize_modifier', 'l')
1189   glibconfig_conf.set_quoted('gssize_modifier', 'l')
1190   glibconfig_conf.set_quoted('gsize_format', 'lu')
1191   glibconfig_conf.set_quoted('gssize_format', 'li')
1192   glibconfig_conf.set('glib_msize_type', 'LONG')
1193 elif sizet_size == long_long_size
1194   glibconfig_conf.set('glib_size_type_define', 'long long')
1195   glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1196   glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1197   glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1198   glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1199   glibconfig_conf.set('glib_msize_type', 'INT64')
1200 else
1201   error('Could not determine size of size_t.')
1202 endif
1204 if voidp_size == int_size
1205   glibconfig_conf.set('glib_intptr_type_define', 'int')
1206   glibconfig_conf.set_quoted('gintptr_modifier', '')
1207   glibconfig_conf.set_quoted('gintptr_format', 'i')
1208   glibconfig_conf.set_quoted('guintptr_format', 'u')
1209   glibconfig_conf.set('glib_gpi_cast', '(gint)')
1210   glibconfig_conf.set('glib_gpui_cast', '(guint)')
1211 elif voidp_size == long_size
1212   glibconfig_conf.set('glib_intptr_type_define', 'long')
1213   glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1214   glibconfig_conf.set_quoted('gintptr_format', 'li')
1215   glibconfig_conf.set_quoted('guintptr_format', 'lu')
1216   glibconfig_conf.set('glib_gpi_cast', '(glong)')
1217   glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1218 elif voidp_size == long_long_size
1219   glibconfig_conf.set('glib_intptr_type_define', 'long long')
1220   glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1221   glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1222   glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1223   glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1224   glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1225 else
1226   error('Could not determine size of void *')
1227 endif
1229 if long_size != 8 and long_long_size != 8 and int_size != 8
1230   error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1231 endif
1233 glibconfig_conf.set('gintbits', int_size * 8)
1234 glibconfig_conf.set('glongbits', long_size * 8)
1235 glibconfig_conf.set('gsizebits', sizet_size * 8)
1236 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1238 # FIXME: maybe meson should tell us the libsuffix?
1239 if host_system == 'windows'
1240   g_module_suffix = 'dll'
1241 elif host_system == 'darwin'
1242   g_module_suffix = 'dylib'
1243 else
1244   g_module_suffix = 'so'
1245 endif
1246 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1248 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1249 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1250 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1251 glibconfig_conf.set('GLIB_VERSION', glib_version)
1253 glibconfig_conf.set('glib_void_p', voidp_size)
1254 glibconfig_conf.set('glib_long', long_size)
1255 glibconfig_conf.set('glib_size_t', sizet_size)
1256 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1257 if host_machine.endian() == 'big'
1258   glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1259   glibconfig_conf.set('g_bs_native', 'BE')
1260   glibconfig_conf.set('g_bs_alien', 'LE')
1261 else
1262   glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1263   glibconfig_conf.set('g_bs_native', 'LE')
1264   glibconfig_conf.set('g_bs_alien', 'BE')
1265 endif
1267 # === va_copy checks ===
1268 # we currently check for all three va_copy possibilities, so we get
1269 # all results in config.log for bug reports.
1271 va_copy_func = ''
1272 foreach try_func : [ '__va_copy', 'va_copy' ]
1273   if cc.compiles('''#include <stdarg.h>
1274                     #include <stdlib.h>
1275                     #ifdef _MSC_VER
1276                     # include "msvc_recommended_pragmas.h"
1277                     #endif
1278                     void f (int i, ...) {
1279                     va_list args1, args2;
1280                     va_start (args1, i);
1281                     @0@ (args2, args1);
1282                     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1283                       exit (1);
1284                     va_end (args1); va_end (args2);
1285                     }
1286                     int main() {
1287                       f (0, 42);
1288                       return 0;
1289                     }'''.format(try_func),
1290                     name : try_func + ' check')
1291     va_copy_func = try_func
1292   endif
1293 endforeach
1294 if va_copy_func != ''
1295   glib_conf.set('G_VA_COPY', va_copy_func)
1296   glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1297 else
1298   glib_vacopy = '/* #undef G_VA_COPY */'
1299 endif
1301 va_list_val_copy_prog = '''
1302   #include <stdarg.h>
1303   #include <stdlib.h>
1304   void f (int i, ...) {
1305     va_list args1, args2;
1306     va_start (args1, i);
1307     args2 = args1;
1308     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1309       exit (1);
1310     va_end (args1); va_end (args2);
1311   }
1312   int main() {
1313     f (0, 42);
1314     return 0;
1315   }'''
1317 if cc_can_run
1318   rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1319   glib_va_val_copy = rres.returncode() == 0
1320 else
1321   glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
1322 endif
1323 if not glib_va_val_copy
1324   glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1325   glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1326 endif
1327 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1329 # check for flavours of varargs macros
1330 g_have_iso_c_varargs = cc.compiles('''
1331   void some_func (void) {
1332     int a(int p1, int p2, int p3);
1333     #define call_a(...) a(1,__VA_ARGS__)
1334     call_a(2,3);
1335   }''', name : 'ISO C99 varargs macros in C')
1337 if g_have_iso_c_varargs
1338   glibconfig_conf.set('g_have_iso_c_varargs', '''
1339 #ifndef __cplusplus
1340 # define G_HAVE_ISO_VARARGS 1
1341 #endif''')
1342 endif
1344 g_have_iso_cxx_varargs = cxx.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_cxx_varargs
1352   glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1353 #ifdef __cplusplus
1354 # define G_HAVE_ISO_VARARGS 1
1355 #endif''')
1356 endif
1358 g_have_gnuc_varargs = cc.compiles('''
1359   void some_func (void) {
1360     int a(int p1, int p2, int p3);
1361     #define call_a(params...) a(1,params)
1362     call_a(2,3);
1363   }''', name : 'GNUC varargs macros')
1365 if cc.has_header('alloca.h')
1366   glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1367 endif
1368 has_syspoll = cc.has_header('sys/poll.h')
1369 has_systypes = cc.has_header('sys/types.h')
1370 if has_syspoll
1371   glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1372 endif
1373 has_winsock2 = cc.has_header('winsock2.h')
1375 if has_syspoll and has_systypes
1376   poll_includes = '''
1377       #include<sys/poll.h>
1378       #include<sys/types.h>'''
1379 elif has_winsock2
1380   poll_includes = '''
1381       #define _WIN32_WINNT @0@
1382       #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1383 else
1384   # FIXME?
1385   error('FIX POLL* defines')
1386 endif
1388 poll_defines = [
1389   [ 'POLLIN', 'g_pollin', 1 ],
1390   [ 'POLLOUT', 'g_pollout', 4 ],
1391   [ 'POLLPRI', 'g_pollpri', 2 ],
1392   [ 'POLLERR', 'g_pollerr', 8 ],
1393   [ 'POLLHUP', 'g_pollhup', 16 ],
1394   [ 'POLLNVAL', 'g_pollnval', 32 ],
1397 if has_syspoll and has_systypes
1398   foreach d : poll_defines
1399     val = cc.compute_int(d[0], prefix: poll_includes)
1400     glibconfig_conf.set(d[1], val)
1401   endforeach
1402 elif has_winsock2
1403   # Due to a missed bug in configure.ac the poll test
1404   # never succeeded on Windows and used some pre-defined
1405   # values as a fallback. Keep using them to maintain
1406   # ABI compatibility with autotools builds of glibs
1407   # and with *any* glib-using code compiled against them,
1408   # since these values end up in a public header glibconfig.h.
1409   foreach d : poll_defines
1410     glibconfig_conf.set(d[1], d[2])
1411   endforeach
1412 endif
1414 # Internet address families
1415 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1416 if host_system == 'windows'
1417   inet_includes = '''
1418       #include <winsock2.h>'''
1419 else
1420   inet_includes = '''
1421       #include <sys/types.h>
1422       #include <sys/socket.h>'''
1423 endif
1425 inet_defines = [
1426   [ 'AF_UNIX', 'g_af_unix' ],
1427   [ 'AF_INET', 'g_af_inet' ],
1428   [ 'AF_INET6', 'g_af_inet6' ],
1429   [ 'MSG_OOB', 'g_msg_oob' ],
1430   [ 'MSG_PEEK', 'g_msg_peek' ],
1431   [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1433 foreach d : inet_defines
1434   val = cc.compute_int(d[0], prefix: inet_includes)
1435   glibconfig_conf.set(d[1], val)
1436 endforeach
1438 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', true) # FIXME!
1440 # We need a more robust approach here...
1441 host_cpu_family = host_machine.cpu_family()
1442 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')
1443   glib_memory_barrier_needed = false
1444 elif host_cpu_family.startswith('sparc') or host_cpu_family.startswith('alpha') or host_cpu_family.startswith('powerpc') or host_cpu_family == 'ia64'
1445   glib_memory_barrier_needed = true
1446 else
1447   warning('Unknown host cpu: ' + host_cpu_family)
1448   glib_memory_barrier_needed = true
1449 endif
1450 glibconfig_conf.set('G_ATOMIC_OP_MEMORY_BARRIER_NEEDED', glib_memory_barrier_needed)
1452 # We need to decide at configure time if GLib will use real atomic
1453 # operations ("lock free") or emulated ones with a mutex.  This is
1454 # because we must put this information in glibconfig.h so we know if
1455 # it is safe or not to inline using compiler intrinsics directly from
1456 # the header.
1458 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1459 # user is interested in knowing if they can use the atomic ops across
1460 # processes.
1462 # We can currently support the atomic ops natively when building GLib
1463 # with recent versions of GCC or MSVC.
1465 # Note that the atomic ops are only available with GCC on x86 when
1466 # using -march=i486 or higher.  If we detect that the atomic ops are
1467 # not available but would be available given the right flags, we want
1468 # to abort and advise the user to fix their CFLAGS.  It's better to do
1469 # that then to silently fall back on emulated atomic ops just because
1470 # the user had the wrong build environment.
1471 atomictest = '''int main() {
1472   volatile int atomic = 2;
1473   __sync_bool_compare_and_swap (&atomic, 2, 3);
1474   return 0;
1478 atomicdefine = '''
1479 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1480 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1481 #endif
1484 # We know that we can always use real ("lock free") atomic operations with MSVC
1485 if cc.get_id() == 'msvc' or cc.links(atomictest, name : 'atomic ops')
1486   have_atomic_lock_free = true
1487   if host_system == 'android' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1488     # When building for armv5 on Android, gcc 4.9 provides
1489     # __sync_bool_compare_and_swap but doesn't define
1490     # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1491     glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1492   endif
1493 else
1494   have_atomic_lock_free = false
1495   if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1496     error('GLib must be built with -march=i486 or later.')
1497   endif
1498 endif
1499 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1501 # === Threads ===
1503 # Determination of thread implementation
1504 if host_system == 'windows' and not get_option('force_posix_threads')
1505   thread_dep = []
1506   threads_implementation = 'win32'
1507   glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1508   glib_conf.set('THREADS_WIN32', 1)
1509 else
1510   # FIXME: probably needs more tweaking in meson for things like -D_REENTRANT etc.
1511   thread_dep = dependency('threads')
1512   threads_implementation = 'posix'
1513   pthread_prefix = '''
1514       #ifndef _GNU_SOURCE
1515       # define _GNU_SOURCE
1516       #endif
1517       #include <pthread.h>'''
1518   glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1519   glib_conf.set('THREADS_POSIX', 1)
1520   if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1521     glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1522   endif
1523   if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1524     glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1525   endif
1526   if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1527     glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1528   endif
1529   if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1530     glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1531   endif
1532   # Assume that pthread_setname_np is available in some form; same as configure
1533   if cc.links(pthread_prefix + '''
1534               int main() {
1535                 pthread_setname_np("example");
1536                 return 0;
1537               }''',
1538               name : 'pthread_setname_np(const char*)',
1539               dependencies : thread_dep)
1540     # macOS and iOS
1541     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1542   elif cc.links(pthread_prefix + '''
1543                 int main() {
1544                   pthread_setname_np(pthread_self(), "example");
1545                   return 0;
1546                 }''',
1547                 name : 'pthread_setname_np(pthread_t, const char*)',
1548                 dependencies : thread_dep)
1549     # Linux, Solaris, etc.
1550     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1551   endif
1552 endif
1554 # FIXME: we should make it print the result and always return 0, so that
1555 # the output in meson shows up as green
1556 stack_grows_check_prog = '''
1557   volatile int *a = 0, *b = 0;
1558   void f (int i) {
1559     volatile int x = 5;
1560     if (i == 0)
1561       b = &x;
1562     else
1563       f (i - 1);
1564   }
1565   int main () {
1566     volatile int y = 7;
1567     a = &y;
1568     f (100);
1569     return b > a ? 0 : 1;
1570   }'''
1572 if cc_can_run
1573   rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
1574   growing_stack = rres.returncode() == 0
1575 else
1576   growing_stack = meson.get_cross_property('growing_stack', false)
1577 endif
1579 glibconfig_conf.set('G_HAVE_GROWING_STACK', growing_stack)
1581 # Tests for iconv
1583 # USE_LIBICONV_GNU: Using GNU libiconv
1584 # USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library
1586 # We should never use the MinGW C library's iconv. On Windows we use the
1587 # GNU implementation that ships with MinGW.
1589 # On Windows, just always use the built-in implementation
1590 if host_system == 'windows'
1591   libiconv = []
1592   glib_conf.set('USE_LIBICONV_NATIVE', true)
1593 else
1594   found_iconv = false
1595   iconv_opt = get_option('iconv')
1596   if iconv_opt == 'libc'
1597     if cc.has_function('iconv_open')
1598       libiconv = []
1599       found_iconv = true
1600     endif
1601   elif iconv_opt == 'gnu'
1602     if cc.has_header_symbol('iconv.h', 'libiconv_open')
1603       glib_conf.set('USE_LIBICONV_GNU', true)
1604       libiconv = [cc.find_library('iconv')]
1605       found_iconv = true
1606     endif
1607   elif iconv_opt == 'native'
1608     if cc.has_header_symbol('iconv.h', 'iconv_open')
1609       glib_conf.set('USE_LIBICONV_NATIVE', true)
1610       libiconv = [cc.find_library('iconv')]
1611       found_iconv = true
1612     endif
1613   endif
1615   if not found_iconv
1616     error('iconv implementation "@0@" not found'.format(iconv_opt))
1617   endif
1619 endif
1621 if get_option('internal_pcre')
1622   pcre = []
1623   use_system_pcre = false
1624 else
1625   pcre = dependency('libpcre', required : false) # Should check for Unicode support, too. FIXME
1626   if not pcre.found()
1627     if cc.get_id() == 'msvc'
1628     # MSVC: Search for the PCRE library by the configuration, which corresponds
1629     # to the output of CMake builds of PCRE.  Note that debugoptimized
1630     # is really a Release build with .PDB files.
1631       if buildtype == 'debug'
1632         pcre = cc.find_library('pcred', required : false)
1633       else
1634         pcre = cc.find_library('pcre', required : false)
1635       endif
1636     endif
1637   endif
1638   use_system_pcre = pcre.found()
1639 endif
1640 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1642 use_pcre_static_flag = false
1644 if host_system == 'windows'
1645   if not use_system_pcre
1646     use_pcre_static_flag = true
1647   else
1648     pcre_static = cc.links('''#define PCRE_STATIC
1649                               #include <pcre.h>
1650                               int main() {
1651                                 void *p = NULL;
1652                                 pcre_free(p);
1653                                 return 0;
1654                               }''',
1655                            dependencies: pcre,
1656                            name : 'Windows system PCRE is a static build')
1657     if pcre_static
1658       use_pcre_static_flag = true
1659     endif
1660   endif
1661 endif
1663 libm = cc.find_library('m', required : false)
1664 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
1665 if cc.get_id() != 'msvc'
1666   libz_dep = dependency('zlib', fallback : ['zlib', 'zlib_dep'])
1667 else
1668   # MSVC: Don't use the bundled ZLib sources until we are sure that we can't
1669   # find the ZLib .lib
1670   libz_dep = dependency('zlib', required : false)
1672   # MSVC: Search for the ZLib .lib, which corresponds to the results of
1673   # of using ZLib's win32/makefile.msc.
1674   if not libz_dep.found()
1675     libz_dep = cc.find_library('zlib1', required : false)
1676     if not libz_dep.found()
1677       libz_dep = cc.find_library('zlib', required : false)
1678       if not libz_dep.found()
1679         libz_dep = subproject('zlib').get_variable('zlib_dep')
1680       endif
1681     endif
1682   endif
1683 endif
1685 # First check in libc, fallback to libintl, and as last chance build
1686 # proxy-libintl subproject.
1687 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
1688 # implementations. This could be extended if issues are found in some platforms.
1689 if cc.has_function('ngettext')
1690   libintl = []
1691 else
1692   libintl = cc.find_library('intl', required : false)
1693   if not libintl.found()
1694     libintl = subproject('proxy-libintl').get_variable('intl_dep')
1695   endif
1696 endif
1698 # We require gettext to always be present
1699 glib_conf.set('HAVE_DCGETTEXT', 1)
1700 glib_conf.set('HAVE_GETTEXT', 1)
1702 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
1703 # xgettext is optional (on Windows for instance)
1704 xgettext = find_program('xgettext', required : false)
1706 # libmount is only used by gio, but we need to fetch the libs to generate the
1707 # pkg-config file below
1708 libmount_dep = []
1709 if host_system == 'linux' and get_option('libmount')
1710   libmount_dep = [dependency('mount', version : '>=2.23', required : true)]
1711   glib_conf.set('HAVE_LIBMOUNT', 1)
1712 endif
1714 if host_system == 'windows'
1715   winsock2 = cc.find_library('ws2_32')
1716 endif
1718 selinux_dep = []
1719 if host_system == 'linux' and get_option('selinux')
1720   selinux_dep = [dependency('libselinux')]
1721   glib_conf.set('HAVE_SELINUX', 1)
1722 endif
1724 xattr_dep = []
1725 if host_system != 'windows' and get_option('xattr')
1726   # either glibc or libattr can provide xattr support
1727   # for both of them, we check for getxattr being in
1728   # the library and a valid xattr header.
1730   # try glibc
1731   if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
1732     glib_conf.set('HAVE_SYS_XATTR_H', 1)
1733     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
1734   #failure. try libattr
1735   elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
1736     glib_conf.set('HAVE_ATTR_XATTR_H', 1)
1737     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
1738     xattr_dep = [cc.find_library('xattr')]
1739   else
1740     error('No getxattr implementation found in C library or libxattr')
1741   endif
1743   glib_conf.set('HAVE_XATTR', 1)
1744   if cc.compiles(glib_conf_prefix + '''
1745                  #include <stdio.h>
1746                  #ifdef HAVE_SYS_TYPES_H
1747                  #include <sys/types.h>
1748                  #endif
1749                  #ifdef HAVE_SYS_XATTR_H
1750                  #include <sys/xattr.h>
1751                  #elif HAVE_ATTR_XATTR_H
1752                  #include <attr/xattr.h>
1753                  #endif
1755                  int main (void) {
1756                    ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
1757                    return len;
1758                  }''',
1759                  name : 'XATTR_NOFOLLOW')
1760     glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
1761   endif
1762 endif
1764 python = import('python3').find_python()
1766 # Determine which user environment-dependent files that we want to install
1767 have_bash = find_program('bash', required : false).found() # For completion scripts
1768 have_m4 = find_program('m4', required : false).found() # For m4 macros
1769 have_sh = find_program('sh', required : false).found() # For glib-gettextize
1771 # FIXME: defines in config.h that are not actually used anywhere
1772 # (we add them for now to minimise the diff)
1773 glib_conf.set('HAVE_DLFCN_H', 1)
1774 glib_conf.set('STDC_HEADERS', 1)
1775 # THREADS_NONE
1776 glib_conf.set('SIZEOF___INT64', 8)
1778 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
1779 if host_system == 'sunos'
1780   glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
1781   glib_conf.set('_XOPEN_SOURCE', 2)
1782   glib_conf.set('__EXTENSIONS__',1)
1783 endif
1785 # Sadly Meson does not expose this value:
1786 # https://github.com/mesonbuild/meson/pull/3460
1787 if host_system == 'windows'
1788   # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
1789   # with no explanation. Do the same here for now but this could be revisited if
1790   # if causes issues.
1791   export_dynamic_ldflags = []
1792 elif host_system == 'cygwin'
1793   export_dynamic_ldflags = ['-Wl,--export-all-symbols']
1794 elif host_system == 'darwin'
1795   export_dynamic_ldflags = []
1796 else
1797   export_dynamic_ldflags = ['-Wl,--export-dynamic']
1798 endif
1800 win32_cflags = []
1801 win32_ldflags = []
1802 if host_system == 'windows' and cc.get_id() != 'msvc'
1803   # Ensure MSVC-compatible struct packing convention is used when
1804   # compiling for Win32 with gcc. It is used for the whole project and exposed
1805   # in glib-2.0.pc.
1806   win32_cflags = ['-mms-bitfields']
1807   add_project_arguments(win32_cflags, language : 'c')
1809   # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
1810   win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi']
1811 elif host_system == 'cygwin'
1812   win32_ldflags = ['-luser32', '-lkernel32']
1813 endif
1815 # Tracing: dtrace
1816 want_dtrace = get_option('dtrace')
1817 enable_dtrace = false
1819 # Since dtrace support is opt-in we just error out if it was requested but
1820 # is not available. We don't bother with autodetection yet.
1821 if want_dtrace
1822   if glib_have_carbon
1823     error('GLib dtrace support not yet compatible with macOS dtrace')
1824   endif
1825   dtrace = find_program('dtrace', required : true) # error out if not found
1826   if not cc.has_header('sys/sdt.h')
1827     error('dtrace support needs sys/sdt.h header')
1828   endif
1829   # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
1830   dtrace_obj_gen = generator(dtrace,
1831     output : '@BASENAME@.o',
1832     arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1833   # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
1834   #               -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
1835   dtrace_hdr_gen = generator(dtrace,
1836     output : '@BASENAME@.h',
1837     arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1838   glib_conf.set('HAVE_DTRACE', 1)
1839   enable_dtrace = true
1840 endif
1842 # systemtap
1843 want_systemtap = get_option('systemtap')
1844 enable_systemtap = false
1846 if want_systemtap and enable_dtrace
1847   tapset_install_dir = get_option('tapset_install_dir')
1848   if tapset_install_dir == ''
1849     tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
1850   endif
1851   stp_cdata = configuration_data()
1852   stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
1853   stp_cdata.set('LT_CURRENT', minor_version * 100)
1854   stp_cdata.set('LT_REVISION', micro_version)
1855   enable_systemtap = true
1856 endif
1859 pkg = import('pkgconfig')
1860 windows = import('windows')
1861 subdir('glib')
1862 subdir('gobject')
1863 subdir('gthread')
1864 subdir('gmodule')
1865 subdir('gio')
1866 if xgettext.found()
1867   subdir('po')
1868 endif
1869 subdir('tests')
1871 # Install glib-gettextize executable, if a UNIX-style shell is found
1872 if have_sh
1873   # These should not contain " quotes around the values
1874   gettexize_conf = configuration_data()
1875   gettexize_conf.set('PACKAGE', 'glib')
1876   gettexize_conf.set('VERSION', meson.project_version())
1877   gettexize_conf.set('prefix', glib_prefix)
1878   gettexize_conf.set('datarootdir', glib_datadir)
1879   gettexize_conf.set('datadir', glib_datadir)
1880   configure_file(input : 'glib-gettextize.in',
1881     install : true,
1882     install_dir : 'bin',
1883     output : 'glib-gettextize',
1884     configuration : gettexize_conf)
1885 endif
1887 if have_m4
1888   # Install m4 macros that other projects use
1889   install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
1890     install_dir : join_paths(get_option('datadir'), 'aclocal'))
1891 endif
1893 if host_system != 'windows'
1894   # Install Valgrind suppression file (except on Windows,
1895   # as Valgrind is currently not supported on Windows)
1896   install_data('glib.supp',
1897     install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
1898 endif
1900 configure_file(output : 'config.h', configuration : glib_conf)
1902 if host_system == 'windows'
1903   install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
1904 endif
1906 if get_option('man')
1907   xsltproc = find_program('xsltproc', required : true)
1908   xsltproc_command = [
1909     xsltproc,
1910     '--nonet',
1911     '--stringparam', 'man.output.quietly', '1',
1912     '--stringparam', 'funcsynopsis.style', 'ansi',
1913     '--stringparam', 'man.th.extra1.suppress', '1',
1914     '--stringparam', 'man.authors.section.enabled', '0',
1915     '--stringparam', 'man.copyright.section.enabled', '0',
1916     '-o', '@OUTPUT@',
1917     'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
1918     '@INPUT@',
1919   ]
1920   man1_dir = get_option('mandir') + '/man1'
1921 endif
1923 gnome = import('gnome')
1924 subdir('docs/reference/glib')
1925 subdir('docs/reference/gobject')
1926 subdir('docs/reference/gio')