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