Imported Upstream version 2.68.3
[platform/upstream/glib.git] / meson.build
1 project('glib', 'c', 'cpp',
2   version : '2.68.3',
3   # NOTE: We keep this pinned at 0.49 because that's what Debian 10 ships
4   meson_version : '>= 0.49.2',
5   default_options : [
6     'buildtype=debugoptimized',
7     'warning_level=1',
8     'c_std=gnu99'
9   ]
10 )
11
12 cc = meson.get_compiler('c')
13 cxx = meson.get_compiler('cpp')
14
15 cc_can_run = not meson.is_cross_build() or meson.has_exe_wrapper()
16
17 if cc.get_id() == 'msvc'
18   # Ignore several spurious warnings for things glib does very commonly
19   # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
20   # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
21   # NOTE: Only add warnings here if you are sure they're spurious
22   add_project_arguments('/wd4035', '/wd4715', '/wd4116',
23     '/wd4046', '/wd4068', '/wo4090', '/FImsvc_recommended_pragmas.h',language : 'c')
24   # Disable SAFESEH with MSVC for plugins and libs that use external deps that
25   # are built with MinGW
26   noseh_link_args = ['/SAFESEH:NO']
27   # Set the input and exec encoding to utf-8, like is the default with GCC
28   add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c')
29 else
30   noseh_link_args = []
31   # -mms-bitfields vs -fnative-struct ?
32 endif
33
34 host_system = host_machine.system()
35
36 if host_system == 'darwin'
37   ios_test_code = '''#include <TargetConditionals.h>
38   #if ! TARGET_OS_IPHONE
39   #error "Not iOS/tvOS/watchOS/iPhoneSimulator"
40   #endif'''
41   if cc.compiles(ios_test_code, name : 'building for iOS')
42     host_system = 'ios'
43   endif
44 endif
45
46 glib_version = meson.project_version()
47 glib_api_version = '2.0'
48 version_arr = glib_version.split('.')
49 major_version = version_arr[0].to_int()
50 minor_version = version_arr[1].to_int()
51 micro_version = version_arr[2].to_int()
52
53 interface_age = minor_version.is_odd() ? 0 : micro_version
54 binary_age = 100 * minor_version + micro_version
55
56 soversion = 0
57 # Maintain compatibility with previous libtool versioning
58 # current = minor * 100 + micro
59 current = binary_age - interface_age
60 library_version = '@0@.@1@.@2@'.format(soversion, current, interface_age)
61 darwin_versions = [current + 1, '@0@.@1@'.format(current + 1, interface_age)]
62
63 configinc = include_directories('.')
64 glibinc = include_directories('glib')
65 gobjectinc = include_directories('gobject')
66 gmoduleinc = include_directories('gmodule')
67 gioinc = include_directories('gio')
68
69 glib_prefix = get_option('prefix')
70 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
71 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
72 glib_libexecdir = join_paths(glib_prefix, get_option('libexecdir'))
73 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
74 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
75 glib_includedir = join_paths(glib_prefix, get_option('includedir'))
76 if get_option('gio_module_dir') != ''
77   glib_giomodulesdir = join_paths(glib_prefix, get_option('gio_module_dir'))
78 else
79   glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
80 endif
81
82 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
83
84 if get_option('charsetalias_dir') != ''
85   glib_charsetaliasdir = join_paths(glib_prefix, get_option('charsetalias_dir'))
86 else
87   glib_charsetaliasdir = glib_libdir
88 endif
89
90 glib_localstatedir = get_option('localstatedir')
91 if not glib_localstatedir.startswith('/')
92   # See https://mesonbuild.com/Builtin-options.html#directories
93   glib_localstatedir = join_paths(glib_prefix, glib_localstatedir)
94 endif
95
96 installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
97 installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
98 installed_tests_enabled = get_option('installed_tests')
99 installed_tests_template = files('template.test.in')
100 installed_tests_template_tap = files('template-tap.test.in')
101
102 # Don’t build the tests unless we can run them (either natively, in an exe wrapper, or by installing them for later use)
103 build_tests = get_option('tests') and (not meson.is_cross_build() or (meson.is_cross_build() and meson.has_exe_wrapper()) or installed_tests_enabled)
104
105 add_project_arguments('-D_GNU_SOURCE', language: 'c')
106
107 if host_system == 'qnx'
108   add_project_arguments('-D_QNX_SOURCE', language: 'c')
109 endif
110
111 # Disable strict aliasing;
112 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
113 if cc.has_argument('-fno-strict-aliasing')
114   add_project_arguments('-fno-strict-aliasing', language: 'c')
115 endif
116
117 ########################
118 # Configuration begins #
119 ########################
120 glib_conf = configuration_data()
121 glibconfig_conf = configuration_data()
122
123 # accumulated list of defines as we check for them, so we can easily
124 # use them later in test programs (autoconf does this automatically)
125 glib_conf_prefix = ''
126
127 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
128 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
129 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
130 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
131 glib_conf.set('GLIB_BINARY_AGE', binary_age)
132 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
133 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
134 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
135 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
136 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
137 glib_conf.set_quoted('PACKAGE_URL', '')
138 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
139 glib_conf.set('ENABLE_NLS', 1)
140
141 # used by the .rc.in files
142 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
143
144 glib_conf.set('_GNU_SOURCE', 1)
145
146 if host_system == 'windows'
147   # Poll doesn't work on devices on Windows
148   glib_conf.set('BROKEN_POLL', true)
149 endif
150
151 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
152   # FIXME: Ideally we shouldn't depend on this on Windows and should use
153   # 64 bit capable Windows API that also works with MSVC.
154   # The autotools build did set this for mingw and while meson sets it
155   # for gcc/clang by default, it doesn't do so on Windows.
156   glib_conf.set('_FILE_OFFSET_BITS', 64)
157 endif
158
159 # Check for GNU visibility attributes
160 g_have_gnuc_visibility = cc.compiles('''
161   void
162   __attribute__ ((visibility ("hidden")))
163        f_hidden (void)
164   {
165   }
166   void
167   __attribute__ ((visibility ("internal")))
168        f_internal (void)
169   {
170   }
171   void
172   __attribute__ ((visibility ("default")))
173        f_default (void)
174   {
175   }
176   int main (void)
177   {
178     f_hidden();
179     f_internal();
180     f_default();
181     return 0;
182   }
183   ''',
184   # Not supported by MSVC, but MSVC also won't support visibility,
185   # so it's OK to pass -Werror explicitly. Replace with
186   # override_options : 'werror=true' once that is supported
187   args: ['-Werror'],
188   name : 'GNU C visibility attributes test')
189
190 if g_have_gnuc_visibility
191   glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
192 endif
193
194 # Detect and set symbol visibility
195 glib_hidden_visibility_args = []
196 if get_option('default_library') != 'static'
197   if host_system == 'windows' or host_system == 'cygwin'
198     glib_conf.set('DLL_EXPORT', true)
199     if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
200       glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
201     elif cc.has_argument('-fvisibility=hidden')
202       glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
203       glib_hidden_visibility_args = ['-fvisibility=hidden']
204     endif
205   elif cc.has_argument('-fvisibility=hidden')
206     glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
207     glib_hidden_visibility_args = ['-fvisibility=hidden']
208   endif
209 endif
210
211 if get_option('default_library') == 'static'
212     glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
213     glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
214 endif
215
216 # Cygwin glib port maintainers made it clear
217 # (via the patches they apply) that they want no
218 # part of glib W32 code, therefore we do not define
219 # G_PLATFORM_WIN32 for host_system == 'cygwin'.
220 # This makes G_PLATFORM_WIN32 a synonym for
221 # G_OS_WIN32.
222 if host_system == 'windows'
223   glib_os = '''#define G_OS_WIN32
224 #define G_PLATFORM_WIN32'''
225 elif host_system == 'cygwin'
226   glib_os = '''#define G_OS_UNIX
227 #define G_WITH_CYGWIN'''
228 else
229   glib_os = '#define G_OS_UNIX'
230 endif
231 glibconfig_conf.set('glib_os', glib_os)
232
233 # We need to know the CRT being used to determine what .lib files we need on
234 # Visual Studio for dependencies that don't normally come with pkg-config files
235 vs_crt = 'release'
236 vs_crt_opt = get_option('b_vscrt')
237 if vs_crt_opt in ['mdd', 'mtd']
238   vs_crt = 'debug'
239 elif vs_crt_opt == 'from_buildtype'
240   if get_option('buildtype') == 'debug'
241     vs_crt = 'debug'
242   endif
243 endif
244
245 # Use debug/optimization flags to determine whether to enable debug or disable
246 # cast checks
247 glib_debug_cflags = []
248 glib_debug = get_option('glib_debug')
249 if glib_debug.enabled() or (glib_debug.auto() and get_option('debug'))
250   glib_debug_cflags += ['-DG_ENABLE_DEBUG']
251   message('Enabling various debug infrastructure')
252 elif get_option('optimization') in ['2', '3', 's']
253   glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
254   message('Disabling cast checks')
255 endif
256
257 if not get_option('glib_assert')
258   glib_debug_cflags += ['-DG_DISABLE_ASSERT']
259   message('Disabling GLib asserts')
260 endif
261
262 if not get_option('glib_checks')
263   glib_debug_cflags += ['-DG_DISABLE_CHECKS']
264   message('Disabling GLib checks')
265 endif
266
267 add_project_arguments(glib_debug_cflags, language: 'c')
268
269 # check for header files
270
271 headers = [
272   'alloca.h',
273   'crt_externs.h',
274   'dirent.h', # MSC does not come with this by default
275   'float.h',
276   'fstab.h',
277   'grp.h',
278   'inttypes.h',
279   'limits.h',
280   'linux/magic.h',
281   'locale.h',
282   'mach/mach_time.h',
283   'memory.h',
284   'mntent.h',
285   'poll.h',
286   'pwd.h',
287   'sched.h',
288   'spawn.h',
289   'stdatomic.h',
290   'stdint.h',
291   'stdlib.h',
292   'string.h',
293   'strings.h',
294   'sys/auxv.h',
295   'sys/event.h',
296   'sys/filio.h',
297   'sys/inotify.h',
298   'sys/mkdev.h',
299   'sys/mntctl.h',
300   'sys/mnttab.h',
301   'sys/mount.h',
302   'sys/param.h',
303   'sys/resource.h',
304   'sys/select.h',
305   'sys/statfs.h',
306   'sys/stat.h',
307   'sys/statvfs.h',
308   'sys/sysctl.h',
309   'sys/time.h', # MSC does not come with this by default
310   'sys/times.h',
311   'sys/types.h',
312   'sys/uio.h',
313   'sys/vfs.h',
314   'sys/vfstab.h',
315   'sys/vmount.h',
316   'sys/wait.h',
317   'termios.h',
318   'unistd.h',
319   'values.h',
320   'wchar.h',
321   'xlocale.h',
322 ]
323
324 foreach h : headers
325   if cc.has_header(h)
326     define = 'HAVE_' + h.underscorify().to_upper()
327     glib_conf.set(define, 1)
328     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
329   endif
330 endforeach
331
332 # FIXME: Use cc.check_header from Meson 0.47.
333 # FreeBSD includes a malloc.h which always throw compilation error.
334 if cc.compiles('#include <malloc.h>', name : 'malloc.h')
335   glib_conf.set('HAVE_MALLOC_H', 1)
336   glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
337 endif
338
339 if cc.has_header('linux/netlink.h')
340   glib_conf.set('HAVE_NETLINK', 1)
341 endif
342
343 # Is statx() supported? Android systems don’t reliably support it as of August 2020.
344 statx_code = '''
345   #ifndef _GNU_SOURCE
346   #define _GNU_SOURCE
347   #endif
348   #include <sys/stat.h>
349   #include <fcntl.h>
350   int main (void)
351   {
352     struct statx stat_buf;
353     return statx (AT_FDCWD, "/", AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS | STATX_BTIME, &stat_buf);
354   }
355   '''
356 if host_system != 'android' and cc.compiles(statx_code, name : 'statx() test')
357   glib_conf.set('HAVE_STATX', 1)
358 endif
359
360 if glib_conf.has('HAVE_LOCALE_H')
361   if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
362     glib_conf.set('HAVE_LC_MESSAGES', 1)
363   endif
364 endif
365
366 struct_stat_blkprefix = '''
367 #include <sys/types.h>
368 #include <sys/stat.h>
369 #ifdef HAVE_UNISTD_H
370 #include <unistd.h>
371 #endif
372 #ifdef HAVE_SYS_STATFS_H
373 #include <sys/statfs.h>
374 #endif
375 #ifdef HAVE_SYS_PARAM_H
376 #include <sys/param.h>
377 #endif
378 #ifdef HAVE_SYS_MOUNT_H
379 #include <sys/mount.h>
380 #endif
381 '''
382
383 struct_members = [
384   [ 'stat', 'st_mtimensec' ],
385   [ 'stat', 'st_mtim.tv_nsec' ],
386   [ 'stat', 'st_atimensec' ],
387   [ 'stat', 'st_atim.tv_nsec' ],
388   [ 'stat', 'st_ctimensec' ],
389   [ 'stat', 'st_ctim.tv_nsec' ],
390   [ 'stat', 'st_birthtime' ],
391   [ 'stat', 'st_birthtimensec' ],
392   [ 'stat', 'st_birthtim' ],
393   [ 'stat', 'st_birthtim.tv_nsec' ],
394   [ 'stat', 'st_blksize', struct_stat_blkprefix ],
395   [ 'stat', 'st_blocks', struct_stat_blkprefix ],
396   [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
397   [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
398   [ 'dirent', 'd_type', '''#include <sys/types.h>
399                            #include <dirent.h>''' ],
400   [ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
401   [ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
402   [ 'tm', 'tm_gmtoff', '#include <time.h>' ],
403   [ 'tm', '__tm_gmtoff', '#include <time.h>' ],
404 ]
405
406 foreach m : struct_members
407   header_check_prefix = glib_conf_prefix
408   if m.length() == 3
409     header_check_prefix = header_check_prefix + m[2]
410   else
411     header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
412   endif
413   if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
414     define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
415     glib_conf.set(define, 1)
416     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
417   else
418   endif
419 endforeach
420
421 # Compiler flags
422 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
423   warning_c_args = [
424     '-Wduplicated-branches',
425     '-Wimplicit-fallthrough',
426     '-Wmisleading-indentation',
427     '-Wstrict-prototypes',
428     '-Wunused',
429     # Due to maintained deprecated code, we do not want to see unused parameters
430     '-Wno-unused-parameter',
431     # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
432     # building with -Wbad-function-cast.
433     '-Wno-bad-function-cast',
434     '-Wno-cast-function-type',
435     # Due to function casts through (void*) we cannot support -Wpedantic:
436     # https://wiki.gnome.org/Projects/GLib/CompilerRequirements#Function_pointer_conversions.
437     '-Wno-pedantic',
438     # A zero-length format string shouldn't be considered an issue.
439     '-Wno-format-zero-length',
440     '-Werror=declaration-after-statement',
441     '-Werror=format=2',
442     '-Werror=implicit-function-declaration',
443     '-Werror=init-self',
444     '-Werror=missing-include-dirs',
445     '-Werror=missing-prototypes',
446     '-Werror=pointer-arith',
447   ]
448   warning_c_link_args = [
449     '-Wl,-z,nodelete',
450   ]
451   if get_option('bsymbolic_functions')
452     warning_c_link_args += ['-Wl,-Bsymbolic-functions']
453   endif
454 else
455   warning_c_args = []
456   warning_c_link_args = []
457 endif
458
459 add_project_arguments(cc.get_supported_arguments(warning_c_args), language: 'c')
460
461 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
462 # means we cannot use that flag in add_project_link_arguments(), and must add
463 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
464 # because that is what the autotools build did.
465 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
466 # improve this.
467 glib_link_flags = cc.get_supported_link_arguments(warning_c_link_args)
468
469 # Windows SDK requirements and checks
470 if host_system == 'windows'
471   # Check whether we're building for UWP apps
472   code = '''
473   #include <windows.h>
474   #if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
475   #error "Not building for UWP"
476   #endif'''
477   if cc.compiles(code, name : 'building for UWP')
478     glib_conf.set('G_WINAPI_ONLY_APP', true)
479     # We require Windows 10+ on WinRT
480     glib_conf.set('_WIN32_WINNT', '0x0A00')
481     uwp_gio_deps = [cc.find_library('shcore'),
482                     cc.find_library('runtimeobject')]
483   else
484     # We require Windows 7+ on Win32
485     glib_conf.set('_WIN32_WINNT', '0x0601')
486     uwp_gio_deps = []
487   endif
488 endif
489
490 functions = [
491   'close_range',
492   'endmntent',
493   'endservent',
494   'epoll_create',
495   'fallocate',
496   'fchmod',
497   'fchown',
498   'fdwalk',
499   'fsync',
500   'getauxval',
501   'getc_unlocked',
502   'getfsstat',
503   'getgrgid_r',
504   'getmntent_r',
505   'getpwuid_r',
506   'getresuid',
507   'getvfsstat',
508   'gmtime_r',
509   'hasmntopt',
510   'inotify_init1',
511   'issetugid',
512   'kevent',
513   'kqueue',
514   'lchmod',
515   'lchown',
516   'link',
517   'localtime_r',
518   'lstat',
519   'mbrtowc',
520   'memalign',
521   'mmap',
522   'newlocale',
523   'pipe2',
524   'poll',
525   'prlimit',
526   'readlink',
527   'recvmmsg',
528   'sendmmsg',
529   'setenv',
530   'setmntent',
531   'strerror_r',
532   'strnlen',
533   'strsignal',
534   'strtod_l',
535   'strtoll_l',
536   'strtoull_l',
537   'symlink',
538   'timegm',
539   'unsetenv',
540   'uselocale',
541   'utimes',
542   'valloc',
543   'vasprintf',
544   'vsnprintf',
545   'wcrtomb',
546   'wcslen',
547   'wcsnlen',
548   'sysctlbyname',
549 ]
550
551 # _NSGetEnviron is available on iOS too, but its usage gets apps rejected from
552 # the app store since it's considered 'private API'
553 if host_system == 'darwin'
554   functions += ['_NSGetEnviron']
555 endif
556
557 if glib_conf.has('HAVE_SYS_STATVFS_H')
558   functions += ['statvfs']
559 else
560   have_func_statvfs = false
561 endif
562 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
563   functions += ['statfs']
564 else
565   have_func_statfs = false
566 endif
567
568 if host_system == 'windows'
569   iphlpapi_dep = cc.find_library('iphlpapi')
570   iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
571   foreach ifunc : iphlpapi_funcs
572     iphl_prefix =  '''#define _WIN32_WINNT @0@
573       #include <winsock2.h>
574       #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
575     if cc.has_function(ifunc,
576                        prefix : iphl_prefix,
577                        dependencies : iphlpapi_dep)
578       idefine = 'HAVE_' + ifunc.underscorify().to_upper()
579       glib_conf.set(idefine, 1)
580       glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
581       set_variable('have_func_' + ifunc, true)
582     else
583       set_variable('have_func_' + ifunc, false)
584     endif
585   endforeach
586 else
587   functions += ['if_indextoname', 'if_nametoindex']
588 endif
589
590 # AIX splice is something else
591 if host_system != 'aix'
592   functions += ['splice']
593 endif
594
595 foreach f : functions
596   if cc.has_function(f)
597     define = 'HAVE_' + f.underscorify().to_upper()
598     glib_conf.set(define, 1)
599     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
600     set_variable('have_func_' + f, true)
601   else
602     set_variable('have_func_' + f, false)
603   endif
604 endforeach
605
606 # Check that stpcpy() is usable; must use header.
607 # cc.has_function() in some cases (clang, gcc 10+) assumes that if the
608 # compiler provides a builtin of the same name that the function exists, while
609 # it's in fact not provided by any header or library. This is true for
610 # stpcpy() on Windows using clang and gcc as well as posix_memalign() using
611 # gcc on Windows. Skip these checks on Windows for now to avoid false
612 # positives. See https://github.com/mesonbuild/meson/pull/7116,
613 # https://github.com/mesonbuild/meson/issues/3672 and
614 # https://github.com/mesonbuild/meson/issues/5628.
615 # FIXME: Once meson no longer returns success for stpcpy() and
616 # posix_memalign() on Windows using GCC and clang we can remove this.
617 if host_system != 'windows' and cc.has_function('stpcpy', prefix : '#include <string.h>')
618   glib_conf.set('HAVE_STPCPY', 1)
619 endif
620
621 # When building for Android-20 and earlier, require Meson 0.54.2 or newer.
622 # This is needed, because Meson build versions prior to 0.54.2 return false
623 # positive for stpcpy has_function check when building for legacy Android.
624 if host_system == 'android'
625     android_is_older = cc.compiles('''#if __ANDROID_API__ >= 21
626                                         #error Android is 21 or newer
627                                     #endif''')
628     if android_is_older and meson.version().version_compare('< 0.54.2')
629       error('Compiling for <Android-21 requires Meson 0.54.2 or newer')
630     endif
631 endif
632
633
634 # Check that posix_memalign() is usable; must use header
635 if host_system != 'windows' and cc.has_function('posix_memalign', prefix : '#include <stdlib.h>')
636   glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
637 endif
638
639 # Check that posix_spawn() is usable; must use header
640 if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
641   glib_conf.set('HAVE_POSIX_SPAWN', 1)
642 endif
643
644 # Check whether strerror_r returns char *
645 if have_func_strerror_r
646   if cc.compiles('''#define _GNU_SOURCE
647                     #include <string.h>
648                     int func (void) {
649                       char error_string[256];
650                       char *ptr = strerror_r (-2, error_string, 256);
651                       char c = *strerror_r (-2, error_string, 256);
652                       return c != 0 && ptr != (void*) 0L;
653                     }
654                  ''',
655                  name : 'strerror_r() returns char *')
656     glib_conf.set('STRERROR_R_CHAR_P', 1,
657                   description: 'Defined if strerror_r returns char *')
658   endif
659 endif
660
661 # Special-case these functions that have alternative names on Windows/MSVC
662 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
663   glib_conf.set('HAVE_SNPRINTF', 1)
664   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
665 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
666   hack_define = '1\n#define snprintf _snprintf'
667   glib_conf.set('HAVE_SNPRINTF', hack_define)
668   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
669 endif
670
671 if cc.has_function('strcasecmp', prefix: '#include <strings.h>')
672   glib_conf.set('HAVE_STRCASECMP', 1)
673   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
674 elif cc.has_function('_stricmp')
675   hack_define = '1\n#define strcasecmp _stricmp'
676   glib_conf.set('HAVE_STRCASECMP', hack_define)
677   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
678 endif
679
680 if cc.has_function('strncasecmp', prefix: '#include <strings.h>')
681   glib_conf.set('HAVE_STRNCASECMP', 1)
682   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
683 elif cc.has_function('_strnicmp')
684   hack_define = '1\n#define strncasecmp _strnicmp'
685   glib_conf.set('HAVE_STRNCASECMP', hack_define)
686   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
687 endif
688
689 if cc.has_header_symbol('sys/sysmacros.h', 'major')
690   glib_conf.set('MAJOR_IN_SYSMACROS', 1)
691 elif cc.has_header_symbol('sys/mkdev.h', 'major')
692   glib_conf.set('MAJOR_IN_MKDEV', 1)
693 elif cc.has_header_symbol('sys/types.h', 'major')
694   glib_conf.set('MAJOR_IN_TYPES', 1)
695 endif
696
697 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
698   glib_conf.set('HAVE_RTLD_LAZY', 1)
699 endif
700
701 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
702   glib_conf.set('HAVE_RTLD_NOW', 1)
703 endif
704
705 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
706   glib_conf.set('HAVE_RTLD_GLOBAL', 1)
707 endif
708
709 have_rtld_next = false
710 if cc.has_header_symbol('dlfcn.h', 'RTLD_NEXT', args: '-D_GNU_SOURCE')
711   have_rtld_next = true
712   glib_conf.set('HAVE_RTLD_NEXT', 1)
713 endif
714
715 # Check whether to use statfs or statvfs
716 # Some systems have both statfs and statvfs, pick the most "native" for these
717 if have_func_statfs and have_func_statvfs
718   # on solaris and irix, statfs doesn't even have the f_bavail field
719   if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
720     have_func_statfs = false
721   else
722     # at least on linux, statfs is the actual syscall
723     have_func_statvfs = false
724   endif
725 endif
726 if have_func_statfs
727   glib_conf.set('USE_STATFS', 1)
728   stat_func_to_use = 'statfs'
729 elif have_func_statvfs
730   glib_conf.set('USE_STATVFS', 1)
731   stat_func_to_use = 'statvfs'
732 else
733   stat_func_to_use = 'neither'
734 endif
735 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
736
737 if host_system == 'linux'
738   if cc.has_function('mkostemp',
739                      prefix: '''#define _GNU_SOURCE
740                                 #include <stdlib.h>''')
741     glib_conf.set('HAVE_MKOSTEMP', 1)
742   endif
743 endif
744
745 osx_ldflags = []
746 glib_have_os_x_9_or_later = false
747 glib_have_carbon = false
748 glib_have_cocoa = false
749 if host_system == 'darwin'
750   add_languages('objc')
751   objcc = meson.get_compiler('objc')
752
753   osx_ldflags += ['-Wl,-framework,CoreFoundation']
754
755   # Mac OS X Carbon support
756   glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
757                                        #include <CoreServices/CoreServices.h>''',
758                                     name : 'Mac OS X Carbon support')
759
760   if glib_have_carbon
761     glib_conf.set('HAVE_CARBON', true)
762     osx_ldflags += '-Wl,-framework,Carbon'
763     glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
764                                                   #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
765                                                   #error Compiling for minimum OS X version before 10.9
766                                                   #endif''',
767                                                name : 'OS X 9 or later')
768   endif
769
770   # Mac OS X Cocoa support
771   glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
772                                       #ifdef GNUSTEP_BASE_VERSION
773                                       #error "Detected GNUstep, not Cocoa"
774                                       #endif''',
775                                    name : 'Mac OS X Cocoa support')
776
777   if glib_have_cocoa
778     glib_conf.set('HAVE_COCOA', true)
779     osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
780   endif
781
782   # FIXME: libgio mix C and objC source files and there is no way to reliably
783   # know which language flags it's going to use to link. Add to both languages
784   # for now. See https://github.com/mesonbuild/meson/issues/3585.
785   add_project_link_arguments(osx_ldflags, language : ['objc', 'c'])
786 endif
787
788 if host_system == 'qnx'
789   glib_conf.set('HAVE_QNX', 1)
790 endif
791
792 # Check for futex(2)
793 if cc.links('''#include <linux/futex.h>
794                #include <sys/syscall.h>
795                #include <unistd.h>
796                int main (int argc, char ** argv) {
797                  syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
798                  return 0;
799                }''', name : 'futex(2) system call')
800   glib_conf.set('HAVE_FUTEX', 1)
801 endif
802
803 # Check for eventfd(2)
804 if cc.links('''#include <sys/eventfd.h>
805                #include <unistd.h>
806                int main (int argc, char ** argv) {
807                  eventfd (0, EFD_CLOEXEC);
808                  return 0;
809                }''', name : 'eventfd(2) system call')
810   glib_conf.set('HAVE_EVENTFD', 1)
811 endif
812
813 # Check for __uint128_t (gcc) by checking for 128-bit division
814 uint128_t_src = '''int main() {
815 static __uint128_t v1 = 100;
816 static __uint128_t v2 = 10;
817 static __uint128_t u;
818 u = v1 / v2;
819 }'''
820 if cc.compiles(uint128_t_src, name : '__uint128_t available')
821   glib_conf.set('HAVE_UINT128_T', 1)
822 endif
823
824 clock_gettime_test_code = '''
825   #include <time.h>
826   struct timespec t;
827   int main (int argc, char ** argv) {
828     return clock_gettime(CLOCK_REALTIME, &t);
829   }'''
830 librt = []
831 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
832   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
833 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
834   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
835   librt = cc.find_library('rt')
836 endif
837
838 dlopen_dlsym_test_code = '''
839 #include <dlfcn.h>
840 int glib_underscore_test (void) { return 42; }
841 int main (int argc, char ** argv) {
842   void *f1 = (void*)0, *f2 = (void*)0, *handle;
843   handle = dlopen ((void*)0, 0);
844   if (handle) {
845     f1 = dlsym (handle, "glib_underscore_test");
846     f2 = dlsym (handle, "_glib_underscore_test");
847   }
848   return (!f2 || f1);
849 }'''
850 libdl_dep = []
851 if cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
852   have_dlopen_dlsym = true
853 elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
854   have_dlopen_dlsym = true
855   libdl_dep = cc.find_library('dl')
856 else
857   have_dlopen_dlsym = false
858 endif
859
860 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
861 if have_func_statfs
862   if cc.compiles(glib_conf_prefix + '''
863                  #include <unistd.h>
864                         #ifdef HAVE_SYS_PARAM_H
865                         #include <sys/param.h>
866                         #endif
867                         #ifdef HAVE_SYS_VFS_H
868                         #include <sys/vfs.h>
869                         #endif
870                         #ifdef HAVE_SYS_MOUNT_H
871                         #include <sys/mount.h>
872                         #endif
873                         #ifdef HAVE_SYS_STATFS_H
874                         #include <sys/statfs.h>
875                         #endif
876                         void some_func (void) {
877                           struct statfs st;
878                           statfs("/", &st);
879                         }''', name : 'number of arguments to statfs() (n=2)')
880     glib_conf.set('STATFS_ARGS', 2)
881   elif cc.compiles(glib_conf_prefix + '''
882                    #include <unistd.h>
883                           #ifdef HAVE_SYS_PARAM_H
884                           #include <sys/param.h>
885                           #endif
886                           #ifdef HAVE_SYS_VFS_H
887                           #include <sys/vfs.h>
888                           #endif
889                           #ifdef HAVE_SYS_MOUNT_H
890                           #include <sys/mount.h>
891                           #endif
892                           #ifdef HAVE_SYS_STATFS_H
893                           #include <sys/statfs.h>
894                           #endif
895                           void some_func (void) {
896                             struct statfs st;
897                             statfs("/", &st, sizeof (st), 0);
898                           }''', name : 'number of arguments to statfs() (n=4)')
899     glib_conf.set('STATFS_ARGS', 4)
900   else
901     error('Unable to determine number of arguments to statfs()')
902   endif
903 endif
904
905 # open takes O_DIRECTORY as an option
906 #AC_MSG_CHECKING([])
907 if cc.compiles('''#include <fcntl.h>
908                   #include <sys/types.h>
909                   #include <sys/stat.h>
910                   void some_func (void) {
911                     open(0, O_DIRECTORY, 0);
912                   }''', name : 'open() option O_DIRECTORY')
913   glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
914 endif
915
916 # fcntl takes F_FULLFSYNC as an option
917 # See https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html
918 if cc.compiles('''#include <fcntl.h>
919                   #include <sys/types.h>
920                   #include <sys/stat.h>
921                   void some_func (void) {
922                     fcntl(0, F_FULLFSYNC, 0);
923                   }''', name : 'fcntl() option F_FULLFSYNC')
924   glib_conf.set('HAVE_FCNTL_F_FULLFSYNC', 1)
925 endif
926
927 # Check whether there is a vsnprintf() function with C99 semantics installed.
928 # (similar tests to AC_FUNC_VSNPRINTF_C99)
929 # Check whether there is a snprintf() function with C99 semantics installed.
930 # (similar tests to AC_FUNC_SNPRINTF_C99)
931 # Check whether there is a printf() function with Unix98 semantics installed.
932 # (similar tests to AC_FUNC_PRINTF_UNIX98)
933 have_good_vsnprintf = false
934 have_good_snprintf = false
935 have_good_printf = false
936
937 if host_system == 'windows' and (cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl')
938   # Unfortunately the Visual Studio 2015+ implementations of C99-style
939   # snprintf and vsnprintf don't seem to be quite good enough.
940   # (Sorry, I don't know exactly what is the problem,
941   # but it is related to floating point formatting and decimal point vs. comma.)
942   # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
943   # rigorous enough to notice, though.
944   glib_conf.set('HAVE_C99_SNPRINTF', false)
945   glib_conf.set('HAVE_C99_VSNPRINTF', false)
946   glib_conf.set('HAVE_UNIX98_PRINTF', false)
947 elif not cc_can_run and host_system in ['ios', 'darwin']
948   # All these are true when compiling natively on macOS, so we should use good
949   # defaults when building for iOS and tvOS.
950   glib_conf.set('HAVE_C99_SNPRINTF', true)
951   glib_conf.set('HAVE_C99_VSNPRINTF', true)
952   glib_conf.set('HAVE_UNIX98_PRINTF', true)
953   have_good_vsnprintf = true
954   have_good_snprintf = true
955   have_good_printf = true
956 else
957   vsnprintf_c99_test_code = '''
958 #include <stdio.h>
959 #include <stdarg.h>
960
961 int
962 doit(char * s, ...)
963 {
964   char buffer[32];
965   va_list args;
966   int r;
967
968   va_start(args, s);
969   r = vsnprintf(buffer, 5, s, args);
970   va_end(args);
971
972   if (r != 7)
973     exit(1);
974
975   /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
976      implementation. The above will return 7 but if you replace
977      the size of the buffer with 0, it borks! */
978   va_start(args, s);
979   r = vsnprintf(buffer, 0, s, args);
980   va_end(args);
981
982   if (r != 7)
983     exit(1);
984
985   exit(0);
986 }
987
988 int
989 main(void)
990 {
991   doit("1234567");
992   exit(1);
993 }'''
994
995   if cc_can_run
996     rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
997     if rres.compiled() and rres.returncode() == 0
998       glib_conf.set('HAVE_C99_VSNPRINTF', 1)
999       have_good_vsnprintf = true
1000     endif
1001   else
1002       have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
1003       glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
1004   endif
1005
1006   snprintf_c99_test_code = '''
1007 #include <stdio.h>
1008 #include <stdarg.h>
1009
1010 int
1011 doit()
1012 {
1013   char buffer[32];
1014   va_list args;
1015   int r;
1016
1017   r = snprintf(buffer, 5, "1234567");
1018
1019   if (r != 7)
1020     exit(1);
1021
1022   r = snprintf(buffer, 0, "1234567");
1023
1024   if (r != 7)
1025     exit(1);
1026
1027   r = snprintf(NULL, 0, "1234567");
1028
1029   if (r != 7)
1030     exit(1);
1031
1032   exit(0);
1033 }
1034
1035 int
1036 main(void)
1037 {
1038   doit();
1039   exit(1);
1040 }'''
1041
1042   if cc_can_run
1043     rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
1044     if rres.compiled() and rres.returncode() == 0
1045       glib_conf.set('HAVE_C99_SNPRINTF', 1)
1046       have_good_snprintf = true
1047     endif
1048   else
1049       have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
1050       glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
1051   endif
1052
1053   printf_unix98_test_code = '''
1054 #include <stdio.h>
1055
1056 int
1057 main (void)
1058 {
1059   char buffer[128];
1060
1061   sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
1062   if (strcmp ("2 3 1", buffer) == 0)
1063     exit (0);
1064   exit (1);
1065 }'''
1066
1067   if cc_can_run
1068     rres = cc.run(printf_unix98_test_code, name : 'Unix98 printf positional parameters')
1069     if rres.compiled() and rres.returncode() == 0
1070       glib_conf.set('HAVE_UNIX98_PRINTF', 1)
1071       have_good_printf = true
1072     endif
1073   else
1074       have_good_printf = meson.get_cross_property('have_unix98_printf', false)
1075       glib_conf.set('HAVE_UNIX98_PRINTF', have_good_printf)
1076   endif
1077 endif
1078
1079 if host_system == 'windows'
1080   glib_conf.set_quoted('EXEEXT', '.exe')
1081 else
1082   glib_conf.set('EXEEXT', '')
1083 endif
1084
1085 # Our printf is 'good' only if vsnpintf()/snprintf()/printf() supports C99 well enough
1086 use_system_printf = have_good_vsnprintf and have_good_snprintf and have_good_printf
1087 glib_conf.set('USE_SYSTEM_PRINTF', use_system_printf)
1088 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', use_system_printf)
1089
1090 if not use_system_printf
1091   # gnulib has vasprintf so override the previous check
1092   glib_conf.set('HAVE_VASPRINTF', 1)
1093 endif
1094
1095 # Check for nl_langinfo and CODESET
1096 if cc.links('''#include <langinfo.h>
1097                int main (int argc, char ** argv) {
1098                  char *codeset = nl_langinfo (CODESET);
1099                  return 0;
1100                }''', name : 'nl_langinfo and CODESET')
1101   glib_conf.set('HAVE_LANGINFO_CODESET', 1)
1102   glib_conf.set('HAVE_CODESET', 1)
1103 endif
1104
1105 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
1106 if cc.links('''#include <langinfo.h>
1107                int main (int argc, char ** argv) {
1108                  char *str;
1109                  str = nl_langinfo (PM_STR);
1110                  str = nl_langinfo (D_T_FMT);
1111                  str = nl_langinfo (D_FMT);
1112                  str = nl_langinfo (T_FMT);
1113                  str = nl_langinfo (T_FMT_AMPM);
1114                  str = nl_langinfo (MON_1);
1115                  str = nl_langinfo (ABMON_12);
1116                  str = nl_langinfo (DAY_1);
1117                  str = nl_langinfo (ABDAY_7);
1118                  return 0;
1119                }''', name : 'nl_langinfo (PM_STR)')
1120   glib_conf.set('HAVE_LANGINFO_TIME', 1)
1121 endif
1122 if cc.links('''#include <langinfo.h>
1123                int main (int argc, char ** argv) {
1124                  char *str;
1125                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
1126                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
1127                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
1128                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
1129                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
1130                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
1131                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
1132                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
1133                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
1134                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
1135                  return 0;
1136                }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
1137   glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
1138 endif
1139
1140 # Check for nl_langinfo and alternative month names
1141 if cc.links('''#ifndef _GNU_SOURCE
1142               # define _GNU_SOURCE
1143               #endif
1144               #include <langinfo.h>
1145                int main (int argc, char ** argv) {
1146                  char *str;
1147                  str = nl_langinfo (ALTMON_1);
1148                  str = nl_langinfo (ALTMON_2);
1149                  str = nl_langinfo (ALTMON_3);
1150                  str = nl_langinfo (ALTMON_4);
1151                  str = nl_langinfo (ALTMON_5);
1152                  str = nl_langinfo (ALTMON_6);
1153                  str = nl_langinfo (ALTMON_7);
1154                  str = nl_langinfo (ALTMON_8);
1155                  str = nl_langinfo (ALTMON_9);
1156                  str = nl_langinfo (ALTMON_10);
1157                  str = nl_langinfo (ALTMON_11);
1158                  str = nl_langinfo (ALTMON_12);
1159                  return 0;
1160                }''', name : 'nl_langinfo (ALTMON_n)')
1161   glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
1162 endif
1163
1164 # Check for nl_langinfo and abbreviated alternative month names
1165 if cc.links('''#ifndef _GNU_SOURCE
1166               # define _GNU_SOURCE
1167               #endif
1168               #include <langinfo.h>
1169                int main (int argc, char ** argv) {
1170                  char *str;
1171                  str = nl_langinfo (_NL_ABALTMON_1);
1172                  str = nl_langinfo (_NL_ABALTMON_2);
1173                  str = nl_langinfo (_NL_ABALTMON_3);
1174                  str = nl_langinfo (_NL_ABALTMON_4);
1175                  str = nl_langinfo (_NL_ABALTMON_5);
1176                  str = nl_langinfo (_NL_ABALTMON_6);
1177                  str = nl_langinfo (_NL_ABALTMON_7);
1178                  str = nl_langinfo (_NL_ABALTMON_8);
1179                  str = nl_langinfo (_NL_ABALTMON_9);
1180                  str = nl_langinfo (_NL_ABALTMON_10);
1181                  str = nl_langinfo (_NL_ABALTMON_11);
1182                  str = nl_langinfo (_NL_ABALTMON_12);
1183                  return 0;
1184                }''', name : 'nl_langinfo (_NL_ABALTMON_n)')
1185   glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
1186 endif
1187
1188 # Check if C compiler supports the 'signed' keyword
1189 if not cc.compiles('''signed char x;''', name : 'signed')
1190   glib_conf.set('signed', '/* NOOP */')
1191 endif
1192
1193 # Check if the ptrdiff_t type exists
1194 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
1195   glib_conf.set('HAVE_PTRDIFF_T', 1)
1196 endif
1197
1198 # Check for sig_atomic_t type
1199 if cc.links('''#include <signal.h>
1200                #include <sys/types.h>
1201                sig_atomic_t val = 42;
1202                int main (int argc, char ** argv) {
1203                  return val == 42 ? 0 : 1;
1204                }''', name : 'sig_atomic_t')
1205   glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
1206 endif
1207
1208 # Check if 'long long' works
1209 # jm_AC_TYPE_LONG_LONG
1210 if cc.compiles('''long long ll = 1LL;
1211                   int i = 63;
1212                   int some_func (void) {
1213                     long long llmax = (long long) -1;
1214                     return ll << i | ll >> i | llmax / ll | llmax % ll;
1215                   }''', name : 'long long')
1216   glib_conf.set('HAVE_LONG_LONG', 1)
1217   have_long_long = true
1218 else
1219   have_long_long = false
1220 endif
1221
1222 # Test whether the compiler supports the 'long double' type.
1223 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it.  */
1224                   long double foo = 0.0;
1225                   /* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
1226                   int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
1227                name : 'long double')
1228   glib_conf.set('HAVE_LONG_DOUBLE', 1)
1229 endif
1230
1231 # Test whether <stddef.h> has the 'wchar_t' type.
1232 if cc.has_header_symbol('stddef.h', 'wchar_t')
1233   glib_conf.set('HAVE_WCHAR_T', 1)
1234 endif
1235
1236 # Test whether <wchar.h> has the 'wint_t' type.
1237 if cc.has_header_symbol('wchar.h', 'wint_t')
1238   glib_conf.set('HAVE_WINT_T', 1)
1239 endif
1240
1241 found_uintmax_t = false
1242
1243 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
1244 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1245 # jm_AC_HEADER_INTTYPES_H
1246 if cc.compiles('''#include <sys/types.h>
1247                   #include <inttypes.h>
1248                   void some_func (void) {
1249                     uintmax_t i = (uintmax_t) -1;
1250                   }''', name : 'uintmax_t in inttypes.h')
1251   glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1252   found_uintmax_t = true
1253 endif
1254
1255 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1256 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1257 # jm_AC_HEADER_STDINT_H
1258 if cc.compiles('''#include <sys/types.h>
1259                   #include <stdint.h>
1260                   void some_func (void) {
1261                     uintmax_t i = (uintmax_t) -1;
1262                   }''', name : 'uintmax_t in stdint.h')
1263   glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1264   found_uintmax_t = true
1265 endif
1266
1267 # Define intmax_t to 'long' or 'long long'
1268 # if it is not already defined in <stdint.h> or <inttypes.h>.
1269 # For simplicity, we assume that a header file defines 'intmax_t' if and
1270 # only if it defines 'uintmax_t'.
1271 if found_uintmax_t
1272   glib_conf.set('HAVE_INTMAX_T', 1)
1273 elif have_long_long
1274   glib_conf.set('intmax_t', 'long long')
1275 else
1276   glib_conf.set('intmax_t', 'long')
1277 endif
1278
1279 char_size = cc.sizeof('char')
1280 short_size = cc.sizeof('short')
1281 int_size = cc.sizeof('int')
1282 voidp_size = cc.sizeof('void*')
1283 long_size = cc.sizeof('long')
1284 if have_long_long
1285   long_long_size = cc.sizeof('long long')
1286 else
1287   long_long_size = 0
1288 endif
1289 sizet_size = cc.sizeof('size_t')
1290 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1291   ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1292 else
1293   ssizet_size = cc.sizeof('ssize_t', prefix : '#include <unistd.h>')
1294 endif
1295
1296 # Some platforms (Apple) hard-code int64_t to long long instead of
1297 # using long on 64-bit architectures. This can cause type mismatch
1298 # warnings when trying to interface with code using the standard
1299 # library type. Test for the warnings and set gint64 to whichever
1300 # works.
1301 if long_long_size == long_size
1302   if cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1303                     #pragma options langlvl=stdc99
1304                     #endif
1305                     #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1306                     #include <stdint.h>
1307                     #include <stdio.h>
1308                     int main () {
1309                       int64_t i1 = 1;
1310                       long *i2 = &i1;
1311                       return 1;
1312                     }''', name : 'int64_t is long')
1313     int64_t_typedef = 'long'
1314   elif cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1315                       #pragma options langlvl=stdc99
1316                       #endif
1317                       #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1318                       #include <stdint.h>
1319                       #include <stdio.h>
1320                       int main () {
1321                         int64_t i1 = 1;
1322                         long long *i2 = &i1;
1323                         return 1;
1324                       }''', name : 'int64_t is long long')
1325     int64_t_typedef = 'long long'
1326   endif
1327 endif
1328
1329 int64_m = 'll'
1330 char_align = cc.alignment('char')
1331 short_align = cc.alignment('short')
1332 int_align = cc.alignment('int')
1333 voidp_align = cc.alignment('void*')
1334 long_align = cc.alignment('long')
1335 long_long_align = cc.alignment('long long')
1336 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1337 # be 64-bit in C99, and it is available on all supported compilers
1338 sizet_align = cc.alignment('size_t')
1339
1340 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1341
1342 glib_conf.set('SIZEOF_CHAR', char_size)
1343 glib_conf.set('SIZEOF_INT', int_size)
1344 glib_conf.set('SIZEOF_SHORT', short_size)
1345 glib_conf.set('SIZEOF_LONG', long_size)
1346 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1347 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1348 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1349 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1350 glib_conf.set('SIZEOF_WCHAR_T', cc.sizeof('wchar_t', prefix: '#include <stddef.h>'))
1351
1352 if short_size == 2
1353   gint16 = 'short'
1354   gint16_modifier='h'
1355   gint16_format='hi'
1356   guint16_format='hu'
1357 elif int_size == 2
1358   gint16 = 'int'
1359   gint16_modifier=''
1360   gint16_format='i'
1361   guint16_format='u'
1362 else
1363   error('Compiler provides no native 16-bit integer type')
1364 endif
1365 glibconfig_conf.set('gint16', gint16)
1366 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1367 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1368 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1369
1370 if short_size == 4
1371   gint32 = 'short'
1372   gint32_modifier='h'
1373   gint32_format='hi'
1374   guint32_format='hu'
1375   guint32_align = short_align
1376 elif int_size == 4
1377   gint32 = 'int'
1378   gint32_modifier=''
1379   gint32_format='i'
1380   guint32_format='u'
1381   guint32_align = int_align
1382 elif long_size == 4
1383   gint32 = 'long'
1384   gint32_modifier='l'
1385   gint32_format='li'
1386   guint32_format='lu'
1387   guint32_align = long_align
1388 else
1389   error('Compiler provides no native 32-bit integer type')
1390 endif
1391 glibconfig_conf.set('gint32', gint32)
1392 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1393 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1394 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1395 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1396
1397 if int_size == 8
1398   gint64 = 'int'
1399   gint64_modifier=''
1400   gint64_format='i'
1401   guint64_format='u'
1402   glib_extension=''
1403   gint64_constant='(val)'
1404   guint64_constant='(val)'
1405   guint64_align = int_align
1406 elif long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long')
1407   gint64 = 'long'
1408   glib_extension=''
1409   gint64_modifier='l'
1410   gint64_format='li'
1411   guint64_format='lu'
1412   gint64_constant='(val##L)'
1413   guint64_constant='(val##UL)'
1414   guint64_align = long_align
1415 elif long_long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long long')
1416   gint64 = 'long long'
1417   glib_extension='G_GNUC_EXTENSION '
1418   gint64_modifier=int64_m
1419   gint64_format=int64_m + 'i'
1420   guint64_format=int64_m + 'u'
1421   gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1422   guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1423   guint64_align = long_long_align
1424 else
1425   error('Compiler provides no native 64-bit integer type')
1426 endif
1427 glibconfig_conf.set('glib_extension', glib_extension)
1428 glibconfig_conf.set('gint64', gint64)
1429 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1430 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1431 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1432 glibconfig_conf.set('gint64_constant', gint64_constant)
1433 glibconfig_conf.set('guint64_constant', guint64_constant)
1434 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1435
1436 if host_system == 'windows'
1437   glibconfig_conf.set('g_pid_type', 'void*')
1438   glibconfig_conf.set_quoted('g_pid_format', 'p')
1439   if host_machine.cpu_family() == 'x86_64'
1440     glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1441   else
1442     glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1443   endif
1444   glibconfig_conf.set('g_dir_separator', '\\\\')
1445   glibconfig_conf.set('g_searchpath_separator', ';')
1446 else
1447   glibconfig_conf.set('g_pid_type', 'int')
1448   glibconfig_conf.set_quoted('g_pid_format', 'i')
1449   glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1450   glibconfig_conf.set('g_dir_separator', '/')
1451   glibconfig_conf.set('g_searchpath_separator', ':')
1452 endif
1453
1454 g_sizet_compatibility = {
1455   'short': sizet_size == short_size,
1456   'int': sizet_size == int_size,
1457   'long': sizet_size == long_size,
1458   'long long': sizet_size == long_long_size,
1459 }
1460
1461 # Do separate checks for gcc/clang (and ignore other compilers for now), since
1462 # we need to explicitly pass -Werror to the compilers.
1463 # FIXME: https://github.com/mesonbuild/meson/issues/5399
1464 # We can’t simplify these checks using a foreach loop because dictionary keys
1465 # have to be string literals.
1466 # FIXME: https://github.com/mesonbuild/meson/issues/5231
1467 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
1468   g_sizet_compatibility += {
1469     'short': g_sizet_compatibility['short'] and cc.compiles(
1470         '''#include <stddef.h>
1471         size_t f (size_t *i) { return *i + 1; }
1472         int main (void) {
1473           unsigned short i = 0;
1474           f (&i);
1475           return 0;
1476         }''',
1477         args: ['-Werror'],
1478         name : 'GCC size_t typedef is short'),
1479     'int': g_sizet_compatibility['int'] and cc.compiles(
1480         '''#include <stddef.h>
1481         size_t f (size_t *i) { return *i + 1; }
1482         int main (void) {
1483           unsigned int i = 0;
1484           f (&i);
1485           return 0;
1486         }''',
1487         args: ['-Werror'],
1488         name : 'GCC size_t typedef is int'),
1489     'long': g_sizet_compatibility['long'] and cc.compiles(
1490         '''#include <stddef.h>
1491         size_t f (size_t *i) { return *i + 1; }
1492         int main (void) {
1493           unsigned long i = 0;
1494           f (&i);
1495           return 0;
1496         }''',
1497         args: ['-Werror'],
1498         name : 'GCC size_t typedef is long'),
1499     'long long': g_sizet_compatibility['long long'] and cc.compiles(
1500         '''#include <stddef.h>
1501         size_t f (size_t *i) { return *i + 1; }
1502         int main (void) {
1503           unsigned long long i = 0;
1504           f (&i);
1505           return 0;
1506         }''',
1507         args: ['-Werror'],
1508         name : 'GCC size_t typedef is long long'),
1509   }
1510 endif
1511
1512 if g_sizet_compatibility['short']
1513   glibconfig_conf.set('glib_size_type_define', 'short')
1514   glibconfig_conf.set_quoted('gsize_modifier', 'h')
1515   glibconfig_conf.set_quoted('gssize_modifier', 'h')
1516   glibconfig_conf.set_quoted('gsize_format', 'hu')
1517   glibconfig_conf.set_quoted('gssize_format', 'hi')
1518   glibconfig_conf.set('glib_msize_type', 'SHRT')
1519 elif g_sizet_compatibility['int']
1520   glibconfig_conf.set('glib_size_type_define', 'int')
1521   glibconfig_conf.set_quoted('gsize_modifier', '')
1522   glibconfig_conf.set_quoted('gssize_modifier', '')
1523   glibconfig_conf.set_quoted('gsize_format', 'u')
1524   glibconfig_conf.set_quoted('gssize_format', 'i')
1525   glibconfig_conf.set('glib_msize_type', 'INT')
1526 elif g_sizet_compatibility['long']
1527   glibconfig_conf.set('glib_size_type_define', 'long')
1528   glibconfig_conf.set_quoted('gsize_modifier', 'l')
1529   glibconfig_conf.set_quoted('gssize_modifier', 'l')
1530   glibconfig_conf.set_quoted('gsize_format', 'lu')
1531   glibconfig_conf.set_quoted('gssize_format', 'li')
1532   glibconfig_conf.set('glib_msize_type', 'LONG')
1533 elif g_sizet_compatibility['long long']
1534   glibconfig_conf.set('glib_size_type_define', 'long long')
1535   glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1536   glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1537   glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1538   glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1539   glibconfig_conf.set('glib_msize_type', 'INT64')
1540 else
1541   error('Could not determine size of size_t.')
1542 endif
1543
1544 if voidp_size == int_size
1545   glibconfig_conf.set('glib_intptr_type_define', 'int')
1546   glibconfig_conf.set_quoted('gintptr_modifier', '')
1547   glibconfig_conf.set_quoted('gintptr_format', 'i')
1548   glibconfig_conf.set_quoted('guintptr_format', 'u')
1549   glibconfig_conf.set('glib_gpi_cast', '(gint)')
1550   glibconfig_conf.set('glib_gpui_cast', '(guint)')
1551 elif voidp_size == long_size
1552   glibconfig_conf.set('glib_intptr_type_define', 'long')
1553   glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1554   glibconfig_conf.set_quoted('gintptr_format', 'li')
1555   glibconfig_conf.set_quoted('guintptr_format', 'lu')
1556   glibconfig_conf.set('glib_gpi_cast', '(glong)')
1557   glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1558 elif voidp_size == long_long_size
1559   glibconfig_conf.set('glib_intptr_type_define', 'long long')
1560   glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1561   glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1562   glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1563   glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1564   glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1565 else
1566   error('Could not determine size of void *')
1567 endif
1568
1569 if long_size != 8 and long_long_size != 8 and int_size != 8
1570   error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1571 endif
1572
1573 glibconfig_conf.set('gintbits', int_size * 8)
1574 glibconfig_conf.set('glongbits', long_size * 8)
1575 glibconfig_conf.set('gsizebits', sizet_size * 8)
1576 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1577
1578 # XXX: https://gitlab.gnome.org/GNOME/glib/issues/1413
1579 if host_system == 'windows'
1580   g_module_suffix = 'dll'
1581 else
1582   g_module_suffix = 'so'
1583 endif
1584 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1585
1586 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1587 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1588 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1589 glibconfig_conf.set('GLIB_VERSION', glib_version)
1590
1591 glibconfig_conf.set('glib_void_p', voidp_size)
1592 glibconfig_conf.set('glib_long', long_size)
1593 glibconfig_conf.set('glib_size_t', sizet_size)
1594 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1595 if host_machine.endian() == 'big'
1596   glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1597   glibconfig_conf.set('g_bs_native', 'BE')
1598   glibconfig_conf.set('g_bs_alien', 'LE')
1599 else
1600   glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1601   glibconfig_conf.set('g_bs_native', 'LE')
1602   glibconfig_conf.set('g_bs_alien', 'BE')
1603 endif
1604
1605 # === va_copy checks ===
1606 # we currently check for all three va_copy possibilities, so we get
1607 # all results in config.log for bug reports.
1608
1609 va_copy_func = ''
1610 foreach try_func : [ '__va_copy', 'va_copy' ]
1611   if cc.compiles('''#include <stdarg.h>
1612                     #include <stdlib.h>
1613                     #ifdef _MSC_VER
1614                     # include "msvc_recommended_pragmas.h"
1615                     #endif
1616                     void f (int i, ...) {
1617                     va_list args1, args2;
1618                     va_start (args1, i);
1619                     @0@ (args2, args1);
1620                     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1621                       exit (1);
1622                     va_end (args1); va_end (args2);
1623                     }
1624                     int main() {
1625                       f (0, 42);
1626                       return 0;
1627                     }'''.format(try_func),
1628                     name : try_func + ' check')
1629     va_copy_func = try_func
1630   endif
1631 endforeach
1632 if va_copy_func != ''
1633   glib_conf.set('G_VA_COPY', va_copy_func)
1634   glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1635 else
1636   glib_vacopy = '/* #undef G_VA_COPY */'
1637 endif
1638
1639 va_list_val_copy_prog = '''
1640   #include <stdarg.h>
1641   #include <stdlib.h>
1642   void f (int i, ...) {
1643     va_list args1, args2;
1644     va_start (args1, i);
1645     args2 = args1;
1646     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1647       exit (1);
1648     va_end (args1); va_end (args2);
1649   }
1650   int main() {
1651     f (0, 42);
1652     return 0;
1653   }'''
1654
1655 if cc_can_run
1656   rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1657   glib_va_val_copy = rres.returncode() == 0
1658 else
1659   glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
1660 endif
1661 if not glib_va_val_copy
1662   glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1663   glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1664 endif
1665 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1666
1667 # check for flavours of varargs macros
1668 g_have_iso_c_varargs = cc.compiles('''
1669   void some_func (void) {
1670     int a(int p1, int p2, int p3);
1671     #define call_a(...) a(1,__VA_ARGS__)
1672     call_a(2,3);
1673   }''', name : 'ISO C99 varargs macros in C')
1674
1675 if g_have_iso_c_varargs
1676   glibconfig_conf.set('g_have_iso_c_varargs', '''
1677 #ifndef __cplusplus
1678 # define G_HAVE_ISO_VARARGS 1
1679 #endif''')
1680 endif
1681
1682 g_have_iso_cxx_varargs = cxx.compiles('''
1683   void some_func (void) {
1684     int a(int p1, int p2, int p3);
1685     #define call_a(...) a(1,__VA_ARGS__)
1686     call_a(2,3);
1687   }''', name : 'ISO C99 varargs macros in C++')
1688
1689 if g_have_iso_cxx_varargs
1690   glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1691 #ifdef __cplusplus
1692 # define G_HAVE_ISO_VARARGS 1
1693 #endif''')
1694 endif
1695
1696 g_have_gnuc_varargs = cc.compiles('''
1697   void some_func (void) {
1698     int a(int p1, int p2, int p3);
1699     #define call_a(params...) a(1,params)
1700     call_a(2,3);
1701   }''', name : 'GNUC varargs macros')
1702
1703 if cc.has_header('alloca.h')
1704   glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1705 endif
1706 has_syspoll = cc.has_header('sys/poll.h')
1707 has_systypes = cc.has_header('sys/types.h')
1708 if has_syspoll
1709   glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1710 endif
1711 has_winsock2 = cc.has_header('winsock2.h')
1712
1713 if has_syspoll and has_systypes
1714   poll_includes = '''
1715       #include<sys/poll.h>
1716       #include<sys/types.h>'''
1717 elif has_winsock2
1718   poll_includes = '''
1719       #define _WIN32_WINNT @0@
1720       #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1721 else
1722   # FIXME?
1723   error('FIX POLL* defines')
1724 endif
1725
1726 poll_defines = [
1727   [ 'POLLIN', 'g_pollin', 1 ],
1728   [ 'POLLOUT', 'g_pollout', 4 ],
1729   [ 'POLLPRI', 'g_pollpri', 2 ],
1730   [ 'POLLERR', 'g_pollerr', 8 ],
1731   [ 'POLLHUP', 'g_pollhup', 16 ],
1732   [ 'POLLNVAL', 'g_pollnval', 32 ],
1733 ]
1734
1735 if has_syspoll and has_systypes
1736   foreach d : poll_defines
1737     val = cc.compute_int(d[0], prefix: poll_includes)
1738     glibconfig_conf.set(d[1], val)
1739   endforeach
1740 elif has_winsock2
1741   # Due to a missed bug in configure.ac the poll test
1742   # never succeeded on Windows and used some pre-defined
1743   # values as a fallback. Keep using them to maintain
1744   # ABI compatibility with autotools builds of glibs
1745   # and with *any* glib-using code compiled against them,
1746   # since these values end up in a public header glibconfig.h.
1747   foreach d : poll_defines
1748     glibconfig_conf.set(d[1], d[2])
1749   endforeach
1750 endif
1751
1752 # Internet address families
1753 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1754 if host_system == 'windows'
1755   inet_includes = '''
1756       #include <winsock2.h>'''
1757 else
1758   inet_includes = '''
1759       #include <sys/types.h>
1760       #include <sys/socket.h>'''
1761 endif
1762
1763 inet_defines = [
1764   [ 'AF_UNIX', 'g_af_unix' ],
1765   [ 'AF_INET', 'g_af_inet' ],
1766   [ 'AF_INET6', 'g_af_inet6' ],
1767   [ 'MSG_OOB', 'g_msg_oob' ],
1768   [ 'MSG_PEEK', 'g_msg_peek' ],
1769   [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1770 ]
1771 foreach d : inet_defines
1772   val = cc.compute_int(d[0], prefix: inet_includes)
1773   glibconfig_conf.set(d[1], val)
1774 endforeach
1775
1776 if host_system == 'windows'
1777   have_ipv6 = true
1778 else
1779   have_ipv6 = cc.has_type('struct in6_addr', prefix: '#include <netinet/in.h>')
1780 endif
1781 glib_conf.set('HAVE_IPV6', have_ipv6)
1782
1783 # We need to decide at configure time if GLib will use real atomic
1784 # operations ("lock free") or emulated ones with a mutex.  This is
1785 # because we must put this information in glibconfig.h so we know if
1786 # it is safe or not to inline using compiler intrinsics directly from
1787 # the header.
1788 #
1789 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1790 # user is interested in knowing if they can use the atomic ops across
1791 # processes.
1792 #
1793 # We can currently support the atomic ops natively when building GLib
1794 # with recent versions of GCC or MSVC.
1795 #
1796 # Note that the atomic ops are only available with GCC on x86 when
1797 # using -march=i486 or higher.  If we detect that the atomic ops are
1798 # not available but would be available given the right flags, we want
1799 # to abort and advise the user to fix their CFLAGS.  It's better to do
1800 # that then to silently fall back on emulated atomic ops just because
1801 # the user had the wrong build environment.
1802 atomictest = '''int main() {
1803   int atomic = 2;
1804   __sync_bool_compare_and_swap (&atomic, 2, 3);
1805   return 0;
1806 }
1807 '''
1808
1809 atomicdefine = '''
1810 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1811 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1812 #endif
1813 '''
1814
1815 # We know that we can always use real ("lock free") atomic operations with MSVC
1816 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' or cc.links(atomictest, name : 'atomic ops')
1817   have_atomic_lock_free = true
1818   if cc.get_id() == 'gcc' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1819     # Old gcc release may provide
1820     # __sync_bool_compare_and_swap but doesn't define
1821     # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1822     glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1823   endif
1824 else
1825   have_atomic_lock_free = false
1826   if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1827     error('GLib must be built with -march=i486 or later.')
1828   endif
1829 endif
1830 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1831
1832 # === Threads ===
1833
1834 # Determination of thread implementation
1835 if host_system == 'windows' and not get_option('force_posix_threads')
1836   thread_dep = []
1837   threads_implementation = 'win32'
1838   glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1839   glib_conf.set('THREADS_WIN32', 1)
1840 else
1841   thread_dep = dependency('threads')
1842   threads_implementation = 'posix'
1843   pthread_prefix = '''
1844       #ifndef _GNU_SOURCE
1845       # define _GNU_SOURCE
1846       #endif
1847       #include <pthread.h>'''
1848   glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1849   glib_conf.set('THREADS_POSIX', 1)
1850   if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1851     glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1852   endif
1853   if cc.has_header_symbol('pthread.h', 'pthread_attr_setinheritsched')
1854     glib_conf.set('HAVE_PTHREAD_ATTR_SETINHERITSCHED', 1)
1855   endif
1856   if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1857     glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1858   endif
1859   if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1860     glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1861   endif
1862   if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1863     glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1864   endif
1865
1866   if cc.has_header_symbol('sys/syscall.h', 'SYS_sched_getattr')
1867     glib_conf.set('HAVE_SYS_SCHED_GETATTR', 1)
1868   endif
1869
1870   # Assume that pthread_setname_np is available in some form; same as configure
1871   if cc.links(pthread_prefix + '''
1872               int main() {
1873                 pthread_setname_np("example");
1874                 return 0;
1875               }''',
1876               name : 'pthread_setname_np(const char*)',
1877               dependencies : thread_dep)
1878     # macOS and iOS
1879     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1880   elif cc.links(pthread_prefix + '''
1881                 int main() {
1882                   pthread_setname_np(pthread_self(), "example");
1883                   return 0;
1884                 }''',
1885                 name : 'pthread_setname_np(pthread_t, const char*)',
1886                 dependencies : thread_dep)
1887     # Linux, Solaris, etc.
1888     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1889   elif cc.links(pthread_prefix + '''
1890                 int main() {
1891                   pthread_setname_np(pthread_self(), "%s", "example");
1892                   return 0;
1893                 }''',
1894                 name : 'pthread_setname_np(pthread_t, const char*, void*)',
1895                 dependencies : thread_dep)
1896     # NetBSD
1897     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG', 1)
1898   elif cc.links(pthread_prefix + '''
1899                 #include <pthread_np.h>
1900                 int main() {
1901                   pthread_set_name_np(pthread_self(), "example");
1902                   return 0;
1903                 }''',
1904                 name : 'pthread_set_name_np(pthread_t, const char*)',
1905                 dependencies : thread_dep)
1906     # FreeBSD, DragonFlyBSD, OpenBSD, etc.
1907     glib_conf.set('HAVE_PTHREAD_SET_NAME_NP', 1)
1908   endif
1909 endif
1910
1911 # FIXME: we should make it print the result and always return 0, so that
1912 # the output in meson shows up as green
1913 # volatile is needed here to avoid optimisations in the test
1914 stack_grows_check_prog = '''
1915   volatile int *a = 0, *b = 0;
1916   void f (int i) {
1917     volatile int x = 5;
1918     if (i == 0)
1919       b = &x;
1920     else
1921       f (i - 1);
1922   }
1923   int main () {
1924     volatile int y = 7;
1925     a = &y;
1926     f (100);
1927     return b > a ? 0 : 1;
1928   }'''
1929
1930 if cc_can_run
1931   rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
1932   growing_stack = rres.returncode() == 0
1933 else
1934   growing_stack = meson.get_cross_property('growing_stack', false)
1935 endif
1936
1937 glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack)
1938
1939 # Tests for iconv
1940 #
1941 # We should never use the MinGW C library's iconv because it may not be
1942 # available in the actual runtime environment. On Windows, we always use
1943 # the built-in implementation
1944 iconv_opt = get_option('iconv')
1945 if host_system == 'windows'
1946   libiconv = []
1947   # We have a #include "win_iconv.c" in gconvert.c on Windows, so we don't need
1948   # any external library for it
1949   if iconv_opt != 'auto'
1950     warning('-Diconv was set to @0@, which was ignored')
1951   endif
1952 else
1953   found_iconv = false
1954   if ['auto', 'libc'].contains(iconv_opt) and cc.has_function('iconv_open')
1955     libiconv = []
1956     found_iconv = true
1957   endif
1958   if not found_iconv and ['auto', 'external'].contains(iconv_opt) and cc.has_header_symbol('iconv.h', 'iconv_open')
1959     libiconv = [cc.find_library('iconv')]
1960     found_iconv = true
1961   endif
1962
1963   if not found_iconv
1964     error('iconv implementation "@0@" not found'.format(iconv_opt))
1965   endif
1966 endif
1967
1968 if get_option('internal_pcre')
1969   pcre = []
1970   use_system_pcre = false
1971 else
1972   pcre = dependency('libpcre', version: '>= 8.31', required : false) # Should check for Unicode support, too. FIXME
1973   if not pcre.found()
1974     if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1975     # MSVC: Search for the PCRE library by the configuration, which corresponds
1976     # to the output of CMake builds of PCRE.  Note that debugoptimized
1977     # is really a Release build with .PDB files.
1978       if vs_crt == 'debug'
1979         pcre = cc.find_library('pcred', required : false)
1980       else
1981         pcre = cc.find_library('pcre', required : false)
1982       endif
1983     endif
1984   endif
1985   use_system_pcre = pcre.found()
1986 endif
1987 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1988
1989 use_pcre_static_flag = false
1990
1991 if host_system == 'windows'
1992   if not use_system_pcre
1993     use_pcre_static_flag = true
1994   else
1995     pcre_static = cc.links('''#define PCRE_STATIC
1996                               #include <pcre.h>
1997                               int main() {
1998                                 void *p = NULL;
1999                                 pcre_free(p);
2000                                 return 0;
2001                               }''',
2002                            dependencies: pcre,
2003                            name : 'Windows system PCRE is a static build')
2004     if pcre_static
2005       use_pcre_static_flag = true
2006     endif
2007   endif
2008 endif
2009
2010 libm = cc.find_library('m', required : false)
2011 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
2012
2013 if get_option('wrap_mode') == 'forcefallback'
2014   # Respects "wrap_mode=forcefallback" option
2015   libz_dep = subproject('zlib').get_variable('zlib_dep')
2016 else
2017   # Don't use the bundled ZLib sources until we are sure that we can't find it on
2018   # the system
2019   libz_dep = dependency('zlib', required : false)
2020 endif
2021
2022 if not libz_dep.found()
2023   if cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
2024     libz_dep = cc.find_library('z', required : false)
2025   else
2026     libz_dep = cc.find_library('zlib1', required : false)
2027     if not libz_dep.found()
2028       libz_dep = cc.find_library('zlib', required : false)
2029     endif
2030   endif
2031   if not libz_dep.found() or not cc.has_header('zlib.h')
2032     libz_dep = subproject('zlib').get_variable('zlib_dep')
2033   endif
2034 endif
2035
2036 # First check in libc, fallback to libintl, and as last chance build
2037 # proxy-libintl subproject.
2038 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
2039 # implementations. This could be extended if issues are found in some platforms.
2040 libintl_deps = []
2041 if cc.has_function('ngettext')
2042   have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset')
2043 else
2044   # First just find the bare library.
2045   libintl = cc.find_library('intl', required : false)
2046   # The bare library probably won't link without help if it's static.
2047   if libintl.found() and not cc.has_function('ngettext', dependencies : libintl)
2048      libintl_iconv = cc.find_library('iconv', required : false)
2049      # libintl supports different threading APIs, which may not
2050      # require additional flags, but it defaults to using pthreads if
2051      # found. Meson's "threads" dependency does not allow you to
2052      # prefer pthreads. We may not be using pthreads for glib itself
2053      # either so just link the library to satisfy libintl rather than
2054      # also defining the macros with the -pthread flag.
2055      libintl_pthread = cc.find_library('pthread', required : false)
2056      # Try linking with just libiconv.
2057      if libintl_iconv.found() and cc.has_function('ngettext', dependencies : [libintl, libintl_iconv])
2058        libintl_deps += [libintl_iconv]
2059      # Then also try linking with pthreads.
2060      elif libintl_iconv.found() and libintl_pthread.found() and cc.has_function('ngettext', dependencies : [libintl, libintl_iconv, libintl_pthread])
2061        libintl_deps += [libintl_iconv, libintl_pthread]
2062      else
2063        libintl = disabler()
2064      endif
2065   endif
2066   if not libintl.found()
2067     libintl = subproject('proxy-libintl').get_variable('intl_dep')
2068     libintl_deps = [libintl] + libintl_deps
2069     have_bind_textdomain_codeset = true  # proxy-libintl supports it
2070   else
2071     libintl_deps = [libintl] + libintl_deps
2072     have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset',
2073                                                    dependencies : libintl_deps)
2074   endif
2075 endif
2076
2077 glib_conf.set('HAVE_BIND_TEXTDOMAIN_CODESET', have_bind_textdomain_codeset)
2078
2079 # We require gettext to always be present
2080 glib_conf.set('HAVE_DCGETTEXT', 1)
2081 glib_conf.set('HAVE_GETTEXT', 1)
2082
2083 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
2084
2085 # libmount is only used by gio, but we need to fetch the libs to generate the
2086 # pkg-config file below
2087 libmount_dep = []
2088 if host_system == 'linux'
2089   libmount_dep = dependency('mount', version : '>=2.23', required : get_option('libmount'))
2090   glib_conf.set('HAVE_LIBMOUNT', libmount_dep.found())
2091 endif
2092
2093 if host_system == 'windows'
2094   winsock2 = cc.find_library('ws2_32')
2095 endif
2096
2097 selinux_dep = []
2098 if host_system == 'linux'
2099   selinux_dep = dependency('libselinux', version: '>=2.2', required: get_option('selinux'))
2100
2101   glib_conf.set('HAVE_SELINUX', selinux_dep.found())
2102 endif
2103
2104 xattr_dep = []
2105 if host_system != 'windows' and get_option('xattr')
2106   # either glibc or libattr can provide xattr support
2107   # for both of them, we check for getxattr being in
2108   # the library and a valid xattr header.
2109
2110   # try glibc
2111   if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
2112     glib_conf.set('HAVE_SYS_XATTR_H', 1)
2113     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
2114   #failure. try libattr
2115   elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
2116     glib_conf.set('HAVE_ATTR_XATTR_H', 1)
2117     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
2118     xattr_dep = [cc.find_library('xattr')]
2119   else
2120     error('No getxattr implementation found in C library or libxattr')
2121   endif
2122
2123   glib_conf.set('HAVE_XATTR', 1)
2124   if cc.compiles(glib_conf_prefix + '''
2125                  #include <stdio.h>
2126                  #ifdef HAVE_SYS_TYPES_H
2127                  #include <sys/types.h>
2128                  #endif
2129                  #ifdef HAVE_SYS_XATTR_H
2130                  #include <sys/xattr.h>
2131                  #elif HAVE_ATTR_XATTR_H
2132                  #include <attr/xattr.h>
2133                  #endif
2134
2135                  int main (void) {
2136                    ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
2137                    return len;
2138                  }''',
2139                  name : 'XATTR_NOFOLLOW')
2140     glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
2141   endif
2142 endif
2143
2144 # If strlcpy is present (BSD and similar), check that it conforms to the BSD
2145 # specification. Specifically Solaris 8's strlcpy() does not, see
2146 # https://bugzilla.gnome.org/show_bug.cgi?id=53933 for further context.
2147 if cc.has_function('strlcpy')
2148   if cc_can_run
2149     rres = cc.run('''#include <stdlib.h>
2150                     #include <string.h>
2151                     int main() {
2152                       char p[10];
2153                       (void) strlcpy (p, "hi", 10);
2154                       if (strlcat (p, "bye", 0) != 3)
2155                         return 1;
2156                       return 0;
2157                     }''',
2158                   name : 'OpenBSD strlcpy/strlcat')
2159     if rres.compiled() and rres.returncode() == 0
2160       glib_conf.set('HAVE_STRLCPY', 1)
2161     endif
2162   elif meson.get_cross_property('have_strlcpy', false)
2163     glib_conf.set('HAVE_STRLCPY', 1)
2164   endif
2165 endif
2166
2167 cmdline_test_code = '''
2168 #include <fcntl.h>
2169 #include <sys/stat.h>
2170 #include <stdio.h>
2171 #include <stdlib.h>
2172
2173 static int
2174 __getcmdline (void)
2175 {
2176 /* This code is a dumbed-down version of g_file_get_contents() */
2177 #ifndef O_BINARY
2178 #define O_BINARY 0
2179 #endif
2180 #define BUFSIZE 1024
2181   char result[BUFSIZE];
2182   struct stat stat_buf;
2183
2184   int fd = open ("/proc/self/cmdline", O_RDONLY|O_BINARY);
2185   if (fd < 0)
2186     exit (1);
2187   if (fstat (fd, &stat_buf))
2188     exit (1);
2189
2190   if (stat_buf.st_size > 0 && S_ISREG (stat_buf.st_mode))
2191     {
2192       if (read (fd, result, BUFSIZE) <= 0)
2193         exit (1);
2194     }
2195   else
2196     {
2197       FILE *f = fdopen (fd, "r");
2198       if (f == NULL)
2199         exit (1);
2200
2201       if (fread (result, 1, BUFSIZE, f) <= 0)
2202         exit (1);
2203     }
2204
2205   return 0;
2206 }
2207
2208 int
2209 main (void)
2210 {
2211   exit (__getcmdline ());
2212 }'''
2213
2214 if cc_can_run
2215   rres = cc.run(cmdline_test_code, name : '/proc/self/cmdline')
2216   have_proc_self_cmdline = rres.compiled() and rres.returncode() == 0
2217 else
2218   have_proc_self_cmdline = meson.get_cross_property('have_proc_self_cmdline', false)
2219 endif
2220
2221 glib_conf.set('HAVE_PROC_SELF_CMDLINE', have_proc_self_cmdline)
2222
2223 python = import('python').find_installation('python3')
2224 # used for '#!/usr/bin/env <name>'
2225 python_name = 'python3'
2226
2227 python_version = python.language_version()
2228 python_version_req = '>=3.5'
2229 if not python_version.version_compare(python_version_req)
2230   error('Requires Python @0@, @1@ found.'.format(python_version_req, python_version))
2231 endif
2232
2233 # Determine which user environment-dependent files that we want to install
2234 have_bash = find_program('bash', required : false).found() # For completion scripts
2235 bash_comp_dep = dependency('bash-completion', version: '>=2.0', required: false)
2236 have_sh = find_program('sh', required : false).found() # For glib-gettextize
2237
2238 # Some installed tests require a custom environment
2239 env_program = find_program('env', required: installed_tests_enabled)
2240
2241 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
2242 if host_system == 'sunos'
2243   glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
2244   glib_conf.set('_XOPEN_SOURCE', 2)
2245   glib_conf.set('__EXTENSIONS__',1)
2246 endif
2247
2248 # Sadly Meson does not expose this value:
2249 # https://github.com/mesonbuild/meson/pull/3460
2250 if host_system == 'windows'
2251   # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
2252   # with no explanation. Do the same here for now but this could be revisited if
2253   # if causes issues.
2254   export_dynamic_ldflags = []
2255 elif host_system == 'cygwin'
2256   export_dynamic_ldflags = ['-Wl,--export-all-symbols']
2257 elif host_system in ['darwin', 'ios']
2258   export_dynamic_ldflags = []
2259 elif host_system == 'sunos'
2260   export_dynamic_ldflags = []
2261 else
2262   export_dynamic_ldflags = ['-Wl,--export-dynamic']
2263 endif
2264
2265 win32_cflags = []
2266 win32_ldflags = []
2267 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
2268   # Ensure MSVC-compatible struct packing convention is used when
2269   # compiling for Win32 with gcc. It is used for the whole project and exposed
2270   # in glib-2.0.pc.
2271   win32_cflags = ['-mms-bitfields']
2272   add_project_arguments(win32_cflags, language : 'c')
2273
2274   # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
2275   win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi']
2276 elif host_system == 'cygwin'
2277   win32_ldflags = ['-luser32', '-lkernel32']
2278 endif
2279
2280 # Tracing: dtrace
2281 want_dtrace = get_option('dtrace')
2282 enable_dtrace = false
2283
2284 # Since dtrace support is opt-in we just error out if it was requested but
2285 # is not available. We don't bother with autodetection yet.
2286 if want_dtrace
2287   if glib_have_carbon
2288     error('GLib dtrace support not yet compatible with macOS dtrace')
2289   endif
2290   dtrace = find_program('dtrace', required : true) # error out if not found
2291   if not cc.has_header('sys/sdt.h')
2292     error('dtrace support needs sys/sdt.h header')
2293   endif
2294   # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
2295   dtrace_obj_gen = generator(dtrace,
2296     output : '@BASENAME@.o',
2297     arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2298   # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
2299   #               -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
2300   dtrace_hdr_gen = generator(dtrace,
2301     output : '@BASENAME@.h',
2302     arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2303   glib_conf.set('HAVE_DTRACE', 1)
2304   enable_dtrace = true
2305 endif
2306
2307 # systemtap
2308 want_systemtap = get_option('systemtap')
2309 enable_systemtap = false
2310
2311 if want_systemtap and enable_dtrace
2312   tapset_install_dir = get_option('tapset_install_dir')
2313   if tapset_install_dir == ''
2314     tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
2315   endif
2316   stp_cdata = configuration_data()
2317   stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
2318   stp_cdata.set('LT_CURRENT', minor_version * 100)
2319   stp_cdata.set('LT_REVISION', micro_version)
2320   enable_systemtap = true
2321 endif
2322
2323 test_timeout = 60
2324 test_timeout_slow = 180
2325
2326 pkg = import('pkgconfig')
2327 windows = import('windows')
2328 subdir('glib')
2329 subdir('gobject')
2330 subdir('gthread')
2331 subdir('gmodule')
2332 subdir('gio')
2333 subdir('fuzzing')
2334 if build_tests
2335   subdir('tests')
2336 endif
2337
2338 # xgettext is optional (on Windows for instance)
2339 if find_program('xgettext', required : get_option('nls')).found()
2340   subdir('po')
2341 endif
2342
2343 # Install glib-gettextize executable, if a UNIX-style shell is found
2344 if have_sh
2345   # These should not contain " quotes around the values
2346   gettextize_conf = configuration_data()
2347   gettextize_conf.set('PACKAGE', 'glib')
2348   gettextize_conf.set('VERSION', meson.project_version())
2349   gettextize_conf.set('prefix', glib_prefix)
2350   gettextize_conf.set('datarootdir', glib_datadir)
2351   gettextize_conf.set('datadir', glib_datadir)
2352   configure_file(input : 'glib-gettextize.in',
2353     install_dir : glib_bindir,
2354     output : 'glib-gettextize',
2355     configuration : gettextize_conf)
2356 endif
2357
2358 # Install m4 macros that other projects use
2359 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
2360   install_dir : join_paths(get_option('datadir'), 'aclocal'))
2361
2362 if host_system != 'windows'
2363   # Install Valgrind suppression file (except on Windows,
2364   # as Valgrind is currently not supported on Windows)
2365   install_data('glib.supp',
2366     install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
2367 endif
2368
2369 configure_file(output : 'config.h', configuration : glib_conf)
2370
2371 if host_system == 'windows'
2372   install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
2373 endif
2374
2375 if get_option('man')
2376   xsltproc = find_program('xsltproc', required : true)
2377   xsltproc_command = [
2378     xsltproc,
2379     '--nonet',
2380     '--stringparam', 'man.output.quietly', '1',
2381     '--stringparam', 'funcsynopsis.style', 'ansi',
2382     '--stringparam', 'man.th.extra1.suppress', '1',
2383     '--stringparam', 'man.authors.section.enabled', '0',
2384     '--stringparam', 'man.copyright.section.enabled', '0',
2385     '-o', '@OUTPUT@',
2386     'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
2387     '@INPUT@',
2388   ]
2389   man1_dir = join_paths(glib_prefix, get_option('mandir'), 'man1')
2390 endif
2391
2392 gnome = import('gnome')
2393 subdir('docs/reference')