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 installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
91 installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
92 installed_tests_enabled = get_option('installed_tests')
93 installed_tests_template = files('template.test.in')
94 installed_tests_template_tap = files('template-tap.test.in')
96 # Don’t build the tests unless we can run them (either natively, in an exe wrapper, or by installing them for later use)
97 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)
99 add_project_arguments('-D_GNU_SOURCE', language: 'c')
101 if host_system == 'qnx'
102 add_project_arguments('-D_QNX_SOURCE', language: 'c')
105 # Disable strict aliasing;
106 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
107 if cc.has_argument('-fno-strict-aliasing')
108 add_project_arguments('-fno-strict-aliasing', language: 'c')
111 ########################
112 # Configuration begins #
113 ########################
114 glib_conf = configuration_data()
115 glibconfig_conf = configuration_data()
117 # accumulated list of defines as we check for them, so we can easily
118 # use them later in test programs (autoconf does this automatically)
119 glib_conf_prefix = ''
121 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
122 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
123 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
124 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
125 glib_conf.set('GLIB_BINARY_AGE', binary_age)
126 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
127 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
128 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
129 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
130 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
131 glib_conf.set_quoted('PACKAGE_URL', '')
132 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
133 glib_conf.set('ENABLE_NLS', 1)
135 # used by the .rc.in files
136 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
138 glib_conf.set('_GNU_SOURCE', 1)
140 if host_system == 'windows'
141 # Poll doesn't work on devices on Windows
142 glib_conf.set('BROKEN_POLL', true)
145 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
146 # FIXME: Ideally we shouldn't depend on this on Windows and should use
147 # 64 bit capable Windows API that also works with MSVC.
148 # The autotools build did set this for mingw and while meson sets it
149 # for gcc/clang by default, it doesn't do so on Windows.
150 glib_conf.set('_FILE_OFFSET_BITS', 64)
153 # Check for GNU visibility attributes
154 g_have_gnuc_visibility = cc.compiles('''
156 __attribute__ ((visibility ("hidden")))
161 __attribute__ ((visibility ("internal")))
166 __attribute__ ((visibility ("default")))
178 # Not supported by MSVC, but MSVC also won't support visibility,
179 # so it's OK to pass -Werror explicitly. Replace with
180 # override_options : 'werror=true' once that is supported
182 name : 'GNU C visibility attributes test')
184 if g_have_gnuc_visibility
185 glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
188 # Detect and set symbol visibility
189 glib_hidden_visibility_args = []
190 if get_option('default_library') != 'static'
191 if host_system == 'windows' or host_system == 'cygwin'
192 glib_conf.set('DLL_EXPORT', true)
193 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
194 glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
195 elif cc.has_argument('-fvisibility=hidden')
196 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
197 glib_hidden_visibility_args = ['-fvisibility=hidden']
199 elif cc.has_argument('-fvisibility=hidden')
200 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
201 glib_hidden_visibility_args = ['-fvisibility=hidden']
205 if get_option('default_library') == 'static'
206 glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
207 glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
210 # Cygwin glib port maintainers made it clear
211 # (via the patches they apply) that they want no
212 # part of glib W32 code, therefore we do not define
213 # G_PLATFORM_WIN32 for host_system == 'cygwin'.
214 # This makes G_PLATFORM_WIN32 a synonym for
216 if host_system == 'windows'
217 glib_os = '''#define G_OS_WIN32
218 #define G_PLATFORM_WIN32'''
219 elif host_system == 'cygwin'
220 glib_os = '''#define G_OS_UNIX
221 #define G_WITH_CYGWIN'''
223 glib_os = '#define G_OS_UNIX'
225 glibconfig_conf.set('glib_os', glib_os)
227 # We need to know the CRT being used to determine what .lib files we need on
228 # Visual Studio for dependencies that don't normally come with pkg-config files
230 vs_crt_opt = get_option('b_vscrt')
231 if vs_crt_opt in ['mdd', 'mtd']
233 elif vs_crt_opt == 'from_buildtype'
234 if get_option('buildtype') == 'debug'
239 # Use debug/optimization flags to determine whether to enable debug or disable
241 glib_debug_cflags = []
242 glib_debug = get_option('glib_debug')
243 if glib_debug.enabled() or (glib_debug.auto() and get_option('debug'))
244 glib_debug_cflags += ['-DG_ENABLE_DEBUG']
245 message('Enabling various debug infrastructure')
246 elif get_option('optimization') in ['2', '3', 's']
247 glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
248 message('Disabling cast checks')
251 if not get_option('glib_assert')
252 glib_debug_cflags += ['-DG_DISABLE_ASSERT']
253 message('Disabling GLib asserts')
256 if not get_option('glib_checks')
257 glib_debug_cflags += ['-DG_DISABLE_CHECKS']
258 message('Disabling GLib checks')
261 add_project_arguments(glib_debug_cflags, language: 'c')
263 # check for header files
268 'dirent.h', # MSC does not come with this by default
303 'sys/time.h', # MSC does not come with this by default
320 define = 'HAVE_' + h.underscorify().to_upper()
321 glib_conf.set(define, 1)
322 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
326 # FIXME: Use cc.check_header from Meson 0.47.
327 # FreeBSD includes a malloc.h which always throw compilation error.
328 if cc.compiles('#include <malloc.h>', name : 'malloc.h')
329 glib_conf.set('HAVE_MALLOC_H', 1)
330 glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
333 if cc.has_header('linux/netlink.h')
334 glib_conf.set('HAVE_NETLINK', 1)
337 # Is statx() supported? Android systems don’t reliably support it as of August 2020.
342 #include <sys/stat.h>
346 struct statx stat_buf;
347 return statx (AT_FDCWD, "/", AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS | STATX_BTIME, &stat_buf);
350 if host_system != 'android' and cc.compiles(statx_code, name : 'statx() test')
351 glib_conf.set('HAVE_STATX', 1)
354 if glib_conf.has('HAVE_LOCALE_H')
355 if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
356 glib_conf.set('HAVE_LC_MESSAGES', 1)
360 struct_stat_blkprefix = '''
361 #include <sys/types.h>
362 #include <sys/stat.h>
366 #ifdef HAVE_SYS_STATFS_H
367 #include <sys/statfs.h>
369 #ifdef HAVE_SYS_PARAM_H
370 #include <sys/param.h>
372 #ifdef HAVE_SYS_MOUNT_H
373 #include <sys/mount.h>
378 [ 'stat', 'st_mtimensec' ],
379 [ 'stat', 'st_mtim.tv_nsec' ],
380 [ 'stat', 'st_atimensec' ],
381 [ 'stat', 'st_atim.tv_nsec' ],
382 [ 'stat', 'st_ctimensec' ],
383 [ 'stat', 'st_ctim.tv_nsec' ],
384 [ 'stat', 'st_birthtime' ],
385 [ 'stat', 'st_birthtimensec' ],
386 [ 'stat', 'st_birthtim' ],
387 [ 'stat', 'st_birthtim.tv_nsec' ],
388 [ 'stat', 'st_blksize', struct_stat_blkprefix ],
389 [ 'stat', 'st_blocks', struct_stat_blkprefix ],
390 [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
391 [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
392 [ 'dirent', 'd_type', '''#include <sys/types.h>
393 #include <dirent.h>''' ],
394 [ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
395 [ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
396 [ 'tm', 'tm_gmtoff', '#include <time.h>' ],
397 [ 'tm', '__tm_gmtoff', '#include <time.h>' ],
400 foreach m : struct_members
401 header_check_prefix = glib_conf_prefix
403 header_check_prefix = header_check_prefix + m[2]
405 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
407 if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
408 define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
409 glib_conf.set(define, 1)
410 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
416 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
418 '-Wduplicated-branches',
419 '-Wimplicit-fallthrough',
420 '-Wmisleading-indentation',
421 '-Wstrict-prototypes',
423 # Due to maintained deprecated code, we do not want to see unused parameters
424 '-Wno-unused-parameter',
425 # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
426 # building with -Wbad-function-cast.
427 '-Wno-bad-function-cast',
428 '-Wno-cast-function-type',
429 # Due to function casts through (void*) we cannot support -Wpedantic:
430 # https://wiki.gnome.org/Projects/GLib/CompilerRequirements#Function_pointer_conversions.
432 # A zero-length format string shouldn't be considered an issue.
433 '-Wno-format-zero-length',
434 '-Werror=declaration-after-statement',
436 '-Werror=implicit-function-declaration',
438 '-Werror=missing-include-dirs',
439 '-Werror=missing-prototypes',
440 '-Werror=pointer-arith',
442 warning_c_link_args = [
445 if get_option('bsymbolic_functions')
446 warning_c_link_args += ['-Wl,-Bsymbolic-functions']
450 warning_c_link_args = []
453 add_project_arguments(cc.get_supported_arguments(warning_c_args), language: 'c')
455 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
456 # means we cannot use that flag in add_project_link_arguments(), and must add
457 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
458 # because that is what the autotools build did.
459 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
461 glib_link_flags = cc.get_supported_link_arguments(warning_c_link_args)
463 # Windows SDK requirements and checks
464 if host_system == 'windows'
465 # Check whether we're building for UWP apps
468 #if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
469 #error "Not building for UWP"
471 if cc.compiles(code, name : 'building for UWP')
472 glib_conf.set('G_WINAPI_ONLY_APP', true)
473 # We require Windows 10+ on WinRT
474 glib_conf.set('_WIN32_WINNT', '0x0A00')
475 uwp_gio_deps = [cc.find_library('shcore'),
476 cc.find_library('runtimeobject')]
478 # We require Windows 7+ on Win32
479 glib_conf.set('_WIN32_WINNT', '0x0601')
545 # _NSGetEnviron is available on iOS too, but its usage gets apps rejected from
546 # the app store since it's considered 'private API'
547 if host_system == 'darwin'
548 functions += ['_NSGetEnviron']
551 if glib_conf.has('HAVE_SYS_STATVFS_H')
552 functions += ['statvfs']
554 have_func_statvfs = false
556 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
557 functions += ['statfs']
559 have_func_statfs = false
562 if host_system == 'windows'
563 iphlpapi_dep = cc.find_library('iphlpapi')
564 iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
565 foreach ifunc : iphlpapi_funcs
566 iphl_prefix = '''#define _WIN32_WINNT @0@
567 #include <winsock2.h>
568 #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
569 if cc.has_function(ifunc,
570 prefix : iphl_prefix,
571 dependencies : iphlpapi_dep)
572 idefine = 'HAVE_' + ifunc.underscorify().to_upper()
573 glib_conf.set(idefine, 1)
574 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
575 set_variable('have_func_' + ifunc, true)
577 set_variable('have_func_' + ifunc, false)
581 functions += ['if_indextoname', 'if_nametoindex']
584 # AIX splice is something else
585 if host_system != 'aix'
586 functions += ['splice']
589 foreach f : functions
590 if cc.has_function(f)
591 define = 'HAVE_' + f.underscorify().to_upper()
592 glib_conf.set(define, 1)
593 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
594 set_variable('have_func_' + f, true)
596 set_variable('have_func_' + f, false)
600 # Check that stpcpy() is usable; must use header.
601 # cc.has_function() in some cases (clang, gcc 10+) assumes that if the
602 # compiler provides a builtin of the same name that the function exists, while
603 # it's in fact not provided by any header or library. This is true for
604 # stpcpy() on Windows using clang and gcc as well as posix_memalign() using
605 # gcc on Windows. Skip these checks on Windows for now to avoid false
606 # positives. See https://github.com/mesonbuild/meson/pull/7116,
607 # https://github.com/mesonbuild/meson/issues/3672 and
608 # https://github.com/mesonbuild/meson/issues/5628.
609 # FIXME: Once meson no longer returns success for stpcpy() and
610 # posix_memalign() on Windows using GCC and clang we can remove this.
611 if host_system != 'windows' and cc.has_function('stpcpy', prefix : '#include <string.h>')
612 glib_conf.set('HAVE_STPCPY', 1)
615 # When building for Android-20 and earlier, require Meson 0.54.2 or newer.
616 # This is needed, because Meson build versions prior to 0.54.2 return false
617 # positive for stpcpy has_function check when building for legacy Android.
618 if host_system == 'android'
619 android_is_older = cc.compiles('''#if __ANDROID_API__ >= 21
620 #error Android is 21 or newer
622 if android_is_older and meson.version().version_compare('< 0.54.2')
623 error('Compiling for <Android-21 requires Meson 0.54.2 or newer')
628 # Check that posix_memalign() is usable; must use header
629 if host_system != 'windows' and cc.has_function('posix_memalign', prefix : '#include <stdlib.h>')
630 glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
633 # Check that posix_spawn() is usable; must use header
634 if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
635 glib_conf.set('HAVE_POSIX_SPAWN', 1)
638 # Check whether strerror_r returns char *
639 if have_func_strerror_r
640 if cc.compiles('''#define _GNU_SOURCE
643 char error_string[256];
644 char *ptr = strerror_r (-2, error_string, 256);
645 char c = *strerror_r (-2, error_string, 256);
646 return c != 0 && ptr != (void*) 0L;
649 name : 'strerror_r() returns char *')
650 glib_conf.set('STRERROR_R_CHAR_P', 1,
651 description: 'Defined if strerror_r returns char *')
655 # Special-case these functions that have alternative names on Windows/MSVC
656 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
657 glib_conf.set('HAVE_SNPRINTF', 1)
658 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
659 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
660 hack_define = '1\n#define snprintf _snprintf'
661 glib_conf.set('HAVE_SNPRINTF', hack_define)
662 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
665 if cc.has_function('strcasecmp')
666 glib_conf.set('HAVE_STRCASECMP', 1)
667 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
668 elif cc.has_function('_stricmp')
669 hack_define = '1\n#define strcasecmp _stricmp'
670 glib_conf.set('HAVE_STRCASECMP', hack_define)
671 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
674 if cc.has_function('strncasecmp')
675 glib_conf.set('HAVE_STRNCASECMP', 1)
676 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
677 elif cc.has_function('_strnicmp')
678 hack_define = '1\n#define strncasecmp _strnicmp'
679 glib_conf.set('HAVE_STRNCASECMP', hack_define)
680 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
683 if cc.has_header_symbol('sys/sysmacros.h', 'major')
684 glib_conf.set('MAJOR_IN_SYSMACROS', 1)
685 elif cc.has_header_symbol('sys/mkdev.h', 'major')
686 glib_conf.set('MAJOR_IN_MKDEV', 1)
687 elif cc.has_header_symbol('sys/types.h', 'major')
688 glib_conf.set('MAJOR_IN_TYPES', 1)
691 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
692 glib_conf.set('HAVE_RTLD_LAZY', 1)
695 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
696 glib_conf.set('HAVE_RTLD_NOW', 1)
699 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
700 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
703 have_rtld_next = false
704 if cc.has_header_symbol('dlfcn.h', 'RTLD_NEXT', args: '-D_GNU_SOURCE')
705 have_rtld_next = true
706 glib_conf.set('HAVE_RTLD_NEXT', 1)
709 # Check whether to use statfs or statvfs
710 # Some systems have both statfs and statvfs, pick the most "native" for these
711 if have_func_statfs and have_func_statvfs
712 # on solaris and irix, statfs doesn't even have the f_bavail field
713 if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
714 have_func_statfs = false
716 # at least on linux, statfs is the actual syscall
717 have_func_statvfs = false
721 glib_conf.set('USE_STATFS', 1)
722 stat_func_to_use = 'statfs'
723 elif have_func_statvfs
724 glib_conf.set('USE_STATVFS', 1)
725 stat_func_to_use = 'statvfs'
727 stat_func_to_use = 'neither'
729 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
731 if host_system == 'linux'
732 if cc.has_function('mkostemp',
733 prefix: '''#define _GNU_SOURCE
734 #include <stdlib.h>''')
735 glib_conf.set('HAVE_MKOSTEMP', 1)
740 glib_have_os_x_9_or_later = false
741 glib_have_carbon = false
742 glib_have_cocoa = false
743 if host_system == 'darwin'
744 add_languages('objc')
745 objcc = meson.get_compiler('objc')
747 osx_ldflags += ['-Wl,-framework,CoreFoundation']
749 # Mac OS X Carbon support
750 glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
751 #include <CoreServices/CoreServices.h>''',
752 name : 'Mac OS X Carbon support')
755 glib_conf.set('HAVE_CARBON', true)
756 osx_ldflags += '-Wl,-framework,Carbon'
757 glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
758 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
759 #error Compiling for minimum OS X version before 10.9
761 name : 'OS X 9 or later')
764 # Mac OS X Cocoa support
765 glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
766 #ifdef GNUSTEP_BASE_VERSION
767 #error "Detected GNUstep, not Cocoa"
769 name : 'Mac OS X Cocoa support')
772 glib_conf.set('HAVE_COCOA', true)
773 osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
776 # FIXME: libgio mix C and objC source files and there is no way to reliably
777 # know which language flags it's going to use to link. Add to both languages
778 # for now. See https://github.com/mesonbuild/meson/issues/3585.
779 add_project_link_arguments(osx_ldflags, language : ['objc', 'c'])
782 if host_system == 'qnx'
783 glib_conf.set('HAVE_QNX', 1)
787 if cc.links('''#include <linux/futex.h>
788 #include <sys/syscall.h>
790 int main (int argc, char ** argv) {
791 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
793 }''', name : 'futex(2) system call')
794 glib_conf.set('HAVE_FUTEX', 1)
797 # Check for eventfd(2)
798 if cc.links('''#include <sys/eventfd.h>
800 int main (int argc, char ** argv) {
801 eventfd (0, EFD_CLOEXEC);
803 }''', name : 'eventfd(2) system call')
804 glib_conf.set('HAVE_EVENTFD', 1)
807 # Check for __uint128_t (gcc) by checking for 128-bit division
808 uint128_t_src = '''int main() {
809 static __uint128_t v1 = 100;
810 static __uint128_t v2 = 10;
811 static __uint128_t u;
814 if cc.compiles(uint128_t_src, name : '__uint128_t available')
815 glib_conf.set('HAVE_UINT128_T', 1)
818 clock_gettime_test_code = '''
821 int main (int argc, char ** argv) {
822 return clock_gettime(CLOCK_REALTIME, &t);
825 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
826 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
827 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
828 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
829 librt = cc.find_library('rt')
832 dlopen_dlsym_test_code = '''
834 int glib_underscore_test (void) { return 42; }
835 int main (int argc, char ** argv) {
836 void *f1 = (void*)0, *f2 = (void*)0, *handle;
837 handle = dlopen ((void*)0, 0);
839 f1 = dlsym (handle, "glib_underscore_test");
840 f2 = dlsym (handle, "_glib_underscore_test");
845 if cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
846 have_dlopen_dlsym = true
847 elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
848 have_dlopen_dlsym = true
849 libdl_dep = cc.find_library('dl')
851 have_dlopen_dlsym = false
854 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
856 if cc.compiles(glib_conf_prefix + '''
858 #ifdef HAVE_SYS_PARAM_H
859 #include <sys/param.h>
861 #ifdef HAVE_SYS_VFS_H
864 #ifdef HAVE_SYS_MOUNT_H
865 #include <sys/mount.h>
867 #ifdef HAVE_SYS_STATFS_H
868 #include <sys/statfs.h>
870 void some_func (void) {
873 }''', name : 'number of arguments to statfs() (n=2)')
874 glib_conf.set('STATFS_ARGS', 2)
875 elif cc.compiles(glib_conf_prefix + '''
877 #ifdef HAVE_SYS_PARAM_H
878 #include <sys/param.h>
880 #ifdef HAVE_SYS_VFS_H
883 #ifdef HAVE_SYS_MOUNT_H
884 #include <sys/mount.h>
886 #ifdef HAVE_SYS_STATFS_H
887 #include <sys/statfs.h>
889 void some_func (void) {
891 statfs("/", &st, sizeof (st), 0);
892 }''', name : 'number of arguments to statfs() (n=4)')
893 glib_conf.set('STATFS_ARGS', 4)
895 error('Unable to determine number of arguments to statfs()')
899 # open takes O_DIRECTORY as an option
901 if cc.compiles('''#include <fcntl.h>
902 #include <sys/types.h>
903 #include <sys/stat.h>
904 void some_func (void) {
905 open(0, O_DIRECTORY, 0);
906 }''', name : 'open() option O_DIRECTORY')
907 glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
910 # fcntl takes F_FULLFSYNC as an option
911 # See https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html
912 if cc.compiles('''#include <fcntl.h>
913 #include <sys/types.h>
914 #include <sys/stat.h>
915 void some_func (void) {
916 fcntl(0, F_FULLFSYNC, 0);
917 }''', name : 'fcntl() option F_FULLFSYNC')
918 glib_conf.set('HAVE_FCNTL_F_FULLFSYNC', 1)
921 # Check whether there is a vsnprintf() function with C99 semantics installed.
922 # (similar tests to AC_FUNC_VSNPRINTF_C99)
923 # Check whether there is a snprintf() function with C99 semantics installed.
924 # (similar tests to AC_FUNC_SNPRINTF_C99)
925 # Check whether there is a printf() function with Unix98 semantics installed.
926 # (similar tests to AC_FUNC_PRINTF_UNIX98)
927 have_good_vsnprintf = false
928 have_good_snprintf = false
929 have_good_printf = false
931 if host_system == 'windows' and (cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl')
932 # Unfortunately the Visual Studio 2015+ implementations of C99-style
933 # snprintf and vsnprintf don't seem to be quite good enough.
934 # (Sorry, I don't know exactly what is the problem,
935 # but it is related to floating point formatting and decimal point vs. comma.)
936 # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
937 # rigorous enough to notice, though.
938 glib_conf.set('HAVE_C99_SNPRINTF', false)
939 glib_conf.set('HAVE_C99_VSNPRINTF', false)
940 glib_conf.set('HAVE_UNIX98_PRINTF', false)
941 elif not cc_can_run and host_system in ['ios', 'darwin']
942 # All these are true when compiling natively on macOS, so we should use good
943 # defaults when building for iOS and tvOS.
944 glib_conf.set('HAVE_C99_SNPRINTF', true)
945 glib_conf.set('HAVE_C99_VSNPRINTF', true)
946 glib_conf.set('HAVE_UNIX98_PRINTF', true)
947 have_good_vsnprintf = true
948 have_good_snprintf = true
949 have_good_printf = true
951 vsnprintf_c99_test_code = '''
963 r = vsnprintf(buffer, 5, s, args);
969 /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
970 implementation. The above will return 7 but if you replace
971 the size of the buffer with 0, it borks! */
973 r = vsnprintf(buffer, 0, s, args);
990 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
991 if rres.compiled() and rres.returncode() == 0
992 glib_conf.set('HAVE_C99_VSNPRINTF', 1)
993 have_good_vsnprintf = true
996 have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
997 glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
1000 snprintf_c99_test_code = '''
1011 r = snprintf(buffer, 5, "1234567");
1016 r = snprintf(buffer, 0, "1234567");
1021 r = snprintf(NULL, 0, "1234567");
1037 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
1038 if rres.compiled() and rres.returncode() == 0
1039 glib_conf.set('HAVE_C99_SNPRINTF', 1)
1040 have_good_snprintf = true
1043 have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
1044 glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
1047 printf_unix98_test_code = '''
1055 sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
1056 if (strcmp ("2 3 1", buffer) == 0)
1062 rres = cc.run(printf_unix98_test_code, name : 'Unix98 printf positional parameters')
1063 if rres.compiled() and rres.returncode() == 0
1064 glib_conf.set('HAVE_UNIX98_PRINTF', 1)
1065 have_good_printf = true
1068 have_good_printf = meson.get_cross_property('have_unix98_printf', false)
1069 glib_conf.set('HAVE_UNIX98_PRINTF', have_good_printf)
1073 if host_system == 'windows'
1074 glib_conf.set_quoted('EXEEXT', '.exe')
1076 glib_conf.set('EXEEXT', '')
1079 # Our printf is 'good' only if vsnpintf()/snprintf()/printf() supports C99 well enough
1080 use_system_printf = have_good_vsnprintf and have_good_snprintf and have_good_printf
1081 glib_conf.set('USE_SYSTEM_PRINTF', use_system_printf)
1082 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', use_system_printf)
1084 if not use_system_printf
1085 # gnulib has vasprintf so override the previous check
1086 glib_conf.set('HAVE_VASPRINTF', 1)
1089 # Check for nl_langinfo and CODESET
1090 if cc.links('''#include <langinfo.h>
1091 int main (int argc, char ** argv) {
1092 char *codeset = nl_langinfo (CODESET);
1094 }''', name : 'nl_langinfo and CODESET')
1095 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
1096 glib_conf.set('HAVE_CODESET', 1)
1099 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
1100 if cc.links('''#include <langinfo.h>
1101 int main (int argc, char ** argv) {
1103 str = nl_langinfo (PM_STR);
1104 str = nl_langinfo (D_T_FMT);
1105 str = nl_langinfo (D_FMT);
1106 str = nl_langinfo (T_FMT);
1107 str = nl_langinfo (T_FMT_AMPM);
1108 str = nl_langinfo (MON_1);
1109 str = nl_langinfo (ABMON_12);
1110 str = nl_langinfo (DAY_1);
1111 str = nl_langinfo (ABDAY_7);
1113 }''', name : 'nl_langinfo (PM_STR)')
1114 glib_conf.set('HAVE_LANGINFO_TIME', 1)
1116 if cc.links('''#include <langinfo.h>
1117 int main (int argc, char ** argv) {
1119 str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
1120 str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
1121 str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
1122 str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
1123 str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
1124 str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
1125 str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
1126 str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
1127 str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
1128 str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
1130 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
1131 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
1134 # Check for nl_langinfo and alternative month names
1135 if cc.links('''#ifndef _GNU_SOURCE
1136 # define _GNU_SOURCE
1138 #include <langinfo.h>
1139 int main (int argc, char ** argv) {
1141 str = nl_langinfo (ALTMON_1);
1142 str = nl_langinfo (ALTMON_2);
1143 str = nl_langinfo (ALTMON_3);
1144 str = nl_langinfo (ALTMON_4);
1145 str = nl_langinfo (ALTMON_5);
1146 str = nl_langinfo (ALTMON_6);
1147 str = nl_langinfo (ALTMON_7);
1148 str = nl_langinfo (ALTMON_8);
1149 str = nl_langinfo (ALTMON_9);
1150 str = nl_langinfo (ALTMON_10);
1151 str = nl_langinfo (ALTMON_11);
1152 str = nl_langinfo (ALTMON_12);
1154 }''', name : 'nl_langinfo (ALTMON_n)')
1155 glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
1158 # Check for nl_langinfo and abbreviated alternative month names
1159 if cc.links('''#ifndef _GNU_SOURCE
1160 # define _GNU_SOURCE
1162 #include <langinfo.h>
1163 int main (int argc, char ** argv) {
1165 str = nl_langinfo (_NL_ABALTMON_1);
1166 str = nl_langinfo (_NL_ABALTMON_2);
1167 str = nl_langinfo (_NL_ABALTMON_3);
1168 str = nl_langinfo (_NL_ABALTMON_4);
1169 str = nl_langinfo (_NL_ABALTMON_5);
1170 str = nl_langinfo (_NL_ABALTMON_6);
1171 str = nl_langinfo (_NL_ABALTMON_7);
1172 str = nl_langinfo (_NL_ABALTMON_8);
1173 str = nl_langinfo (_NL_ABALTMON_9);
1174 str = nl_langinfo (_NL_ABALTMON_10);
1175 str = nl_langinfo (_NL_ABALTMON_11);
1176 str = nl_langinfo (_NL_ABALTMON_12);
1178 }''', name : 'nl_langinfo (_NL_ABALTMON_n)')
1179 glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
1182 # Check if C compiler supports the 'signed' keyword
1183 if not cc.compiles('''signed char x;''', name : 'signed')
1184 glib_conf.set('signed', '/* NOOP */')
1187 # Check if the ptrdiff_t type exists
1188 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
1189 glib_conf.set('HAVE_PTRDIFF_T', 1)
1192 # Check for sig_atomic_t type
1193 if cc.links('''#include <signal.h>
1194 #include <sys/types.h>
1195 sig_atomic_t val = 42;
1196 int main (int argc, char ** argv) {
1197 return val == 42 ? 0 : 1;
1198 }''', name : 'sig_atomic_t')
1199 glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
1202 # Check if 'long long' works
1203 # jm_AC_TYPE_LONG_LONG
1204 if cc.compiles('''long long ll = 1LL;
1206 int some_func (void) {
1207 long long llmax = (long long) -1;
1208 return ll << i | ll >> i | llmax / ll | llmax % ll;
1209 }''', name : 'long long')
1210 glib_conf.set('HAVE_LONG_LONG', 1)
1211 have_long_long = true
1213 have_long_long = false
1216 # Test whether the compiler supports the 'long double' type.
1217 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
1218 long double foo = 0.0;
1219 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
1220 int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
1221 name : 'long double')
1222 glib_conf.set('HAVE_LONG_DOUBLE', 1)
1225 # Test whether <stddef.h> has the 'wchar_t' type.
1226 if cc.has_header_symbol('stddef.h', 'wchar_t')
1227 glib_conf.set('HAVE_WCHAR_T', 1)
1230 # Test whether <wchar.h> has the 'wint_t' type.
1231 if cc.has_header_symbol('wchar.h', 'wint_t')
1232 glib_conf.set('HAVE_WINT_T', 1)
1235 found_uintmax_t = false
1237 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
1238 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1239 # jm_AC_HEADER_INTTYPES_H
1240 if cc.compiles('''#include <sys/types.h>
1241 #include <inttypes.h>
1242 void some_func (void) {
1243 uintmax_t i = (uintmax_t) -1;
1244 }''', name : 'uintmax_t in inttypes.h')
1245 glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1246 found_uintmax_t = true
1249 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1250 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1251 # jm_AC_HEADER_STDINT_H
1252 if cc.compiles('''#include <sys/types.h>
1254 void some_func (void) {
1255 uintmax_t i = (uintmax_t) -1;
1256 }''', name : 'uintmax_t in stdint.h')
1257 glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1258 found_uintmax_t = true
1261 # Define intmax_t to 'long' or 'long long'
1262 # if it is not already defined in <stdint.h> or <inttypes.h>.
1263 # For simplicity, we assume that a header file defines 'intmax_t' if and
1264 # only if it defines 'uintmax_t'.
1266 glib_conf.set('HAVE_INTMAX_T', 1)
1268 glib_conf.set('intmax_t', 'long long')
1270 glib_conf.set('intmax_t', 'long')
1273 char_size = cc.sizeof('char')
1274 short_size = cc.sizeof('short')
1275 int_size = cc.sizeof('int')
1276 voidp_size = cc.sizeof('void*')
1277 long_size = cc.sizeof('long')
1279 long_long_size = cc.sizeof('long long')
1283 sizet_size = cc.sizeof('size_t')
1284 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1285 ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1287 ssizet_size = cc.sizeof('ssize_t', prefix : '#include <unistd.h>')
1290 # Some platforms (Apple) hard-code int64_t to long long instead of
1291 # using long on 64-bit architectures. This can cause type mismatch
1292 # warnings when trying to interface with code using the standard
1293 # library type. Test for the warnings and set gint64 to whichever
1295 if long_long_size == long_size
1296 if cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1297 #pragma options langlvl=stdc99
1299 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1306 }''', name : 'int64_t is long')
1307 int64_t_typedef = 'long'
1308 elif cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1309 #pragma options langlvl=stdc99
1311 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1316 long long *i2 = &i1;
1318 }''', name : 'int64_t is long long')
1319 int64_t_typedef = 'long long'
1324 char_align = cc.alignment('char')
1325 short_align = cc.alignment('short')
1326 int_align = cc.alignment('int')
1327 voidp_align = cc.alignment('void*')
1328 long_align = cc.alignment('long')
1329 long_long_align = cc.alignment('long long')
1330 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1331 # be 64-bit in C99, and it is available on all supported compilers
1332 sizet_align = cc.alignment('size_t')
1334 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1336 glib_conf.set('SIZEOF_CHAR', char_size)
1337 glib_conf.set('SIZEOF_INT', int_size)
1338 glib_conf.set('SIZEOF_SHORT', short_size)
1339 glib_conf.set('SIZEOF_LONG', long_size)
1340 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1341 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1342 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1343 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1344 glib_conf.set('SIZEOF_WCHAR_T', cc.sizeof('wchar_t', prefix: '#include <stddef.h>'))
1357 error('Compiler provides no native 16-bit integer type')
1359 glibconfig_conf.set('gint16', gint16)
1360 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1361 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1362 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1369 guint32_align = short_align
1375 guint32_align = int_align
1381 guint32_align = long_align
1383 error('Compiler provides no native 32-bit integer type')
1385 glibconfig_conf.set('gint32', gint32)
1386 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1387 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1388 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1389 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1397 gint64_constant='(val)'
1398 guint64_constant='(val)'
1399 guint64_align = int_align
1400 elif long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long')
1406 gint64_constant='(val##L)'
1407 guint64_constant='(val##UL)'
1408 guint64_align = long_align
1409 elif long_long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long long')
1410 gint64 = 'long long'
1411 glib_extension='G_GNUC_EXTENSION '
1412 gint64_modifier=int64_m
1413 gint64_format=int64_m + 'i'
1414 guint64_format=int64_m + 'u'
1415 gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1416 guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1417 guint64_align = long_long_align
1419 error('Compiler provides no native 64-bit integer type')
1421 glibconfig_conf.set('glib_extension', glib_extension)
1422 glibconfig_conf.set('gint64', gint64)
1423 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1424 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1425 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1426 glibconfig_conf.set('gint64_constant', gint64_constant)
1427 glibconfig_conf.set('guint64_constant', guint64_constant)
1428 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1430 if host_system == 'windows'
1431 glibconfig_conf.set('g_pid_type', 'void*')
1432 glibconfig_conf.set_quoted('g_pid_format', 'p')
1433 if host_machine.cpu_family() == 'x86_64'
1434 glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1436 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1438 glibconfig_conf.set('g_dir_separator', '\\\\')
1439 glibconfig_conf.set('g_searchpath_separator', ';')
1441 glibconfig_conf.set('g_pid_type', 'int')
1442 glibconfig_conf.set_quoted('g_pid_format', 'i')
1443 glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1444 glibconfig_conf.set('g_dir_separator', '/')
1445 glibconfig_conf.set('g_searchpath_separator', ':')
1448 g_sizet_compatibility = {
1449 'short': sizet_size == short_size,
1450 'int': sizet_size == int_size,
1451 'long': sizet_size == long_size,
1452 'long long': sizet_size == long_long_size,
1455 # Do separate checks for gcc/clang (and ignore other compilers for now), since
1456 # we need to explicitly pass -Werror to the compilers.
1457 # FIXME: https://github.com/mesonbuild/meson/issues/5399
1458 # We can’t simplify these checks using a foreach loop because dictionary keys
1459 # have to be string literals.
1460 # FIXME: https://github.com/mesonbuild/meson/issues/5231
1461 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
1462 g_sizet_compatibility += {
1463 'short': g_sizet_compatibility['short'] and cc.compiles(
1464 '''#include <stddef.h>
1465 size_t f (size_t *i) { return *i + 1; }
1467 unsigned short i = 0;
1472 name : 'GCC size_t typedef is short'),
1473 'int': g_sizet_compatibility['int'] and cc.compiles(
1474 '''#include <stddef.h>
1475 size_t f (size_t *i) { return *i + 1; }
1482 name : 'GCC size_t typedef is int'),
1483 'long': g_sizet_compatibility['long'] and cc.compiles(
1484 '''#include <stddef.h>
1485 size_t f (size_t *i) { return *i + 1; }
1487 unsigned long i = 0;
1492 name : 'GCC size_t typedef is long'),
1493 'long long': g_sizet_compatibility['long long'] and cc.compiles(
1494 '''#include <stddef.h>
1495 size_t f (size_t *i) { return *i + 1; }
1497 unsigned long long i = 0;
1502 name : 'GCC size_t typedef is long long'),
1506 if g_sizet_compatibility['short']
1507 glibconfig_conf.set('glib_size_type_define', 'short')
1508 glibconfig_conf.set_quoted('gsize_modifier', 'h')
1509 glibconfig_conf.set_quoted('gssize_modifier', 'h')
1510 glibconfig_conf.set_quoted('gsize_format', 'hu')
1511 glibconfig_conf.set_quoted('gssize_format', 'hi')
1512 glibconfig_conf.set('glib_msize_type', 'SHRT')
1513 elif g_sizet_compatibility['int']
1514 glibconfig_conf.set('glib_size_type_define', 'int')
1515 glibconfig_conf.set_quoted('gsize_modifier', '')
1516 glibconfig_conf.set_quoted('gssize_modifier', '')
1517 glibconfig_conf.set_quoted('gsize_format', 'u')
1518 glibconfig_conf.set_quoted('gssize_format', 'i')
1519 glibconfig_conf.set('glib_msize_type', 'INT')
1520 elif g_sizet_compatibility['long']
1521 glibconfig_conf.set('glib_size_type_define', 'long')
1522 glibconfig_conf.set_quoted('gsize_modifier', 'l')
1523 glibconfig_conf.set_quoted('gssize_modifier', 'l')
1524 glibconfig_conf.set_quoted('gsize_format', 'lu')
1525 glibconfig_conf.set_quoted('gssize_format', 'li')
1526 glibconfig_conf.set('glib_msize_type', 'LONG')
1527 elif g_sizet_compatibility['long long']
1528 glibconfig_conf.set('glib_size_type_define', 'long long')
1529 glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1530 glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1531 glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1532 glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1533 glibconfig_conf.set('glib_msize_type', 'INT64')
1535 error('Could not determine size of size_t.')
1538 if voidp_size == int_size
1539 glibconfig_conf.set('glib_intptr_type_define', 'int')
1540 glibconfig_conf.set_quoted('gintptr_modifier', '')
1541 glibconfig_conf.set_quoted('gintptr_format', 'i')
1542 glibconfig_conf.set_quoted('guintptr_format', 'u')
1543 glibconfig_conf.set('glib_gpi_cast', '(gint)')
1544 glibconfig_conf.set('glib_gpui_cast', '(guint)')
1545 elif voidp_size == long_size
1546 glibconfig_conf.set('glib_intptr_type_define', 'long')
1547 glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1548 glibconfig_conf.set_quoted('gintptr_format', 'li')
1549 glibconfig_conf.set_quoted('guintptr_format', 'lu')
1550 glibconfig_conf.set('glib_gpi_cast', '(glong)')
1551 glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1552 elif voidp_size == long_long_size
1553 glibconfig_conf.set('glib_intptr_type_define', 'long long')
1554 glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1555 glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1556 glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1557 glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1558 glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1560 error('Could not determine size of void *')
1563 if long_size != 8 and long_long_size != 8 and int_size != 8
1564 error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1567 glibconfig_conf.set('gintbits', int_size * 8)
1568 glibconfig_conf.set('glongbits', long_size * 8)
1569 glibconfig_conf.set('gsizebits', sizet_size * 8)
1570 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1572 # XXX: https://gitlab.gnome.org/GNOME/glib/issues/1413
1573 if host_system == 'windows'
1574 g_module_suffix = 'dll'
1576 g_module_suffix = 'so'
1578 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1580 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1581 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1582 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1583 glibconfig_conf.set('GLIB_VERSION', glib_version)
1585 glibconfig_conf.set('glib_void_p', voidp_size)
1586 glibconfig_conf.set('glib_long', long_size)
1587 glibconfig_conf.set('glib_size_t', sizet_size)
1588 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1589 if host_machine.endian() == 'big'
1590 glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1591 glibconfig_conf.set('g_bs_native', 'BE')
1592 glibconfig_conf.set('g_bs_alien', 'LE')
1594 glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1595 glibconfig_conf.set('g_bs_native', 'LE')
1596 glibconfig_conf.set('g_bs_alien', 'BE')
1599 # === va_copy checks ===
1600 # we currently check for all three va_copy possibilities, so we get
1601 # all results in config.log for bug reports.
1604 foreach try_func : [ '__va_copy', 'va_copy' ]
1605 if cc.compiles('''#include <stdarg.h>
1608 # include "msvc_recommended_pragmas.h"
1610 void f (int i, ...) {
1611 va_list args1, args2;
1612 va_start (args1, i);
1614 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1616 va_end (args1); va_end (args2);
1621 }'''.format(try_func),
1622 name : try_func + ' check')
1623 va_copy_func = try_func
1626 if va_copy_func != ''
1627 glib_conf.set('G_VA_COPY', va_copy_func)
1628 glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1630 glib_vacopy = '/* #undef G_VA_COPY */'
1633 va_list_val_copy_prog = '''
1636 void f (int i, ...) {
1637 va_list args1, args2;
1638 va_start (args1, i);
1640 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1642 va_end (args1); va_end (args2);
1650 rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1651 glib_va_val_copy = rres.returncode() == 0
1653 glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
1655 if not glib_va_val_copy
1656 glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1657 glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1659 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1661 # check for flavours of varargs macros
1662 g_have_iso_c_varargs = cc.compiles('''
1663 void some_func (void) {
1664 int a(int p1, int p2, int p3);
1665 #define call_a(...) a(1,__VA_ARGS__)
1667 }''', name : 'ISO C99 varargs macros in C')
1669 if g_have_iso_c_varargs
1670 glibconfig_conf.set('g_have_iso_c_varargs', '''
1672 # define G_HAVE_ISO_VARARGS 1
1676 g_have_iso_cxx_varargs = cxx.compiles('''
1677 void some_func (void) {
1678 int a(int p1, int p2, int p3);
1679 #define call_a(...) a(1,__VA_ARGS__)
1681 }''', name : 'ISO C99 varargs macros in C++')
1683 if g_have_iso_cxx_varargs
1684 glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1686 # define G_HAVE_ISO_VARARGS 1
1690 g_have_gnuc_varargs = cc.compiles('''
1691 void some_func (void) {
1692 int a(int p1, int p2, int p3);
1693 #define call_a(params...) a(1,params)
1695 }''', name : 'GNUC varargs macros')
1697 if cc.has_header('alloca.h')
1698 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1700 has_syspoll = cc.has_header('sys/poll.h')
1701 has_systypes = cc.has_header('sys/types.h')
1703 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1705 has_winsock2 = cc.has_header('winsock2.h')
1707 if has_syspoll and has_systypes
1709 #include<sys/poll.h>
1710 #include<sys/types.h>'''
1713 #define _WIN32_WINNT @0@
1714 #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1717 error('FIX POLL* defines')
1721 [ 'POLLIN', 'g_pollin', 1 ],
1722 [ 'POLLOUT', 'g_pollout', 4 ],
1723 [ 'POLLPRI', 'g_pollpri', 2 ],
1724 [ 'POLLERR', 'g_pollerr', 8 ],
1725 [ 'POLLHUP', 'g_pollhup', 16 ],
1726 [ 'POLLNVAL', 'g_pollnval', 32 ],
1729 if has_syspoll and has_systypes
1730 foreach d : poll_defines
1731 val = cc.compute_int(d[0], prefix: poll_includes)
1732 glibconfig_conf.set(d[1], val)
1735 # Due to a missed bug in configure.ac the poll test
1736 # never succeeded on Windows and used some pre-defined
1737 # values as a fallback. Keep using them to maintain
1738 # ABI compatibility with autotools builds of glibs
1739 # and with *any* glib-using code compiled against them,
1740 # since these values end up in a public header glibconfig.h.
1741 foreach d : poll_defines
1742 glibconfig_conf.set(d[1], d[2])
1746 # Internet address families
1747 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1748 if host_system == 'windows'
1750 #include <winsock2.h>'''
1753 #include <sys/types.h>
1754 #include <sys/socket.h>'''
1758 [ 'AF_UNIX', 'g_af_unix' ],
1759 [ 'AF_INET', 'g_af_inet' ],
1760 [ 'AF_INET6', 'g_af_inet6' ],
1761 [ 'MSG_OOB', 'g_msg_oob' ],
1762 [ 'MSG_PEEK', 'g_msg_peek' ],
1763 [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1765 foreach d : inet_defines
1766 val = cc.compute_int(d[0], prefix: inet_includes)
1767 glibconfig_conf.set(d[1], val)
1770 if host_system == 'windows'
1773 have_ipv6 = cc.has_type('struct in6_addr', prefix: '#include <netinet/in.h>')
1775 glib_conf.set('HAVE_IPV6', have_ipv6)
1777 # We need to decide at configure time if GLib will use real atomic
1778 # operations ("lock free") or emulated ones with a mutex. This is
1779 # because we must put this information in glibconfig.h so we know if
1780 # it is safe or not to inline using compiler intrinsics directly from
1783 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1784 # user is interested in knowing if they can use the atomic ops across
1787 # We can currently support the atomic ops natively when building GLib
1788 # with recent versions of GCC or MSVC.
1790 # Note that the atomic ops are only available with GCC on x86 when
1791 # using -march=i486 or higher. If we detect that the atomic ops are
1792 # not available but would be available given the right flags, we want
1793 # to abort and advise the user to fix their CFLAGS. It's better to do
1794 # that then to silently fall back on emulated atomic ops just because
1795 # the user had the wrong build environment.
1796 atomictest = '''int main() {
1798 __sync_bool_compare_and_swap (&atomic, 2, 3);
1804 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1805 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1809 # We know that we can always use real ("lock free") atomic operations with MSVC
1810 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' or cc.links(atomictest, name : 'atomic ops')
1811 have_atomic_lock_free = true
1812 if cc.get_id() == 'gcc' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1813 # Old gcc release may provide
1814 # __sync_bool_compare_and_swap but doesn't define
1815 # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1816 glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1819 have_atomic_lock_free = false
1820 if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1821 error('GLib must be built with -march=i486 or later.')
1824 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1828 # Determination of thread implementation
1829 if host_system == 'windows' and not get_option('force_posix_threads')
1831 threads_implementation = 'win32'
1832 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1833 glib_conf.set('THREADS_WIN32', 1)
1835 thread_dep = dependency('threads')
1836 threads_implementation = 'posix'
1837 pthread_prefix = '''
1839 # define _GNU_SOURCE
1841 #include <pthread.h>'''
1842 glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1843 glib_conf.set('THREADS_POSIX', 1)
1844 if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1845 glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1847 if cc.has_header_symbol('pthread.h', 'pthread_attr_setinheritsched')
1848 glib_conf.set('HAVE_PTHREAD_ATTR_SETINHERITSCHED', 1)
1850 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1851 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1853 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1854 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1856 if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1857 glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1860 if cc.has_header_symbol('sys/syscall.h', 'SYS_sched_getattr')
1861 glib_conf.set('HAVE_SYS_SCHED_GETATTR', 1)
1864 # Assume that pthread_setname_np is available in some form; same as configure
1865 if cc.links(pthread_prefix + '''
1867 pthread_setname_np("example");
1870 name : 'pthread_setname_np(const char*)',
1871 dependencies : thread_dep)
1873 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1874 elif cc.links(pthread_prefix + '''
1876 pthread_setname_np(pthread_self(), "example");
1879 name : 'pthread_setname_np(pthread_t, const char*)',
1880 dependencies : thread_dep)
1881 # Linux, Solaris, etc.
1882 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1883 elif cc.links(pthread_prefix + '''
1885 pthread_setname_np(pthread_self(), "%s", "example");
1888 name : 'pthread_setname_np(pthread_t, const char*, void*)',
1889 dependencies : thread_dep)
1891 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG', 1)
1892 elif cc.links(pthread_prefix + '''
1893 #include <pthread_np.h>
1895 pthread_set_name_np(pthread_self(), "example");
1898 name : 'pthread_set_name_np(pthread_t, const char*)',
1899 dependencies : thread_dep)
1900 # FreeBSD, DragonFlyBSD, OpenBSD, etc.
1901 glib_conf.set('HAVE_PTHREAD_SET_NAME_NP', 1)
1905 # FIXME: we should make it print the result and always return 0, so that
1906 # the output in meson shows up as green
1907 # volatile is needed here to avoid optimisations in the test
1908 stack_grows_check_prog = '''
1909 volatile int *a = 0, *b = 0;
1921 return b > a ? 0 : 1;
1925 rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
1926 growing_stack = rres.returncode() == 0
1928 growing_stack = meson.get_cross_property('growing_stack', false)
1931 glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack)
1935 # We should never use the MinGW C library's iconv because it may not be
1936 # available in the actual runtime environment. On Windows, we always use
1937 # the built-in implementation
1938 iconv_opt = get_option('iconv')
1939 if host_system == 'windows'
1941 # We have a #include "win_iconv.c" in gconvert.c on Windows, so we don't need
1942 # any external library for it
1943 if iconv_opt != 'auto'
1944 warning('-Diconv was set to @0@, which was ignored')
1948 if ['auto', 'libc'].contains(iconv_opt) and cc.has_function('iconv_open')
1952 if not found_iconv and ['auto', 'external'].contains(iconv_opt) and cc.has_header_symbol('iconv.h', 'iconv_open')
1953 libiconv = [cc.find_library('iconv')]
1958 error('iconv implementation "@0@" not found'.format(iconv_opt))
1962 if get_option('internal_pcre')
1964 use_system_pcre = false
1966 pcre = dependency('libpcre', version: '>= 8.31', required : false) # Should check for Unicode support, too. FIXME
1968 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1969 # MSVC: Search for the PCRE library by the configuration, which corresponds
1970 # to the output of CMake builds of PCRE. Note that debugoptimized
1971 # is really a Release build with .PDB files.
1972 if vs_crt == 'debug'
1973 pcre = cc.find_library('pcred', required : false)
1975 pcre = cc.find_library('pcre', required : false)
1979 use_system_pcre = pcre.found()
1981 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1983 use_pcre_static_flag = false
1985 if host_system == 'windows'
1986 if not use_system_pcre
1987 use_pcre_static_flag = true
1989 pcre_static = cc.links('''#define PCRE_STATIC
1997 name : 'Windows system PCRE is a static build')
1999 use_pcre_static_flag = true
2004 libm = cc.find_library('m', required : false)
2005 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
2007 # Don't use the bundled ZLib sources until we are sure that we can't find it on
2009 libz_dep = dependency('zlib', required : false)
2010 if not libz_dep.found()
2011 if cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
2012 libz_dep = cc.find_library('z', required : false)
2014 libz_dep = cc.find_library('zlib1', required : false)
2015 if not libz_dep.found()
2016 libz_dep = cc.find_library('zlib', required : false)
2019 if not libz_dep.found() or not cc.has_header('zlib.h')
2020 libz_dep = subproject('zlib').get_variable('zlib_dep')
2024 # First check in libc, fallback to libintl, and as last chance build
2025 # proxy-libintl subproject.
2026 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
2027 # implementations. This could be extended if issues are found in some platforms.
2029 if cc.has_function('ngettext')
2030 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset')
2032 # First just find the bare library.
2033 libintl = cc.find_library('intl', required : false)
2034 # The bare library probably won't link without help if it's static.
2035 if libintl.found() and not cc.has_function('ngettext', dependencies : libintl)
2036 libintl_iconv = cc.find_library('iconv', required : false)
2037 # libintl supports different threading APIs, which may not
2038 # require additional flags, but it defaults to using pthreads if
2039 # found. Meson's "threads" dependency does not allow you to
2040 # prefer pthreads. We may not be using pthreads for glib itself
2041 # either so just link the library to satisfy libintl rather than
2042 # also defining the macros with the -pthread flag.
2043 libintl_pthread = cc.find_library('pthread', required : false)
2044 # Try linking with just libiconv.
2045 if libintl_iconv.found() and cc.has_function('ngettext', dependencies : [libintl, libintl_iconv])
2046 libintl_deps += [libintl_iconv]
2047 # Then also try linking with pthreads.
2048 elif libintl_iconv.found() and libintl_pthread.found() and cc.has_function('ngettext', dependencies : [libintl, libintl_iconv, libintl_pthread])
2049 libintl_deps += [libintl_iconv, libintl_pthread]
2051 libintl = disabler()
2054 if not libintl.found()
2055 libintl = subproject('proxy-libintl').get_variable('intl_dep')
2056 libintl_deps = [libintl] + libintl_deps
2057 have_bind_textdomain_codeset = true # proxy-libintl supports it
2059 libintl_deps = [libintl] + libintl_deps
2060 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset',
2061 dependencies : libintl_deps)
2065 glib_conf.set('HAVE_BIND_TEXTDOMAIN_CODESET', have_bind_textdomain_codeset)
2067 # We require gettext to always be present
2068 glib_conf.set('HAVE_DCGETTEXT', 1)
2069 glib_conf.set('HAVE_GETTEXT', 1)
2071 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
2073 # libmount is only used by gio, but we need to fetch the libs to generate the
2074 # pkg-config file below
2076 if host_system == 'linux'
2077 libmount_dep = dependency('mount', version : '>=2.23', required : get_option('libmount'))
2078 glib_conf.set('HAVE_LIBMOUNT', libmount_dep.found())
2081 if host_system == 'windows'
2082 winsock2 = cc.find_library('ws2_32')
2086 if host_system == 'linux'
2087 selinux_dep = dependency('libselinux', version: '>=2.2', required: get_option('selinux'))
2089 glib_conf.set('HAVE_SELINUX', selinux_dep.found())
2093 if host_system != 'windows' and get_option('xattr')
2094 # either glibc or libattr can provide xattr support
2095 # for both of them, we check for getxattr being in
2096 # the library and a valid xattr header.
2099 if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
2100 glib_conf.set('HAVE_SYS_XATTR_H', 1)
2101 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
2102 #failure. try libattr
2103 elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
2104 glib_conf.set('HAVE_ATTR_XATTR_H', 1)
2105 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
2106 xattr_dep = [cc.find_library('xattr')]
2108 error('No getxattr implementation found in C library or libxattr')
2111 glib_conf.set('HAVE_XATTR', 1)
2112 if cc.compiles(glib_conf_prefix + '''
2114 #ifdef HAVE_SYS_TYPES_H
2115 #include <sys/types.h>
2117 #ifdef HAVE_SYS_XATTR_H
2118 #include <sys/xattr.h>
2119 #elif HAVE_ATTR_XATTR_H
2120 #include <attr/xattr.h>
2124 ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
2127 name : 'XATTR_NOFOLLOW')
2128 glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
2132 # If strlcpy is present (BSD and similar), check that it conforms to the BSD
2133 # specification. Specifically Solaris 8's strlcpy() does not, see
2134 # https://bugzilla.gnome.org/show_bug.cgi?id=53933 for further context.
2135 if cc.has_function('strlcpy')
2137 rres = cc.run('''#include <stdlib.h>
2141 (void) strlcpy (p, "hi", 10);
2142 if (strlcat (p, "bye", 0) != 3)
2146 name : 'OpenBSD strlcpy/strlcat')
2147 if rres.compiled() and rres.returncode() == 0
2148 glib_conf.set('HAVE_STRLCPY', 1)
2150 elif meson.get_cross_property('have_strlcpy', false)
2151 glib_conf.set('HAVE_STRLCPY', 1)
2155 cmdline_test_code = '''
2157 #include <sys/stat.h>
2164 /* This code is a dumbed-down version of g_file_get_contents() */
2168 #define BUFSIZE 1024
2169 char result[BUFSIZE];
2170 struct stat stat_buf;
2172 int fd = open ("/proc/self/cmdline", O_RDONLY|O_BINARY);
2175 if (fstat (fd, &stat_buf))
2178 if (stat_buf.st_size > 0 && S_ISREG (stat_buf.st_mode))
2180 if (read (fd, result, BUFSIZE) <= 0)
2185 FILE *f = fdopen (fd, "r");
2189 if (fread (result, 1, BUFSIZE, f) <= 0)
2199 exit (__getcmdline ());
2203 rres = cc.run(cmdline_test_code, name : '/proc/self/cmdline')
2204 have_proc_self_cmdline = rres.compiled() and rres.returncode() == 0
2206 have_proc_self_cmdline = meson.get_cross_property('have_proc_self_cmdline', false)
2209 glib_conf.set('HAVE_PROC_SELF_CMDLINE', have_proc_self_cmdline)
2211 python = import('python').find_installation('python3')
2212 # used for '#!/usr/bin/env <name>'
2213 python_name = 'python3'
2215 python_version = python.language_version()
2216 python_version_req = '>=3.5'
2217 if not python_version.version_compare(python_version_req)
2218 error('Requires Python @0@, @1@ found.'.format(python_version_req, python_version))
2221 # Determine which user environment-dependent files that we want to install
2222 have_bash = find_program('bash', required : false).found() # For completion scripts
2223 bash_comp_dep = dependency('bash-completion', version: '>=2.0', required: false)
2224 have_sh = find_program('sh', required : false).found() # For glib-gettextize
2226 # Some installed tests require a custom environment
2227 env_program = find_program('env', required: installed_tests_enabled)
2229 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
2230 if host_system == 'sunos'
2231 glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
2232 glib_conf.set('_XOPEN_SOURCE', 2)
2233 glib_conf.set('__EXTENSIONS__',1)
2236 # Sadly Meson does not expose this value:
2237 # https://github.com/mesonbuild/meson/pull/3460
2238 if host_system == 'windows'
2239 # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
2240 # with no explanation. Do the same here for now but this could be revisited if
2242 export_dynamic_ldflags = []
2243 elif host_system == 'cygwin'
2244 export_dynamic_ldflags = ['-Wl,--export-all-symbols']
2245 elif host_system in ['darwin', 'ios']
2246 export_dynamic_ldflags = []
2247 elif host_system == 'sunos'
2248 export_dynamic_ldflags = []
2250 export_dynamic_ldflags = ['-Wl,--export-dynamic']
2255 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
2256 # Ensure MSVC-compatible struct packing convention is used when
2257 # compiling for Win32 with gcc. It is used for the whole project and exposed
2259 win32_cflags = ['-mms-bitfields']
2260 add_project_arguments(win32_cflags, language : 'c')
2262 # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
2263 win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi']
2264 elif host_system == 'cygwin'
2265 win32_ldflags = ['-luser32', '-lkernel32']
2269 want_dtrace = get_option('dtrace')
2270 enable_dtrace = false
2272 # Since dtrace support is opt-in we just error out if it was requested but
2273 # is not available. We don't bother with autodetection yet.
2276 error('GLib dtrace support not yet compatible with macOS dtrace')
2278 dtrace = find_program('dtrace', required : true) # error out if not found
2279 if not cc.has_header('sys/sdt.h')
2280 error('dtrace support needs sys/sdt.h header')
2282 # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
2283 dtrace_obj_gen = generator(dtrace,
2284 output : '@BASENAME@.o',
2285 arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2286 # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
2287 # -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
2288 dtrace_hdr_gen = generator(dtrace,
2289 output : '@BASENAME@.h',
2290 arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2291 glib_conf.set('HAVE_DTRACE', 1)
2292 enable_dtrace = true
2296 want_systemtap = get_option('systemtap')
2297 enable_systemtap = false
2299 if want_systemtap and enable_dtrace
2300 tapset_install_dir = get_option('tapset_install_dir')
2301 if tapset_install_dir == ''
2302 tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
2304 stp_cdata = configuration_data()
2305 stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
2306 stp_cdata.set('LT_CURRENT', minor_version * 100)
2307 stp_cdata.set('LT_REVISION', micro_version)
2308 enable_systemtap = true
2312 test_timeout_slow = 180
2314 pkg = import('pkgconfig')
2315 windows = import('windows')
2326 # xgettext is optional (on Windows for instance)
2327 if find_program('xgettext', required : get_option('nls')).found()
2331 # Install glib-gettextize executable, if a UNIX-style shell is found
2333 # These should not contain " quotes around the values
2334 gettextize_conf = configuration_data()
2335 gettextize_conf.set('PACKAGE', 'glib')
2336 gettextize_conf.set('VERSION', meson.project_version())
2337 gettextize_conf.set('prefix', glib_prefix)
2338 gettextize_conf.set('datarootdir', glib_datadir)
2339 gettextize_conf.set('datadir', glib_datadir)
2340 configure_file(input : 'glib-gettextize.in',
2341 install_dir : glib_bindir,
2342 output : 'glib-gettextize',
2343 configuration : gettextize_conf)
2346 # Install m4 macros that other projects use
2347 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
2348 install_dir : join_paths(get_option('datadir'), 'aclocal'))
2350 if host_system != 'windows'
2351 # Install Valgrind suppression file (except on Windows,
2352 # as Valgrind is currently not supported on Windows)
2353 install_data('glib.supp',
2354 install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
2357 configure_file(output : 'config.h', configuration : glib_conf)
2359 if host_system == 'windows'
2360 install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
2363 if get_option('man')
2364 xsltproc = find_program('xsltproc', required : true)
2365 xsltproc_command = [
2368 '--stringparam', 'man.output.quietly', '1',
2369 '--stringparam', 'funcsynopsis.style', 'ansi',
2370 '--stringparam', 'man.th.extra1.suppress', '1',
2371 '--stringparam', 'man.authors.section.enabled', '0',
2372 '--stringparam', 'man.copyright.section.enabled', '0',
2374 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
2377 man1_dir = join_paths(glib_prefix, get_option('mandir'), 'man1')
2380 gnome = import('gnome')
2381 subdir('docs/reference')