1 project('glib', 'c', 'cpp',
3 # NOTE: We keep this pinned at 0.49 because that's what Debian 10 ships
4 meson_version : '>= 0.49.2',
6 'buildtype=debugoptimized',
12 cc = meson.get_compiler('c')
13 cxx = meson.get_compiler('cpp')
15 cc_can_run = not meson.is_cross_build() or meson.has_exe_wrapper()
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')
31 # -mms-bitfields vs -fnative-struct ?
34 host_system = host_machine.system()
36 if host_system == 'darwin'
37 ios_test_code = '''#include <TargetConditionals.h>
38 #if ! TARGET_OS_IPHONE
39 #error "Not iOS/tvOS/watchOS/iPhoneSimulator"
41 if cc.compiles(ios_test_code, name : 'building for iOS')
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()
53 interface_age = minor_version.is_odd() ? 0 : micro_version
54 binary_age = 100 * minor_version + micro_version
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)]
63 configinc = include_directories('.')
64 glibinc = include_directories('glib')
65 gobjectinc = include_directories('gobject')
66 gmoduleinc = include_directories('gmodule')
67 gioinc = include_directories('gio')
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'))
79 glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
82 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
84 if get_option('charsetalias_dir') != ''
85 glib_charsetaliasdir = join_paths(glib_prefix, get_option('charsetalias_dir'))
87 glib_charsetaliasdir = glib_libdir
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)
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')
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)
105 add_project_arguments('-D_GNU_SOURCE', language: 'c')
107 if host_system == 'qnx'
108 add_project_arguments('-D_QNX_SOURCE', language: 'c')
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')
117 ########################
118 # Configuration begins #
119 ########################
120 glib_conf = configuration_data()
121 glibconfig_conf = configuration_data()
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 = ''
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)
141 # used by the .rc.in files
142 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
144 glib_conf.set('_GNU_SOURCE', 1)
146 if host_system == 'windows'
147 # Poll doesn't work on devices on Windows
148 glib_conf.set('BROKEN_POLL', true)
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)
159 # Check for GNU visibility attributes
160 g_have_gnuc_visibility = cc.compiles('''
162 __attribute__ ((visibility ("hidden")))
167 __attribute__ ((visibility ("internal")))
172 __attribute__ ((visibility ("default")))
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
188 name : 'GNU C visibility attributes test')
190 if g_have_gnuc_visibility
191 glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
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']
205 elif cc.has_argument('-fvisibility=hidden')
206 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
207 glib_hidden_visibility_args = ['-fvisibility=hidden']
211 if get_option('default_library') == 'static'
212 glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
213 glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
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
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'''
229 glib_os = '#define G_OS_UNIX'
231 glibconfig_conf.set('glib_os', glib_os)
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
236 vs_crt_opt = get_option('b_vscrt')
237 if vs_crt_opt in ['mdd', 'mtd']
239 elif vs_crt_opt == 'from_buildtype'
240 if get_option('buildtype') == 'debug'
245 # Use debug/optimization flags to determine whether to enable debug or disable
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')
257 if not get_option('glib_assert')
258 glib_debug_cflags += ['-DG_DISABLE_ASSERT']
259 message('Disabling GLib asserts')
262 if not get_option('glib_checks')
263 glib_debug_cflags += ['-DG_DISABLE_CHECKS']
264 message('Disabling GLib checks')
267 add_project_arguments(glib_debug_cflags, language: 'c')
269 # check for header files
274 'dirent.h', # MSC does not come with this by default
309 'sys/time.h', # MSC does not come with this by default
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)
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'
339 if cc.has_header('linux/netlink.h')
340 glib_conf.set('HAVE_NETLINK', 1)
343 # Is statx() supported? Android systems don’t reliably support it as of August 2020.
348 #include <sys/stat.h>
352 struct statx stat_buf;
353 return statx (AT_FDCWD, "/", AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS | STATX_BTIME, &stat_buf);
356 if host_system != 'android' and cc.compiles(statx_code, name : 'statx() test')
357 glib_conf.set('HAVE_STATX', 1)
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)
366 struct_stat_blkprefix = '''
367 #include <sys/types.h>
368 #include <sys/stat.h>
372 #ifdef HAVE_SYS_STATFS_H
373 #include <sys/statfs.h>
375 #ifdef HAVE_SYS_PARAM_H
376 #include <sys/param.h>
378 #ifdef HAVE_SYS_MOUNT_H
379 #include <sys/mount.h>
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>' ],
406 foreach m : struct_members
407 header_check_prefix = glib_conf_prefix
409 header_check_prefix = header_check_prefix + m[2]
411 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
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)
422 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
424 '-Wduplicated-branches',
425 '-Wimplicit-fallthrough',
426 '-Wmisleading-indentation',
427 '-Wstrict-prototypes',
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.
438 # A zero-length format string shouldn't be considered an issue.
439 '-Wno-format-zero-length',
440 '-Werror=declaration-after-statement',
442 '-Werror=implicit-function-declaration',
444 '-Werror=missing-include-dirs',
445 '-Werror=missing-prototypes',
446 '-Werror=pointer-arith',
448 warning_c_link_args = [
451 if get_option('bsymbolic_functions')
452 warning_c_link_args += ['-Wl,-Bsymbolic-functions']
456 warning_c_link_args = []
459 add_project_arguments(cc.get_supported_arguments(warning_c_args), language: 'c')
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
467 glib_link_flags = cc.get_supported_link_arguments(warning_c_link_args)
469 # Windows SDK requirements and checks
470 if host_system == 'windows'
471 # Check whether we're building for UWP apps
474 #if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
475 #error "Not building for UWP"
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')]
484 # We require Windows 7+ on Win32
485 glib_conf.set('_WIN32_WINNT', '0x0601')
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']
557 if glib_conf.has('HAVE_SYS_STATVFS_H')
558 functions += ['statvfs']
560 have_func_statvfs = false
562 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
563 functions += ['statfs']
565 have_func_statfs = false
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)
583 set_variable('have_func_' + ifunc, false)
587 functions += ['if_indextoname', 'if_nametoindex']
590 # AIX splice is something else
591 if host_system != 'aix'
592 functions += ['splice']
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)
602 set_variable('have_func_' + f, false)
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)
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
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')
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)
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)
644 # Check whether strerror_r returns char *
645 if have_func_strerror_r
646 if cc.compiles('''#define _GNU_SOURCE
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;
655 name : 'strerror_r() returns char *')
656 glib_conf.set('STRERROR_R_CHAR_P', 1,
657 description: 'Defined if strerror_r returns char *')
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
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
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
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)
697 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
698 glib_conf.set('HAVE_RTLD_LAZY', 1)
701 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
702 glib_conf.set('HAVE_RTLD_NOW', 1)
705 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
706 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
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)
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
722 # at least on linux, statfs is the actual syscall
723 have_func_statvfs = false
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'
733 stat_func_to_use = 'neither'
735 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
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)
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')
753 osx_ldflags += ['-Wl,-framework,CoreFoundation']
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')
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
767 name : 'OS X 9 or later')
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"
775 name : 'Mac OS X Cocoa support')
778 glib_conf.set('HAVE_COCOA', true)
779 osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
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'])
788 if host_system == 'qnx'
789 glib_conf.set('HAVE_QNX', 1)
793 if cc.links('''#include <linux/futex.h>
794 #include <sys/syscall.h>
796 int main (int argc, char ** argv) {
797 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
799 }''', name : 'futex(2) system call')
800 glib_conf.set('HAVE_FUTEX', 1)
803 # Check for eventfd(2)
804 if cc.links('''#include <sys/eventfd.h>
806 int main (int argc, char ** argv) {
807 eventfd (0, EFD_CLOEXEC);
809 }''', name : 'eventfd(2) system call')
810 glib_conf.set('HAVE_EVENTFD', 1)
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;
820 if cc.compiles(uint128_t_src, name : '__uint128_t available')
821 glib_conf.set('HAVE_UINT128_T', 1)
824 clock_gettime_test_code = '''
827 int main (int argc, char ** argv) {
828 return clock_gettime(CLOCK_REALTIME, &t);
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')
838 dlopen_dlsym_test_code = '''
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);
845 f1 = dlsym (handle, "glib_underscore_test");
846 f2 = dlsym (handle, "_glib_underscore_test");
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')
857 have_dlopen_dlsym = false
860 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
862 if cc.compiles(glib_conf_prefix + '''
864 #ifdef HAVE_SYS_PARAM_H
865 #include <sys/param.h>
867 #ifdef HAVE_SYS_VFS_H
870 #ifdef HAVE_SYS_MOUNT_H
871 #include <sys/mount.h>
873 #ifdef HAVE_SYS_STATFS_H
874 #include <sys/statfs.h>
876 void some_func (void) {
879 }''', name : 'number of arguments to statfs() (n=2)')
880 glib_conf.set('STATFS_ARGS', 2)
881 elif cc.compiles(glib_conf_prefix + '''
883 #ifdef HAVE_SYS_PARAM_H
884 #include <sys/param.h>
886 #ifdef HAVE_SYS_VFS_H
889 #ifdef HAVE_SYS_MOUNT_H
890 #include <sys/mount.h>
892 #ifdef HAVE_SYS_STATFS_H
893 #include <sys/statfs.h>
895 void some_func (void) {
897 statfs("/", &st, sizeof (st), 0);
898 }''', name : 'number of arguments to statfs() (n=4)')
899 glib_conf.set('STATFS_ARGS', 4)
901 error('Unable to determine number of arguments to statfs()')
905 # open takes O_DIRECTORY as an option
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)
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)
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
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
957 vsnprintf_c99_test_code = '''
969 r = vsnprintf(buffer, 5, s, args);
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! */
979 r = vsnprintf(buffer, 0, s, args);
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
1002 have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
1003 glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
1006 snprintf_c99_test_code = '''
1017 r = snprintf(buffer, 5, "1234567");
1022 r = snprintf(buffer, 0, "1234567");
1027 r = snprintf(NULL, 0, "1234567");
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
1049 have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
1050 glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
1053 printf_unix98_test_code = '''
1061 sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
1062 if (strcmp ("2 3 1", buffer) == 0)
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
1074 have_good_printf = meson.get_cross_property('have_unix98_printf', false)
1075 glib_conf.set('HAVE_UNIX98_PRINTF', have_good_printf)
1079 if host_system == 'windows'
1080 glib_conf.set_quoted('EXEEXT', '.exe')
1082 glib_conf.set('EXEEXT', '')
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)
1090 if not use_system_printf
1091 # gnulib has vasprintf so override the previous check
1092 glib_conf.set('HAVE_VASPRINTF', 1)
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);
1100 }''', name : 'nl_langinfo and CODESET')
1101 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
1102 glib_conf.set('HAVE_CODESET', 1)
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) {
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);
1119 }''', name : 'nl_langinfo (PM_STR)')
1120 glib_conf.set('HAVE_LANGINFO_TIME', 1)
1122 if cc.links('''#include <langinfo.h>
1123 int main (int argc, char ** argv) {
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);
1136 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
1137 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
1140 # Check for nl_langinfo and alternative month names
1141 if cc.links('''#ifndef _GNU_SOURCE
1142 # define _GNU_SOURCE
1144 #include <langinfo.h>
1145 int main (int argc, char ** argv) {
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);
1160 }''', name : 'nl_langinfo (ALTMON_n)')
1161 glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
1164 # Check for nl_langinfo and abbreviated alternative month names
1165 if cc.links('''#ifndef _GNU_SOURCE
1166 # define _GNU_SOURCE
1168 #include <langinfo.h>
1169 int main (int argc, char ** argv) {
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);
1184 }''', name : 'nl_langinfo (_NL_ABALTMON_n)')
1185 glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
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 */')
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)
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)
1208 # Check if 'long long' works
1209 # jm_AC_TYPE_LONG_LONG
1210 if cc.compiles('''long long ll = 1LL;
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
1219 have_long_long = false
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)
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)
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)
1241 found_uintmax_t = false
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
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>
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
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'.
1272 glib_conf.set('HAVE_INTMAX_T', 1)
1274 glib_conf.set('intmax_t', 'long long')
1276 glib_conf.set('intmax_t', 'long')
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')
1285 long_long_size = cc.sizeof('long long')
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>')
1293 ssizet_size = cc.sizeof('ssize_t', prefix : '#include <unistd.h>')
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
1301 if long_long_size == long_size
1302 if cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1303 #pragma options langlvl=stdc99
1305 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
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
1317 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1322 long long *i2 = &i1;
1324 }''', name : 'int64_t is long long')
1325 int64_t_typedef = 'long long'
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')
1340 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
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>'))
1363 error('Compiler provides no native 16-bit integer type')
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)
1375 guint32_align = short_align
1381 guint32_align = int_align
1387 guint32_align = long_align
1389 error('Compiler provides no native 32-bit integer type')
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)
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')
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
1425 error('Compiler provides no native 64-bit integer type')
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)
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')
1442 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1444 glibconfig_conf.set('g_dir_separator', '\\\\')
1445 glibconfig_conf.set('g_searchpath_separator', ';')
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', ':')
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,
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; }
1473 unsigned short i = 0;
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; }
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; }
1493 unsigned long i = 0;
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; }
1503 unsigned long long i = 0;
1508 name : 'GCC size_t typedef is long long'),
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')
1541 error('Could not determine size of size_t.')
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)')
1566 error('Could not determine size of void *')
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.')
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)
1578 # XXX: https://gitlab.gnome.org/GNOME/glib/issues/1413
1579 if host_system == 'windows'
1580 g_module_suffix = 'dll'
1582 g_module_suffix = 'so'
1584 glibconfig_conf.set('g_module_suffix', g_module_suffix)
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)
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')
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')
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.
1610 foreach try_func : [ '__va_copy', 'va_copy' ]
1611 if cc.compiles('''#include <stdarg.h>
1614 # include "msvc_recommended_pragmas.h"
1616 void f (int i, ...) {
1617 va_list args1, args2;
1618 va_start (args1, i);
1620 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1622 va_end (args1); va_end (args2);
1627 }'''.format(try_func),
1628 name : try_func + ' check')
1629 va_copy_func = try_func
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
1636 glib_vacopy = '/* #undef G_VA_COPY */'
1639 va_list_val_copy_prog = '''
1642 void f (int i, ...) {
1643 va_list args1, args2;
1644 va_start (args1, i);
1646 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1648 va_end (args1); va_end (args2);
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
1659 glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
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)
1665 glibconfig_conf.set('glib_vacopy', glib_vacopy)
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__)
1673 }''', name : 'ISO C99 varargs macros in C')
1675 if g_have_iso_c_varargs
1676 glibconfig_conf.set('g_have_iso_c_varargs', '''
1678 # define G_HAVE_ISO_VARARGS 1
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__)
1687 }''', name : 'ISO C99 varargs macros in C++')
1689 if g_have_iso_cxx_varargs
1690 glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1692 # define G_HAVE_ISO_VARARGS 1
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)
1701 }''', name : 'GNUC varargs macros')
1703 if cc.has_header('alloca.h')
1704 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1706 has_syspoll = cc.has_header('sys/poll.h')
1707 has_systypes = cc.has_header('sys/types.h')
1709 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1711 has_winsock2 = cc.has_header('winsock2.h')
1713 if has_syspoll and has_systypes
1715 #include<sys/poll.h>
1716 #include<sys/types.h>'''
1719 #define _WIN32_WINNT @0@
1720 #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1723 error('FIX 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 ],
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)
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])
1752 # Internet address families
1753 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1754 if host_system == 'windows'
1756 #include <winsock2.h>'''
1759 #include <sys/types.h>
1760 #include <sys/socket.h>'''
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' ],
1771 foreach d : inet_defines
1772 val = cc.compute_int(d[0], prefix: inet_includes)
1773 glibconfig_conf.set(d[1], val)
1776 if host_system == 'windows'
1779 have_ipv6 = cc.has_type('struct in6_addr', prefix: '#include <netinet/in.h>')
1781 glib_conf.set('HAVE_IPV6', have_ipv6)
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
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
1793 # We can currently support the atomic ops natively when building GLib
1794 # with recent versions of GCC or MSVC.
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() {
1804 __sync_bool_compare_and_swap (&atomic, 2, 3);
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"
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)
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.')
1830 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1834 # Determination of thread implementation
1835 if host_system == 'windows' and not get_option('force_posix_threads')
1837 threads_implementation = 'win32'
1838 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1839 glib_conf.set('THREADS_WIN32', 1)
1841 thread_dep = dependency('threads')
1842 threads_implementation = 'posix'
1843 pthread_prefix = '''
1845 # define _GNU_SOURCE
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)
1853 if cc.has_header_symbol('pthread.h', 'pthread_attr_setinheritsched')
1854 glib_conf.set('HAVE_PTHREAD_ATTR_SETINHERITSCHED', 1)
1856 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1857 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1859 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1860 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1862 if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1863 glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1866 if cc.has_header_symbol('sys/syscall.h', 'SYS_sched_getattr')
1867 glib_conf.set('HAVE_SYS_SCHED_GETATTR', 1)
1870 # Assume that pthread_setname_np is available in some form; same as configure
1871 if cc.links(pthread_prefix + '''
1873 pthread_setname_np("example");
1876 name : 'pthread_setname_np(const char*)',
1877 dependencies : thread_dep)
1879 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1880 elif cc.links(pthread_prefix + '''
1882 pthread_setname_np(pthread_self(), "example");
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 + '''
1891 pthread_setname_np(pthread_self(), "%s", "example");
1894 name : 'pthread_setname_np(pthread_t, const char*, void*)',
1895 dependencies : thread_dep)
1897 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG', 1)
1898 elif cc.links(pthread_prefix + '''
1899 #include <pthread_np.h>
1901 pthread_set_name_np(pthread_self(), "example");
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)
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;
1927 return b > a ? 0 : 1;
1931 rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
1932 growing_stack = rres.returncode() == 0
1934 growing_stack = meson.get_cross_property('growing_stack', false)
1937 glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack)
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'
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')
1954 if ['auto', 'libc'].contains(iconv_opt) and cc.has_function('iconv_open')
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')]
1964 error('iconv implementation "@0@" not found'.format(iconv_opt))
1968 if get_option('internal_pcre')
1970 use_system_pcre = false
1972 pcre = dependency('libpcre', version: '>= 8.31', required : false) # Should check for Unicode support, too. FIXME
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)
1981 pcre = cc.find_library('pcre', required : false)
1985 use_system_pcre = pcre.found()
1987 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1989 use_pcre_static_flag = false
1991 if host_system == 'windows'
1992 if not use_system_pcre
1993 use_pcre_static_flag = true
1995 pcre_static = cc.links('''#define PCRE_STATIC
2003 name : 'Windows system PCRE is a static build')
2005 use_pcre_static_flag = true
2010 libm = cc.find_library('m', required : false)
2011 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
2013 if get_option('wrap_mode') == 'forcefallback'
2014 # Respects "wrap_mode=forcefallback" option
2015 libz_dep = subproject('zlib').get_variable('zlib_dep')
2017 # Don't use the bundled ZLib sources until we are sure that we can't find it on
2019 libz_dep = dependency('zlib', required : false)
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)
2026 libz_dep = cc.find_library('zlib1', required : false)
2027 if not libz_dep.found()
2028 libz_dep = cc.find_library('zlib', required : false)
2031 if not libz_dep.found() or not cc.has_header('zlib.h')
2032 libz_dep = subproject('zlib').get_variable('zlib_dep')
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.
2041 if cc.has_function('ngettext')
2042 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset')
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]
2063 libintl = disabler()
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
2071 libintl_deps = [libintl] + libintl_deps
2072 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset',
2073 dependencies : libintl_deps)
2077 glib_conf.set('HAVE_BIND_TEXTDOMAIN_CODESET', have_bind_textdomain_codeset)
2079 # We require gettext to always be present
2080 glib_conf.set('HAVE_DCGETTEXT', 1)
2081 glib_conf.set('HAVE_GETTEXT', 1)
2083 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
2085 # libmount is only used by gio, but we need to fetch the libs to generate the
2086 # pkg-config file below
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())
2093 if host_system == 'windows'
2094 winsock2 = cc.find_library('ws2_32')
2098 if host_system == 'linux'
2099 selinux_dep = dependency('libselinux', version: '>=2.2', required: get_option('selinux'))
2101 glib_conf.set('HAVE_SELINUX', selinux_dep.found())
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.
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')]
2120 error('No getxattr implementation found in C library or libxattr')
2123 glib_conf.set('HAVE_XATTR', 1)
2124 if cc.compiles(glib_conf_prefix + '''
2126 #ifdef HAVE_SYS_TYPES_H
2127 #include <sys/types.h>
2129 #ifdef HAVE_SYS_XATTR_H
2130 #include <sys/xattr.h>
2131 #elif HAVE_ATTR_XATTR_H
2132 #include <attr/xattr.h>
2136 ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
2139 name : 'XATTR_NOFOLLOW')
2140 glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
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')
2149 rres = cc.run('''#include <stdlib.h>
2153 (void) strlcpy (p, "hi", 10);
2154 if (strlcat (p, "bye", 0) != 3)
2158 name : 'OpenBSD strlcpy/strlcat')
2159 if rres.compiled() and rres.returncode() == 0
2160 glib_conf.set('HAVE_STRLCPY', 1)
2162 elif meson.get_cross_property('have_strlcpy', false)
2163 glib_conf.set('HAVE_STRLCPY', 1)
2167 cmdline_test_code = '''
2169 #include <sys/stat.h>
2176 /* This code is a dumbed-down version of g_file_get_contents() */
2180 #define BUFSIZE 1024
2181 char result[BUFSIZE];
2182 struct stat stat_buf;
2184 int fd = open ("/proc/self/cmdline", O_RDONLY|O_BINARY);
2187 if (fstat (fd, &stat_buf))
2190 if (stat_buf.st_size > 0 && S_ISREG (stat_buf.st_mode))
2192 if (read (fd, result, BUFSIZE) <= 0)
2197 FILE *f = fdopen (fd, "r");
2201 if (fread (result, 1, BUFSIZE, f) <= 0)
2211 exit (__getcmdline ());
2215 rres = cc.run(cmdline_test_code, name : '/proc/self/cmdline')
2216 have_proc_self_cmdline = rres.compiled() and rres.returncode() == 0
2218 have_proc_self_cmdline = meson.get_cross_property('have_proc_self_cmdline', false)
2221 glib_conf.set('HAVE_PROC_SELF_CMDLINE', have_proc_self_cmdline)
2223 python = import('python').find_installation('python3')
2224 # used for '#!/usr/bin/env <name>'
2225 python_name = 'python3'
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))
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
2238 # Some installed tests require a custom environment
2239 env_program = find_program('env', required: installed_tests_enabled)
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)
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
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 = []
2262 export_dynamic_ldflags = ['-Wl,--export-dynamic']
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
2271 win32_cflags = ['-mms-bitfields']
2272 add_project_arguments(win32_cflags, language : 'c')
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']
2281 want_dtrace = get_option('dtrace')
2282 enable_dtrace = false
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.
2288 error('GLib dtrace support not yet compatible with macOS dtrace')
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')
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
2308 want_systemtap = get_option('systemtap')
2309 enable_systemtap = false
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())
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
2324 test_timeout_slow = 180
2326 pkg = import('pkgconfig')
2327 windows = import('windows')
2338 # xgettext is optional (on Windows for instance)
2339 if find_program('xgettext', required : get_option('nls')).found()
2343 # Install glib-gettextize executable, if a UNIX-style shell is found
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)
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'))
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'))
2369 configure_file(output : 'config.h', configuration : glib_conf)
2371 if host_system == 'windows'
2372 install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
2375 if get_option('man')
2376 xsltproc = find_program('xsltproc', required : true)
2377 xsltproc_command = [
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',
2386 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
2389 man1_dir = join_paths(glib_prefix, get_option('mandir'), 'man1')
2392 gnome = import('gnome')
2393 subdir('docs/reference')