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_argument_syntax() == 'msvc'
18 # Ignore several spurious warnings for things glib does very commonly
20 add_project_arguments('/FImsvc_recommended_pragmas.h',language : 'c')
23 if cc.get_id() == 'msvc'
24 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
25 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
26 # NOTE: Only add warnings here if you are sure they're spurious
27 add_project_arguments('/wd4035', '/wd4715', '/wd4116',
28 '/wd4046', '/wd4068', '/wo4090',language : 'c')
29 # Set the input and exec encoding to utf-8, like is the default with GCC
30 add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c')
31 # Disable SAFESEH with MSVC for plugins and libs that use external deps that
32 # are built with MinGW
33 noseh_link_args = ['/SAFESEH:NO']
36 # -mms-bitfields vs -fnative-struct ?
39 host_system = host_machine.system()
41 if host_system == 'darwin'
42 ios_test_code = '''#include <TargetConditionals.h>
43 #if ! TARGET_OS_IPHONE
44 #error "Not iOS/tvOS/watchOS/iPhoneSimulator"
46 if cc.compiles(ios_test_code, name : 'building for iOS')
51 glib_version = meson.project_version()
52 glib_api_version = '2.0'
53 version_arr = glib_version.split('.')
54 major_version = version_arr[0].to_int()
55 minor_version = version_arr[1].to_int()
56 micro_version = version_arr[2].to_int()
58 interface_age = minor_version.is_odd() ? 0 : micro_version
59 binary_age = 100 * minor_version + micro_version
62 # Maintain compatibility with previous libtool versioning
63 # current = minor * 100 + micro
64 current = binary_age - interface_age
65 library_version = '@0@.@1@.@2@'.format(soversion, current, interface_age)
66 darwin_versions = [current + 1, '@0@.@1@'.format(current + 1, interface_age)]
68 configinc = include_directories('.')
69 glibinc = include_directories('glib')
70 gobjectinc = include_directories('gobject')
71 gmoduleinc = include_directories('gmodule')
72 gioinc = include_directories('gio')
74 glib_prefix = get_option('prefix')
75 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
76 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
77 glib_libexecdir = join_paths(glib_prefix, get_option('libexecdir'))
78 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
79 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
80 glib_includedir = join_paths(glib_prefix, get_option('includedir'))
81 if get_option('gio_module_dir') != ''
82 glib_giomodulesdir = join_paths(glib_prefix, get_option('gio_module_dir'))
84 glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
87 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
89 if get_option('charsetalias_dir') != ''
90 glib_charsetaliasdir = join_paths(glib_prefix, get_option('charsetalias_dir'))
92 glib_charsetaliasdir = glib_libdir
95 glib_localstatedir = get_option('localstatedir')
96 if not glib_localstatedir.startswith('/')
97 # See https://mesonbuild.com/Builtin-options.html#directories
98 glib_localstatedir = join_paths(glib_prefix, glib_localstatedir)
101 installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
102 installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
103 installed_tests_enabled = get_option('installed_tests')
104 installed_tests_template = files('template.test.in')
105 installed_tests_template_tap = files('template-tap.test.in')
107 # Don’t build the tests unless we can run them (either natively, in an exe wrapper, or by installing them for later use)
108 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)
110 add_project_arguments('-D_GNU_SOURCE', language: 'c')
112 if host_system == 'qnx'
113 add_project_arguments('-D_QNX_SOURCE', language: 'c')
116 # Disable strict aliasing;
117 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
118 if cc.has_argument('-fno-strict-aliasing')
119 add_project_arguments('-fno-strict-aliasing', language: 'c')
122 ########################
123 # Configuration begins #
124 ########################
125 glib_conf = configuration_data()
126 glibconfig_conf = configuration_data()
128 # accumulated list of defines as we check for them, so we can easily
129 # use them later in test programs (autoconf does this automatically)
130 glib_conf_prefix = ''
132 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
133 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
134 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
135 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
136 glib_conf.set('GLIB_BINARY_AGE', binary_age)
137 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
138 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
139 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
140 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
141 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
142 glib_conf.set_quoted('PACKAGE_URL', '')
143 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
144 glib_conf.set('ENABLE_NLS', 1)
146 # used by the .rc.in files
147 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
149 glib_conf.set('_GNU_SOURCE', 1)
151 if host_system == 'windows'
152 # Poll doesn't work on devices on Windows
153 glib_conf.set('BROKEN_POLL', true)
156 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
157 # FIXME: Ideally we shouldn't depend on this on Windows and should use
158 # 64 bit capable Windows API that also works with MSVC.
159 # The autotools build did set this for mingw and while meson sets it
160 # for gcc/clang by default, it doesn't do so on Windows.
161 glib_conf.set('_FILE_OFFSET_BITS', 64)
164 # Check for GNU visibility attributes
165 g_have_gnuc_visibility = cc.compiles('''
167 __attribute__ ((visibility ("hidden")))
172 __attribute__ ((visibility ("internal")))
177 __attribute__ ((visibility ("default")))
189 # Not supported by MSVC, but MSVC also won't support visibility,
190 # so it's OK to pass -Werror explicitly. Replace with
191 # override_options : 'werror=true' once that is supported
193 name : 'GNU C visibility attributes test')
195 if g_have_gnuc_visibility
196 glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
199 # Detect and set symbol visibility
200 glib_hidden_visibility_args = []
201 if get_option('default_library') != 'static'
202 if host_system == 'windows' or host_system == 'cygwin'
203 glib_conf.set('DLL_EXPORT', true)
204 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
205 glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
206 elif cc.has_argument('-fvisibility=hidden')
207 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
208 glib_hidden_visibility_args = ['-fvisibility=hidden']
210 elif cc.has_argument('-fvisibility=hidden')
211 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
212 glib_hidden_visibility_args = ['-fvisibility=hidden']
216 if get_option('default_library') == 'static'
217 glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
218 glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
221 # Cygwin glib port maintainers made it clear
222 # (via the patches they apply) that they want no
223 # part of glib W32 code, therefore we do not define
224 # G_PLATFORM_WIN32 for host_system == 'cygwin'.
225 # This makes G_PLATFORM_WIN32 a synonym for
227 if host_system == 'windows'
228 glib_os = '''#define G_OS_WIN32
229 #define G_PLATFORM_WIN32'''
230 elif host_system == 'cygwin'
231 glib_os = '''#define G_OS_UNIX
232 #define G_WITH_CYGWIN'''
234 glib_os = '#define G_OS_UNIX'
236 glibconfig_conf.set('glib_os', glib_os)
238 # We need to know the CRT being used to determine what .lib files we need on
239 # Visual Studio for dependencies that don't normally come with pkg-config files
241 vs_crt_opt = get_option('b_vscrt')
242 if vs_crt_opt in ['mdd', 'mtd']
244 elif vs_crt_opt == 'from_buildtype'
245 if get_option('buildtype') == 'debug'
250 # Use debug/optimization flags to determine whether to enable debug or disable
252 glib_debug_cflags = []
253 glib_debug = get_option('glib_debug')
254 if glib_debug.enabled() or (glib_debug.auto() and get_option('debug'))
255 glib_debug_cflags += ['-DG_ENABLE_DEBUG']
256 message('Enabling various debug infrastructure')
257 elif get_option('optimization') in ['2', '3', 's']
258 glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
259 message('Disabling cast checks')
262 if not get_option('glib_assert')
263 glib_debug_cflags += ['-DG_DISABLE_ASSERT']
264 message('Disabling GLib asserts')
267 if not get_option('glib_checks')
268 glib_debug_cflags += ['-DG_DISABLE_CHECKS']
269 message('Disabling GLib checks')
272 add_project_arguments(glib_debug_cflags, language: 'c')
274 # check for header files
279 'dirent.h', # MSC does not come with this by default
314 'sys/time.h', # MSC does not come with this by default
331 define = 'HAVE_' + h.underscorify().to_upper()
332 glib_conf.set(define, 1)
333 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
337 # FIXME: Use cc.check_header from Meson 0.47.
338 # FreeBSD includes a malloc.h which always throw compilation error.
339 if cc.compiles('#include <malloc.h>', name : 'malloc.h')
340 glib_conf.set('HAVE_MALLOC_H', 1)
341 glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
344 if cc.has_header('linux/netlink.h')
345 glib_conf.set('HAVE_NETLINK', 1)
348 # Is statx() supported? Android systems don’t reliably support it as of August 2020.
353 #include <sys/stat.h>
357 struct statx stat_buf;
358 return statx (AT_FDCWD, "/", AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS | STATX_BTIME, &stat_buf);
361 if host_system != 'android' and cc.compiles(statx_code, name : 'statx() test')
362 glib_conf.set('HAVE_STATX', 1)
365 if glib_conf.has('HAVE_LOCALE_H')
366 if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
367 glib_conf.set('HAVE_LC_MESSAGES', 1)
371 struct_stat_blkprefix = '''
372 #include <sys/types.h>
373 #include <sys/stat.h>
377 #ifdef HAVE_SYS_STATFS_H
378 #include <sys/statfs.h>
380 #ifdef HAVE_SYS_PARAM_H
381 #include <sys/param.h>
383 #ifdef HAVE_SYS_MOUNT_H
384 #include <sys/mount.h>
389 [ 'stat', 'st_mtimensec' ],
390 [ 'stat', 'st_mtim.tv_nsec' ],
391 [ 'stat', 'st_atimensec' ],
392 [ 'stat', 'st_atim.tv_nsec' ],
393 [ 'stat', 'st_ctimensec' ],
394 [ 'stat', 'st_ctim.tv_nsec' ],
395 [ 'stat', 'st_birthtime' ],
396 [ 'stat', 'st_birthtimensec' ],
397 [ 'stat', 'st_birthtim' ],
398 [ 'stat', 'st_birthtim.tv_nsec' ],
399 [ 'stat', 'st_blksize', struct_stat_blkprefix ],
400 [ 'stat', 'st_blocks', struct_stat_blkprefix ],
401 [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
402 [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
403 [ 'dirent', 'd_type', '''#include <sys/types.h>
404 #include <dirent.h>''' ],
405 [ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
406 [ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
407 [ 'tm', 'tm_gmtoff', '#include <time.h>' ],
408 [ 'tm', '__tm_gmtoff', '#include <time.h>' ],
411 foreach m : struct_members
412 header_check_prefix = glib_conf_prefix
414 header_check_prefix = header_check_prefix + m[2]
416 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
418 if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
419 define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
420 glib_conf.set(define, 1)
421 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
427 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
429 '-Wduplicated-branches',
430 '-Wimplicit-fallthrough',
431 '-Wmisleading-indentation',
432 '-Wstrict-prototypes',
434 # Due to maintained deprecated code, we do not want to see unused parameters
435 '-Wno-unused-parameter',
436 # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
437 # building with -Wbad-function-cast.
438 '-Wno-bad-function-cast',
439 '-Wno-cast-function-type',
440 # Due to function casts through (void*) we cannot support -Wpedantic:
441 # https://wiki.gnome.org/Projects/GLib/CompilerRequirements#Function_pointer_conversions.
443 # A zero-length format string shouldn't be considered an issue.
444 '-Wno-format-zero-length',
445 '-Werror=declaration-after-statement',
447 '-Werror=implicit-function-declaration',
449 '-Werror=missing-include-dirs',
450 '-Werror=missing-prototypes',
451 '-Werror=pointer-arith',
453 warning_c_link_args = [
456 if get_option('bsymbolic_functions')
457 warning_c_link_args += ['-Wl,-Bsymbolic-functions']
461 warning_c_link_args = []
464 add_project_arguments(cc.get_supported_arguments(warning_c_args), language: 'c')
466 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
467 # means we cannot use that flag in add_project_link_arguments(), and must add
468 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
469 # because that is what the autotools build did.
470 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
472 glib_link_flags = cc.get_supported_link_arguments(warning_c_link_args)
474 # Windows SDK requirements and checks
475 if host_system == 'windows'
476 # Check whether we're building for UWP apps
479 #if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
480 #error "Not building for UWP"
482 if cc.compiles(code, name : 'building for UWP')
483 glib_conf.set('G_WINAPI_ONLY_APP', true)
484 # We require Windows 10+ on WinRT
485 glib_conf.set('_WIN32_WINNT', '0x0A00')
486 uwp_gio_deps = [cc.find_library('shcore'),
487 cc.find_library('runtimeobject')]
489 # We require Windows 7+ on Win32
490 glib_conf.set('_WIN32_WINNT', '0x0601')
556 # _NSGetEnviron is available on iOS too, but its usage gets apps rejected from
557 # the app store since it's considered 'private API'
558 if host_system == 'darwin'
559 functions += ['_NSGetEnviron']
562 if glib_conf.has('HAVE_SYS_STATVFS_H')
563 functions += ['statvfs']
565 have_func_statvfs = false
567 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
568 functions += ['statfs']
570 have_func_statfs = false
573 if host_system == 'windows'
574 iphlpapi_dep = cc.find_library('iphlpapi')
575 iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
576 foreach ifunc : iphlpapi_funcs
577 iphl_prefix = '''#define _WIN32_WINNT @0@
578 #include <winsock2.h>
579 #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
580 if cc.has_function(ifunc,
581 prefix : iphl_prefix,
582 dependencies : iphlpapi_dep)
583 idefine = 'HAVE_' + ifunc.underscorify().to_upper()
584 glib_conf.set(idefine, 1)
585 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
586 set_variable('have_func_' + ifunc, true)
588 set_variable('have_func_' + ifunc, false)
592 functions += ['if_indextoname', 'if_nametoindex']
595 # AIX splice is something else
596 if host_system != 'aix'
597 functions += ['splice']
600 foreach f : functions
601 if cc.has_function(f)
602 define = 'HAVE_' + f.underscorify().to_upper()
603 glib_conf.set(define, 1)
604 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
605 set_variable('have_func_' + f, true)
607 set_variable('have_func_' + f, false)
611 # Check that stpcpy() is usable; must use header.
612 # cc.has_function() in some cases (clang, gcc 10+) assumes that if the
613 # compiler provides a builtin of the same name that the function exists, while
614 # it's in fact not provided by any header or library. This is true for
615 # stpcpy() on Windows using clang and gcc as well as posix_memalign() using
616 # gcc on Windows. Skip these checks on Windows for now to avoid false
617 # positives. See https://github.com/mesonbuild/meson/pull/7116,
618 # https://github.com/mesonbuild/meson/issues/3672 and
619 # https://github.com/mesonbuild/meson/issues/5628.
620 # FIXME: Once meson no longer returns success for stpcpy() and
621 # posix_memalign() on Windows using GCC and clang we can remove this.
622 if host_system != 'windows' and cc.has_function('stpcpy', prefix : '#include <string.h>')
623 glib_conf.set('HAVE_STPCPY', 1)
626 # When building for Android-20 and earlier, require Meson 0.54.2 or newer.
627 # This is needed, because Meson build versions prior to 0.54.2 return false
628 # positive for stpcpy has_function check when building for legacy Android.
629 if host_system == 'android'
630 android_is_older = cc.compiles('''#if __ANDROID_API__ >= 21
631 #error Android is 21 or newer
633 if android_is_older and meson.version().version_compare('< 0.54.2')
634 error('Compiling for <Android-21 requires Meson 0.54.2 or newer')
639 # Check that posix_memalign() is usable; must use header
640 if host_system != 'windows' and cc.has_function('posix_memalign', prefix : '#include <stdlib.h>')
641 glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
644 # Check that posix_spawn() is usable; must use header
645 if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
646 glib_conf.set('HAVE_POSIX_SPAWN', 1)
649 # Check whether strerror_r returns char *
650 if have_func_strerror_r
651 if cc.compiles('''#define _GNU_SOURCE
654 char error_string[256];
655 char *ptr = strerror_r (-2, error_string, 256);
656 char c = *strerror_r (-2, error_string, 256);
657 return c != 0 && ptr != (void*) 0L;
660 name : 'strerror_r() returns char *')
661 glib_conf.set('STRERROR_R_CHAR_P', 1,
662 description: 'Defined if strerror_r returns char *')
666 # Special-case these functions that have alternative names on Windows/MSVC
667 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
668 glib_conf.set('HAVE_SNPRINTF', 1)
669 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
670 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
671 hack_define = '1\n#define snprintf _snprintf'
672 glib_conf.set('HAVE_SNPRINTF', hack_define)
673 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
676 if cc.has_function('strcasecmp', prefix: '#include <strings.h>')
677 glib_conf.set('HAVE_STRCASECMP', 1)
678 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
679 elif cc.has_function('_stricmp')
680 hack_define = '1\n#define strcasecmp _stricmp'
681 glib_conf.set('HAVE_STRCASECMP', hack_define)
682 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
685 if cc.has_function('strncasecmp', prefix: '#include <strings.h>')
686 glib_conf.set('HAVE_STRNCASECMP', 1)
687 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
688 elif cc.has_function('_strnicmp')
689 hack_define = '1\n#define strncasecmp _strnicmp'
690 glib_conf.set('HAVE_STRNCASECMP', hack_define)
691 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
694 if cc.has_header_symbol('sys/sysmacros.h', 'major')
695 glib_conf.set('MAJOR_IN_SYSMACROS', 1)
696 elif cc.has_header_symbol('sys/mkdev.h', 'major')
697 glib_conf.set('MAJOR_IN_MKDEV', 1)
698 elif cc.has_header_symbol('sys/types.h', 'major')
699 glib_conf.set('MAJOR_IN_TYPES', 1)
702 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
703 glib_conf.set('HAVE_RTLD_LAZY', 1)
706 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
707 glib_conf.set('HAVE_RTLD_NOW', 1)
710 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
711 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
714 have_rtld_next = false
715 if cc.has_header_symbol('dlfcn.h', 'RTLD_NEXT', args: '-D_GNU_SOURCE')
716 have_rtld_next = true
717 glib_conf.set('HAVE_RTLD_NEXT', 1)
720 # Check whether to use statfs or statvfs
721 # Some systems have both statfs and statvfs, pick the most "native" for these
722 if have_func_statfs and have_func_statvfs
723 # on solaris and irix, statfs doesn't even have the f_bavail field
724 if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
725 have_func_statfs = false
727 # at least on linux, statfs is the actual syscall
728 have_func_statvfs = false
732 glib_conf.set('USE_STATFS', 1)
733 stat_func_to_use = 'statfs'
734 elif have_func_statvfs
735 glib_conf.set('USE_STATVFS', 1)
736 stat_func_to_use = 'statvfs'
738 stat_func_to_use = 'neither'
740 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
742 if host_system == 'linux'
743 if cc.has_function('mkostemp',
744 prefix: '''#define _GNU_SOURCE
745 #include <stdlib.h>''')
746 glib_conf.set('HAVE_MKOSTEMP', 1)
751 glib_have_os_x_9_or_later = false
752 glib_have_carbon = false
753 glib_have_cocoa = false
754 if host_system == 'darwin'
755 add_languages('objc')
756 objcc = meson.get_compiler('objc')
758 osx_ldflags += ['-Wl,-framework,CoreFoundation']
760 # Mac OS X Carbon support
761 glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
762 #include <CoreServices/CoreServices.h>''',
763 name : 'Mac OS X Carbon support')
766 glib_conf.set('HAVE_CARBON', true)
767 osx_ldflags += '-Wl,-framework,Carbon'
768 glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
769 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
770 #error Compiling for minimum OS X version before 10.9
772 name : 'OS X 9 or later')
775 # Mac OS X Cocoa support
776 glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
777 #ifdef GNUSTEP_BASE_VERSION
778 #error "Detected GNUstep, not Cocoa"
780 name : 'Mac OS X Cocoa support')
783 glib_conf.set('HAVE_COCOA', true)
784 osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
787 # FIXME: libgio mix C and objC source files and there is no way to reliably
788 # know which language flags it's going to use to link. Add to both languages
789 # for now. See https://github.com/mesonbuild/meson/issues/3585.
790 add_project_link_arguments(osx_ldflags, language : ['objc', 'c'])
793 if host_system == 'qnx'
794 glib_conf.set('HAVE_QNX', 1)
798 if cc.links('''#include <linux/futex.h>
799 #include <sys/syscall.h>
801 int main (int argc, char ** argv) {
802 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
804 }''', name : 'futex(2) system call')
805 glib_conf.set('HAVE_FUTEX', 1)
808 # Check for eventfd(2)
809 if cc.links('''#include <sys/eventfd.h>
811 int main (int argc, char ** argv) {
812 eventfd (0, EFD_CLOEXEC);
814 }''', name : 'eventfd(2) system call')
815 glib_conf.set('HAVE_EVENTFD', 1)
818 # Check for __uint128_t (gcc) by checking for 128-bit division
819 uint128_t_src = '''int main() {
820 static __uint128_t v1 = 100;
821 static __uint128_t v2 = 10;
822 static __uint128_t u;
825 if cc.compiles(uint128_t_src, name : '__uint128_t available')
826 glib_conf.set('HAVE_UINT128_T', 1)
829 clock_gettime_test_code = '''
832 int main (int argc, char ** argv) {
833 return clock_gettime(CLOCK_REALTIME, &t);
836 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
837 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
838 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
839 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
840 librt = cc.find_library('rt')
843 dlopen_dlsym_test_code = '''
845 int glib_underscore_test (void) { return 42; }
846 int main (int argc, char ** argv) {
847 void *f1 = (void*)0, *f2 = (void*)0, *handle;
848 handle = dlopen ((void*)0, 0);
850 f1 = dlsym (handle, "glib_underscore_test");
851 f2 = dlsym (handle, "_glib_underscore_test");
856 if cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
857 have_dlopen_dlsym = true
858 elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
859 have_dlopen_dlsym = true
860 libdl_dep = cc.find_library('dl')
862 have_dlopen_dlsym = false
865 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
867 if cc.compiles(glib_conf_prefix + '''
869 #ifdef HAVE_SYS_PARAM_H
870 #include <sys/param.h>
872 #ifdef HAVE_SYS_VFS_H
875 #ifdef HAVE_SYS_MOUNT_H
876 #include <sys/mount.h>
878 #ifdef HAVE_SYS_STATFS_H
879 #include <sys/statfs.h>
881 void some_func (void) {
884 }''', name : 'number of arguments to statfs() (n=2)')
885 glib_conf.set('STATFS_ARGS', 2)
886 elif cc.compiles(glib_conf_prefix + '''
888 #ifdef HAVE_SYS_PARAM_H
889 #include <sys/param.h>
891 #ifdef HAVE_SYS_VFS_H
894 #ifdef HAVE_SYS_MOUNT_H
895 #include <sys/mount.h>
897 #ifdef HAVE_SYS_STATFS_H
898 #include <sys/statfs.h>
900 void some_func (void) {
902 statfs("/", &st, sizeof (st), 0);
903 }''', name : 'number of arguments to statfs() (n=4)')
904 glib_conf.set('STATFS_ARGS', 4)
906 error('Unable to determine number of arguments to statfs()')
910 # open takes O_DIRECTORY as an option
912 if cc.compiles('''#include <fcntl.h>
913 #include <sys/types.h>
914 #include <sys/stat.h>
915 void some_func (void) {
916 open(0, O_DIRECTORY, 0);
917 }''', name : 'open() option O_DIRECTORY')
918 glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
921 # fcntl takes F_FULLFSYNC as an option
922 # See https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html
923 if cc.compiles('''#include <fcntl.h>
924 #include <sys/types.h>
925 #include <sys/stat.h>
926 void some_func (void) {
927 fcntl(0, F_FULLFSYNC, 0);
928 }''', name : 'fcntl() option F_FULLFSYNC')
929 glib_conf.set('HAVE_FCNTL_F_FULLFSYNC', 1)
932 # Check whether there is a vsnprintf() function with C99 semantics installed.
933 # (similar tests to AC_FUNC_VSNPRINTF_C99)
934 # Check whether there is a snprintf() function with C99 semantics installed.
935 # (similar tests to AC_FUNC_SNPRINTF_C99)
936 # Check whether there is a printf() function with Unix98 semantics installed.
937 # (similar tests to AC_FUNC_PRINTF_UNIX98)
938 have_good_vsnprintf = false
939 have_good_snprintf = false
940 have_good_printf = false
942 if host_system == 'windows' and (cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl')
943 # Unfortunately the Visual Studio 2015+ implementations of C99-style
944 # snprintf and vsnprintf don't seem to be quite good enough.
945 # (Sorry, I don't know exactly what is the problem,
946 # but it is related to floating point formatting and decimal point vs. comma.)
947 # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
948 # rigorous enough to notice, though.
949 glib_conf.set('HAVE_C99_SNPRINTF', false)
950 glib_conf.set('HAVE_C99_VSNPRINTF', false)
951 glib_conf.set('HAVE_UNIX98_PRINTF', false)
952 elif not cc_can_run and host_system in ['ios', 'darwin']
953 # All these are true when compiling natively on macOS, so we should use good
954 # defaults when building for iOS and tvOS.
955 glib_conf.set('HAVE_C99_SNPRINTF', true)
956 glib_conf.set('HAVE_C99_VSNPRINTF', true)
957 glib_conf.set('HAVE_UNIX98_PRINTF', true)
958 have_good_vsnprintf = true
959 have_good_snprintf = true
960 have_good_printf = true
962 vsnprintf_c99_test_code = '''
975 r = vsnprintf(buffer, 5, s, args);
981 /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
982 implementation. The above will return 7 but if you replace
983 the size of the buffer with 0, it borks! */
985 r = vsnprintf(buffer, 0, s, args);
1002 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
1003 if rres.compiled() and rres.returncode() == 0
1004 glib_conf.set('HAVE_C99_VSNPRINTF', 1)
1005 have_good_vsnprintf = true
1008 have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
1009 glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
1012 snprintf_c99_test_code = '''
1024 r = snprintf(buffer, 5, "1234567");
1029 r = snprintf(buffer, 0, "1234567");
1034 r = snprintf(NULL, 0, "1234567");
1050 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
1051 if rres.compiled() and rres.returncode() == 0
1052 glib_conf.set('HAVE_C99_SNPRINTF', 1)
1053 have_good_snprintf = true
1056 have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
1057 glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
1060 printf_unix98_test_code = '''
1070 sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
1071 if (strcmp ("2 3 1", buffer) == 0)
1077 rres = cc.run(printf_unix98_test_code, name : 'Unix98 printf positional parameters')
1078 if rres.compiled() and rres.returncode() == 0
1079 glib_conf.set('HAVE_UNIX98_PRINTF', 1)
1080 have_good_printf = true
1083 have_good_printf = meson.get_cross_property('have_unix98_printf', false)
1084 glib_conf.set('HAVE_UNIX98_PRINTF', have_good_printf)
1088 if host_system == 'windows'
1089 glib_conf.set_quoted('EXEEXT', '.exe')
1091 glib_conf.set('EXEEXT', '')
1094 # Our printf is 'good' only if vsnpintf()/snprintf()/printf() supports C99 well enough
1095 use_system_printf = have_good_vsnprintf and have_good_snprintf and have_good_printf
1096 glib_conf.set('USE_SYSTEM_PRINTF', use_system_printf)
1097 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', use_system_printf)
1099 if not use_system_printf
1100 # gnulib has vasprintf so override the previous check
1101 glib_conf.set('HAVE_VASPRINTF', 1)
1104 # Check for nl_langinfo and CODESET
1105 if cc.links('''#include <langinfo.h>
1106 int main (int argc, char ** argv) {
1107 char *codeset = nl_langinfo (CODESET);
1109 }''', name : 'nl_langinfo and CODESET')
1110 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
1111 glib_conf.set('HAVE_CODESET', 1)
1114 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
1115 if cc.links('''#include <langinfo.h>
1116 int main (int argc, char ** argv) {
1118 str = nl_langinfo (PM_STR);
1119 str = nl_langinfo (D_T_FMT);
1120 str = nl_langinfo (D_FMT);
1121 str = nl_langinfo (T_FMT);
1122 str = nl_langinfo (T_FMT_AMPM);
1123 str = nl_langinfo (MON_1);
1124 str = nl_langinfo (ABMON_12);
1125 str = nl_langinfo (DAY_1);
1126 str = nl_langinfo (ABDAY_7);
1128 }''', name : 'nl_langinfo (PM_STR)')
1129 glib_conf.set('HAVE_LANGINFO_TIME', 1)
1131 if cc.links('''#include <langinfo.h>
1132 int main (int argc, char ** argv) {
1134 str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
1135 str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
1136 str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
1137 str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
1138 str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
1139 str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
1140 str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
1141 str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
1142 str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
1143 str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
1145 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
1146 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
1149 # Check for nl_langinfo and alternative month names
1150 if cc.links('''#ifndef _GNU_SOURCE
1151 # define _GNU_SOURCE
1153 #include <langinfo.h>
1154 int main (int argc, char ** argv) {
1156 str = nl_langinfo (ALTMON_1);
1157 str = nl_langinfo (ALTMON_2);
1158 str = nl_langinfo (ALTMON_3);
1159 str = nl_langinfo (ALTMON_4);
1160 str = nl_langinfo (ALTMON_5);
1161 str = nl_langinfo (ALTMON_6);
1162 str = nl_langinfo (ALTMON_7);
1163 str = nl_langinfo (ALTMON_8);
1164 str = nl_langinfo (ALTMON_9);
1165 str = nl_langinfo (ALTMON_10);
1166 str = nl_langinfo (ALTMON_11);
1167 str = nl_langinfo (ALTMON_12);
1169 }''', name : 'nl_langinfo (ALTMON_n)')
1170 glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
1173 # Check for nl_langinfo and abbreviated alternative month names
1174 if cc.links('''#ifndef _GNU_SOURCE
1175 # define _GNU_SOURCE
1177 #include <langinfo.h>
1178 int main (int argc, char ** argv) {
1180 str = nl_langinfo (_NL_ABALTMON_1);
1181 str = nl_langinfo (_NL_ABALTMON_2);
1182 str = nl_langinfo (_NL_ABALTMON_3);
1183 str = nl_langinfo (_NL_ABALTMON_4);
1184 str = nl_langinfo (_NL_ABALTMON_5);
1185 str = nl_langinfo (_NL_ABALTMON_6);
1186 str = nl_langinfo (_NL_ABALTMON_7);
1187 str = nl_langinfo (_NL_ABALTMON_8);
1188 str = nl_langinfo (_NL_ABALTMON_9);
1189 str = nl_langinfo (_NL_ABALTMON_10);
1190 str = nl_langinfo (_NL_ABALTMON_11);
1191 str = nl_langinfo (_NL_ABALTMON_12);
1193 }''', name : 'nl_langinfo (_NL_ABALTMON_n)')
1194 glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
1197 # Check for nl_langinfo and _NL_TIME_CODESET
1198 if cc.links('''#include <langinfo.h>
1199 int main (int argc, char ** argv) {
1200 char *codeset = nl_langinfo (_NL_TIME_CODESET);
1202 }''', name : 'nl_langinfo and _NL_TIME_CODESET')
1203 glib_conf.set('HAVE_LANGINFO_TIME_CODESET', 1)
1206 # Check if C compiler supports the 'signed' keyword
1207 if not cc.compiles('''signed char x;''', name : 'signed')
1208 glib_conf.set('signed', '/* NOOP */')
1211 # Check if the ptrdiff_t type exists
1212 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
1213 glib_conf.set('HAVE_PTRDIFF_T', 1)
1216 # Check for sig_atomic_t type
1217 if cc.links('''#include <signal.h>
1218 #include <sys/types.h>
1219 sig_atomic_t val = 42;
1220 int main (int argc, char ** argv) {
1221 return val == 42 ? 0 : 1;
1222 }''', name : 'sig_atomic_t')
1223 glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
1226 # Check if 'long long' works
1227 # jm_AC_TYPE_LONG_LONG
1228 if cc.compiles('''long long ll = 1LL;
1230 int some_func (void) {
1231 long long llmax = (long long) -1;
1232 return ll << i | ll >> i | llmax / ll | llmax % ll;
1233 }''', name : 'long long')
1234 glib_conf.set('HAVE_LONG_LONG', 1)
1235 have_long_long = true
1237 have_long_long = false
1240 # Test whether the compiler supports the 'long double' type.
1241 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
1242 long double foo = 0.0;
1243 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
1244 int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
1245 name : 'long double')
1246 glib_conf.set('HAVE_LONG_DOUBLE', 1)
1249 # Test whether <stddef.h> has the 'wchar_t' type.
1250 if cc.has_header_symbol('stddef.h', 'wchar_t')
1251 glib_conf.set('HAVE_WCHAR_T', 1)
1254 # Test whether <wchar.h> has the 'wint_t' type.
1255 if cc.has_header_symbol('wchar.h', 'wint_t')
1256 glib_conf.set('HAVE_WINT_T', 1)
1259 found_uintmax_t = false
1261 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
1262 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1263 # jm_AC_HEADER_INTTYPES_H
1264 if cc.compiles('''#include <sys/types.h>
1265 #include <inttypes.h>
1266 void some_func (void) {
1267 uintmax_t i = (uintmax_t) -1;
1268 }''', name : 'uintmax_t in inttypes.h')
1269 glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1270 found_uintmax_t = true
1273 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1274 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1275 # jm_AC_HEADER_STDINT_H
1276 if cc.compiles('''#include <sys/types.h>
1278 void some_func (void) {
1279 uintmax_t i = (uintmax_t) -1;
1280 }''', name : 'uintmax_t in stdint.h')
1281 glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1282 found_uintmax_t = true
1285 # Define intmax_t to 'long' or 'long long'
1286 # if it is not already defined in <stdint.h> or <inttypes.h>.
1287 # For simplicity, we assume that a header file defines 'intmax_t' if and
1288 # only if it defines 'uintmax_t'.
1290 glib_conf.set('HAVE_INTMAX_T', 1)
1292 glib_conf.set('intmax_t', 'long long')
1294 glib_conf.set('intmax_t', 'long')
1297 char_size = cc.sizeof('char')
1298 short_size = cc.sizeof('short')
1299 int_size = cc.sizeof('int')
1300 voidp_size = cc.sizeof('void*')
1301 long_size = cc.sizeof('long')
1303 long_long_size = cc.sizeof('long long')
1307 sizet_size = cc.sizeof('size_t')
1308 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1309 ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1311 ssizet_size = cc.sizeof('ssize_t', prefix : '#include <unistd.h>')
1314 # Some platforms (Apple) hard-code int64_t to long long instead of
1315 # using long on 64-bit architectures. This can cause type mismatch
1316 # warnings when trying to interface with code using the standard
1317 # library type. Test for the warnings and set gint64 to whichever
1319 if long_long_size == long_size
1320 if cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1321 #pragma options langlvl=stdc99
1323 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1330 }''', name : 'int64_t is long')
1331 int64_t_typedef = 'long'
1332 elif cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1333 #pragma options langlvl=stdc99
1335 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1340 long long *i2 = &i1;
1342 }''', name : 'int64_t is long long')
1343 int64_t_typedef = 'long long'
1348 char_align = cc.alignment('char')
1349 short_align = cc.alignment('short')
1350 int_align = cc.alignment('int')
1351 voidp_align = cc.alignment('void*')
1352 long_align = cc.alignment('long')
1353 long_long_align = cc.alignment('long long')
1354 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1355 # be 64-bit in C99, and it is available on all supported compilers
1356 sizet_align = cc.alignment('size_t')
1358 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1360 glib_conf.set('SIZEOF_CHAR', char_size)
1361 glib_conf.set('SIZEOF_INT', int_size)
1362 glib_conf.set('SIZEOF_SHORT', short_size)
1363 glib_conf.set('SIZEOF_LONG', long_size)
1364 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1365 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1366 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1367 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1368 glib_conf.set('SIZEOF_WCHAR_T', cc.sizeof('wchar_t', prefix: '#include <stddef.h>'))
1381 error('Compiler provides no native 16-bit integer type')
1383 glibconfig_conf.set('gint16', gint16)
1384 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1385 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1386 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1393 guint32_align = short_align
1399 guint32_align = int_align
1405 guint32_align = long_align
1407 error('Compiler provides no native 32-bit integer type')
1409 glibconfig_conf.set('gint32', gint32)
1410 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1411 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1412 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1413 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1421 gint64_constant='(val)'
1422 guint64_constant='(val)'
1423 guint64_align = int_align
1424 elif long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long')
1430 gint64_constant='(val##L)'
1431 guint64_constant='(val##UL)'
1432 guint64_align = long_align
1433 elif long_long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long long')
1434 gint64 = 'long long'
1435 glib_extension='G_GNUC_EXTENSION '
1436 gint64_modifier=int64_m
1437 gint64_format=int64_m + 'i'
1438 guint64_format=int64_m + 'u'
1439 gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1440 guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1441 guint64_align = long_long_align
1443 error('Compiler provides no native 64-bit integer type')
1445 glibconfig_conf.set('glib_extension', glib_extension)
1446 glibconfig_conf.set('gint64', gint64)
1447 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1448 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1449 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1450 glibconfig_conf.set('gint64_constant', gint64_constant)
1451 glibconfig_conf.set('guint64_constant', guint64_constant)
1452 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1454 if host_system == 'windows'
1455 glibconfig_conf.set('g_pid_type', 'void*')
1456 glibconfig_conf.set_quoted('g_pid_format', 'p')
1457 if host_machine.cpu_family() == 'x86_64'
1458 glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1460 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1462 glibconfig_conf.set('g_dir_separator', '\\\\')
1463 glibconfig_conf.set('g_searchpath_separator', ';')
1465 glibconfig_conf.set('g_pid_type', 'int')
1466 glibconfig_conf.set_quoted('g_pid_format', 'i')
1467 glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1468 glibconfig_conf.set('g_dir_separator', '/')
1469 glibconfig_conf.set('g_searchpath_separator', ':')
1472 g_sizet_compatibility = {
1473 'short': sizet_size == short_size,
1474 'int': sizet_size == int_size,
1475 'long': sizet_size == long_size,
1476 'long long': sizet_size == long_long_size,
1479 # Do separate checks for gcc/clang (and ignore other compilers for now), since
1480 # we need to explicitly pass -Werror to the compilers.
1481 # FIXME: https://github.com/mesonbuild/meson/issues/5399
1482 # We can’t simplify these checks using a foreach loop because dictionary keys
1483 # have to be string literals.
1484 # FIXME: https://github.com/mesonbuild/meson/issues/5231
1485 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
1486 g_sizet_compatibility += {
1487 'short': g_sizet_compatibility['short'] and cc.compiles(
1488 '''#include <stddef.h>
1489 size_t f (size_t *i) { return *i + 1; }
1491 unsigned short i = 0;
1496 name : 'GCC size_t typedef is short'),
1497 'int': g_sizet_compatibility['int'] and cc.compiles(
1498 '''#include <stddef.h>
1499 size_t f (size_t *i) { return *i + 1; }
1506 name : 'GCC size_t typedef is int'),
1507 'long': g_sizet_compatibility['long'] and cc.compiles(
1508 '''#include <stddef.h>
1509 size_t f (size_t *i) { return *i + 1; }
1511 unsigned long i = 0;
1516 name : 'GCC size_t typedef is long'),
1517 'long long': g_sizet_compatibility['long long'] and cc.compiles(
1518 '''#include <stddef.h>
1519 size_t f (size_t *i) { return *i + 1; }
1521 unsigned long long i = 0;
1526 name : 'GCC size_t typedef is long long'),
1530 if g_sizet_compatibility['short']
1531 glibconfig_conf.set('glib_size_type_define', 'short')
1532 glibconfig_conf.set_quoted('gsize_modifier', 'h')
1533 glibconfig_conf.set_quoted('gssize_modifier', 'h')
1534 glibconfig_conf.set_quoted('gsize_format', 'hu')
1535 glibconfig_conf.set_quoted('gssize_format', 'hi')
1536 glibconfig_conf.set('glib_msize_type', 'SHRT')
1537 elif g_sizet_compatibility['int']
1538 glibconfig_conf.set('glib_size_type_define', 'int')
1539 glibconfig_conf.set_quoted('gsize_modifier', '')
1540 glibconfig_conf.set_quoted('gssize_modifier', '')
1541 glibconfig_conf.set_quoted('gsize_format', 'u')
1542 glibconfig_conf.set_quoted('gssize_format', 'i')
1543 glibconfig_conf.set('glib_msize_type', 'INT')
1544 elif g_sizet_compatibility['long']
1545 glibconfig_conf.set('glib_size_type_define', 'long')
1546 glibconfig_conf.set_quoted('gsize_modifier', 'l')
1547 glibconfig_conf.set_quoted('gssize_modifier', 'l')
1548 glibconfig_conf.set_quoted('gsize_format', 'lu')
1549 glibconfig_conf.set_quoted('gssize_format', 'li')
1550 glibconfig_conf.set('glib_msize_type', 'LONG')
1551 elif g_sizet_compatibility['long long']
1552 glibconfig_conf.set('glib_size_type_define', 'long long')
1553 glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1554 glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1555 glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1556 glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1557 glibconfig_conf.set('glib_msize_type', 'INT64')
1559 error('Could not determine size of size_t.')
1562 if voidp_size == int_size
1563 glibconfig_conf.set('glib_intptr_type_define', 'int')
1564 glibconfig_conf.set_quoted('gintptr_modifier', '')
1565 glibconfig_conf.set_quoted('gintptr_format', 'i')
1566 glibconfig_conf.set_quoted('guintptr_format', 'u')
1567 glibconfig_conf.set('glib_gpi_cast', '(gint)')
1568 glibconfig_conf.set('glib_gpui_cast', '(guint)')
1569 elif voidp_size == long_size
1570 glibconfig_conf.set('glib_intptr_type_define', 'long')
1571 glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1572 glibconfig_conf.set_quoted('gintptr_format', 'li')
1573 glibconfig_conf.set_quoted('guintptr_format', 'lu')
1574 glibconfig_conf.set('glib_gpi_cast', '(glong)')
1575 glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1576 elif voidp_size == long_long_size
1577 glibconfig_conf.set('glib_intptr_type_define', 'long long')
1578 glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1579 glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1580 glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1581 glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1582 glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1584 error('Could not determine size of void *')
1587 if long_size != 8 and long_long_size != 8 and int_size != 8
1588 error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1591 glibconfig_conf.set('gintbits', int_size * 8)
1592 glibconfig_conf.set('glongbits', long_size * 8)
1593 glibconfig_conf.set('gsizebits', sizet_size * 8)
1594 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1596 # XXX: https://gitlab.gnome.org/GNOME/glib/issues/1413
1597 if host_system == 'windows'
1598 g_module_suffix = 'dll'
1600 g_module_suffix = 'so'
1602 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1604 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1605 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1606 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1607 glibconfig_conf.set('GLIB_VERSION', glib_version)
1609 glibconfig_conf.set('glib_void_p', voidp_size)
1610 glibconfig_conf.set('glib_long', long_size)
1611 glibconfig_conf.set('glib_size_t', sizet_size)
1612 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1613 if host_machine.endian() == 'big'
1614 glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1615 glibconfig_conf.set('g_bs_native', 'BE')
1616 glibconfig_conf.set('g_bs_alien', 'LE')
1618 glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1619 glibconfig_conf.set('g_bs_native', 'LE')
1620 glibconfig_conf.set('g_bs_alien', 'BE')
1623 # === va_copy checks ===
1624 # we currently check for all three va_copy possibilities, so we get
1625 # all results in config.log for bug reports.
1628 foreach try_func : [ '__va_copy', 'va_copy' ]
1629 if cc.compiles('''#include <stdarg.h>
1632 # include "msvc_recommended_pragmas.h"
1634 void f (int i, ...) {
1635 va_list args1, args2;
1636 va_start (args1, i);
1638 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1640 va_end (args1); va_end (args2);
1645 }'''.format(try_func),
1646 name : try_func + ' check')
1647 va_copy_func = try_func
1650 if va_copy_func != ''
1651 glib_conf.set('G_VA_COPY', va_copy_func)
1652 glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1654 glib_vacopy = '/* #undef G_VA_COPY */'
1657 va_list_val_copy_prog = '''
1660 void f (int i, ...) {
1661 va_list args1, args2;
1662 va_start (args1, i);
1664 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1666 va_end (args1); va_end (args2);
1674 rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1675 glib_va_val_copy = rres.returncode() == 0
1677 glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
1679 if not glib_va_val_copy
1680 glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1681 glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1683 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1685 # check for flavours of varargs macros
1686 g_have_iso_c_varargs = cc.compiles('''
1687 void some_func (void) {
1688 int a(int p1, int p2, int p3);
1689 #define call_a(...) a(1,__VA_ARGS__)
1691 }''', name : 'ISO C99 varargs macros in C')
1693 if g_have_iso_c_varargs
1694 glibconfig_conf.set('g_have_iso_c_varargs', '''
1696 # define G_HAVE_ISO_VARARGS 1
1700 g_have_iso_cxx_varargs = cxx.compiles('''
1701 void some_func (void) {
1702 int a(int p1, int p2, int p3);
1703 #define call_a(...) a(1,__VA_ARGS__)
1705 }''', name : 'ISO C99 varargs macros in C++')
1707 if g_have_iso_cxx_varargs
1708 glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1710 # define G_HAVE_ISO_VARARGS 1
1714 g_have_gnuc_varargs = cc.compiles('''
1715 void some_func (void) {
1716 int a(int p1, int p2, int p3);
1717 #define call_a(params...) a(1,params)
1719 }''', name : 'GNUC varargs macros')
1721 if cc.has_header('alloca.h')
1722 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1724 has_syspoll = cc.has_header('sys/poll.h')
1725 has_systypes = cc.has_header('sys/types.h')
1727 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1729 has_winsock2 = cc.has_header('winsock2.h')
1731 if has_syspoll and has_systypes
1733 #include<sys/poll.h>
1734 #include<sys/types.h>'''
1737 #define _WIN32_WINNT @0@
1738 #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1741 error('FIX POLL* defines')
1745 [ 'POLLIN', 'g_pollin', 1 ],
1746 [ 'POLLOUT', 'g_pollout', 4 ],
1747 [ 'POLLPRI', 'g_pollpri', 2 ],
1748 [ 'POLLERR', 'g_pollerr', 8 ],
1749 [ 'POLLHUP', 'g_pollhup', 16 ],
1750 [ 'POLLNVAL', 'g_pollnval', 32 ],
1753 if has_syspoll and has_systypes
1754 foreach d : poll_defines
1755 val = cc.compute_int(d[0], prefix: poll_includes)
1756 glibconfig_conf.set(d[1], val)
1759 # Due to a missed bug in configure.ac the poll test
1760 # never succeeded on Windows and used some pre-defined
1761 # values as a fallback. Keep using them to maintain
1762 # ABI compatibility with autotools builds of glibs
1763 # and with *any* glib-using code compiled against them,
1764 # since these values end up in a public header glibconfig.h.
1765 foreach d : poll_defines
1766 glibconfig_conf.set(d[1], d[2])
1770 # Internet address families
1771 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1772 if host_system == 'windows'
1774 #include <winsock2.h>'''
1777 #include <sys/types.h>
1778 #include <sys/socket.h>'''
1782 [ 'AF_UNIX', 'g_af_unix' ],
1783 [ 'AF_INET', 'g_af_inet' ],
1784 [ 'AF_INET6', 'g_af_inet6' ],
1785 [ 'MSG_OOB', 'g_msg_oob' ],
1786 [ 'MSG_PEEK', 'g_msg_peek' ],
1787 [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1789 foreach d : inet_defines
1790 val = cc.compute_int(d[0], prefix: inet_includes)
1791 glibconfig_conf.set(d[1], val)
1794 if host_system == 'windows'
1797 have_ipv6 = cc.has_type('struct in6_addr', prefix: '#include <netinet/in.h>')
1799 glib_conf.set('HAVE_IPV6', have_ipv6)
1801 # We need to decide at configure time if GLib will use real atomic
1802 # operations ("lock free") or emulated ones with a mutex. This is
1803 # because we must put this information in glibconfig.h so we know if
1804 # it is safe or not to inline using compiler intrinsics directly from
1807 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1808 # user is interested in knowing if they can use the atomic ops across
1811 # We can currently support the atomic ops natively when building GLib
1812 # with recent versions of GCC or MSVC.
1814 # Note that the atomic ops are only available with GCC on x86 when
1815 # using -march=i486 or higher. If we detect that the atomic ops are
1816 # not available but would be available given the right flags, we want
1817 # to abort and advise the user to fix their CFLAGS. It's better to do
1818 # that then to silently fall back on emulated atomic ops just because
1819 # the user had the wrong build environment.
1820 atomictest = '''int main() {
1822 __sync_bool_compare_and_swap (&atomic, 2, 3);
1828 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1829 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1833 # We know that we can always use real ("lock free") atomic operations with MSVC
1834 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' or cc.links(atomictest, name : 'atomic ops')
1835 have_atomic_lock_free = true
1836 if cc.get_id() == 'gcc' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1837 # Old gcc release may provide
1838 # __sync_bool_compare_and_swap but doesn't define
1839 # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1840 glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1843 have_atomic_lock_free = false
1844 if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1845 error('GLib must be built with -march=i486 or later.')
1848 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1852 # Determination of thread implementation
1853 if host_system == 'windows' and not get_option('force_posix_threads')
1855 threads_implementation = 'win32'
1856 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1857 glib_conf.set('THREADS_WIN32', 1)
1859 thread_dep = dependency('threads')
1860 threads_implementation = 'posix'
1861 pthread_prefix = '''
1863 # define _GNU_SOURCE
1865 #include <pthread.h>'''
1866 glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1867 glib_conf.set('THREADS_POSIX', 1)
1868 if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1869 glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1871 if cc.has_header_symbol('pthread.h', 'pthread_attr_setinheritsched')
1872 glib_conf.set('HAVE_PTHREAD_ATTR_SETINHERITSCHED', 1)
1874 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1875 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1877 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1878 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1880 if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1881 glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1884 if cc.has_header_symbol('sys/syscall.h', 'SYS_sched_getattr')
1885 glib_conf.set('HAVE_SYS_SCHED_GETATTR', 1)
1888 # Assume that pthread_setname_np is available in some form; same as configure
1889 if cc.links(pthread_prefix + '''
1891 pthread_setname_np("example");
1894 name : 'pthread_setname_np(const char*)',
1895 dependencies : thread_dep)
1897 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1898 elif cc.links(pthread_prefix + '''
1900 pthread_setname_np(pthread_self(), "example");
1903 name : 'pthread_setname_np(pthread_t, const char*)',
1904 dependencies : thread_dep)
1905 # Linux, Solaris, etc.
1906 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1907 elif cc.links(pthread_prefix + '''
1909 pthread_setname_np(pthread_self(), "%s", "example");
1912 name : 'pthread_setname_np(pthread_t, const char*, void*)',
1913 dependencies : thread_dep)
1915 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG', 1)
1916 elif cc.links(pthread_prefix + '''
1917 #include <pthread_np.h>
1919 pthread_set_name_np(pthread_self(), "example");
1922 name : 'pthread_set_name_np(pthread_t, const char*)',
1923 dependencies : thread_dep)
1924 # FreeBSD, DragonFlyBSD, OpenBSD, etc.
1925 glib_conf.set('HAVE_PTHREAD_SET_NAME_NP', 1)
1929 # FIXME: we should make it print the result and always return 0, so that
1930 # the output in meson shows up as green
1931 # volatile is needed here to avoid optimisations in the test
1932 stack_grows_check_prog = '''
1933 volatile int *a = 0, *b = 0;
1945 return b > a ? 0 : 1;
1949 rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
1950 growing_stack = rres.returncode() == 0
1952 growing_stack = meson.get_cross_property('growing_stack', false)
1955 glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack)
1959 # We should never use the MinGW C library's iconv because it may not be
1960 # available in the actual runtime environment. On Windows, we always use
1961 # the built-in implementation
1962 iconv_opt = get_option('iconv')
1963 if host_system == 'windows'
1965 # We have a #include "win_iconv.c" in gconvert.c on Windows, so we don't need
1966 # any external library for it
1967 if iconv_opt != 'auto'
1968 warning('-Diconv was set to @0@, which was ignored')
1972 if ['auto', 'libc'].contains(iconv_opt) and cc.has_function('iconv_open')
1976 if not found_iconv and ['auto', 'external'].contains(iconv_opt) and cc.has_header_symbol('iconv.h', 'iconv_open')
1977 libiconv = [cc.find_library('iconv')]
1982 error('iconv implementation "@0@" not found'.format(iconv_opt))
1986 pcre = dependency('libpcre', version: '>= 8.31', required : false) # Should check for Unicode support, too. FIXME
1988 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1989 # MSVC: Search for the PCRE library by the configuration, which corresponds
1990 # to the output of CMake builds of PCRE. Note that debugoptimized
1991 # is really a Release build with .PDB files.
1992 if vs_crt == 'debug'
1993 pcre = cc.find_library('pcred', required : false)
1995 pcre = cc.find_library('pcre', required : false)
2000 # Try again with the fallback
2002 pcre = dependency('libpcre', required : true, fallback : ['libpcre', 'pcre_dep'])
2003 use_pcre_static_flag = true
2004 elif host_system == 'windows'
2005 pcre_static = cc.links('''#define PCRE_STATIC
2013 name : 'Windows system PCRE is a static build')
2014 use_pcre_static_flag = pcre_static
2016 use_pcre_static_flag = false
2019 libm = cc.find_library('m', required : false)
2020 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
2022 if get_option('wrap_mode') == 'forcefallback'
2023 # Respects "wrap_mode=forcefallback" option
2024 libz_dep = subproject('zlib').get_variable('zlib_dep')
2026 # Don't use the bundled ZLib sources until we are sure that we can't find it on
2028 libz_dep = dependency('zlib', required : false)
2031 if not libz_dep.found()
2032 if cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
2033 libz_dep = cc.find_library('z', required : false)
2035 libz_dep = cc.find_library('zlib1', required : false)
2036 if not libz_dep.found()
2037 libz_dep = cc.find_library('zlib', required : false)
2040 if not libz_dep.found() or not cc.has_header('zlib.h')
2041 libz_dep = subproject('zlib').get_variable('zlib_dep')
2045 # First check in libc, fallback to libintl, and as last chance build
2046 # proxy-libintl subproject.
2047 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
2048 # implementations. This could be extended if issues are found in some platforms.
2050 if cc.has_function('ngettext', args : osx_ldflags)
2051 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset')
2053 # First just find the bare library.
2054 libintl = cc.find_library('intl', required : false)
2055 # The bare library probably won't link without help if it's static.
2056 if libintl.found() and not cc.has_function('ngettext', args : osx_ldflags, dependencies : libintl)
2057 libintl_iconv = cc.find_library('iconv', required : false)
2058 # libintl supports different threading APIs, which may not
2059 # require additional flags, but it defaults to using pthreads if
2060 # found. Meson's "threads" dependency does not allow you to
2061 # prefer pthreads. We may not be using pthreads for glib itself
2062 # either so just link the library to satisfy libintl rather than
2063 # also defining the macros with the -pthread flag.
2064 libintl_pthread = cc.find_library('pthread', required : false)
2065 # Try linking with just libiconv.
2066 if libintl_iconv.found() and cc.has_function('ngettext', args : osx_ldflags, dependencies : [libintl, libintl_iconv])
2067 libintl_deps += [libintl_iconv]
2068 # Then also try linking with pthreads.
2069 elif libintl_iconv.found() and libintl_pthread.found() and cc.has_function('ngettext', args : osx_ldflags, dependencies : [libintl, libintl_iconv, libintl_pthread])
2070 libintl_deps += [libintl_iconv, libintl_pthread]
2072 libintl = disabler()
2075 if not libintl.found()
2076 libintl = subproject('proxy-libintl').get_variable('intl_dep')
2077 libintl_deps = [libintl] + libintl_deps
2078 have_bind_textdomain_codeset = true # proxy-libintl supports it
2080 libintl_deps = [libintl] + libintl_deps
2081 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset', args : osx_ldflags,
2082 dependencies : libintl_deps)
2086 glib_conf.set('HAVE_BIND_TEXTDOMAIN_CODESET', have_bind_textdomain_codeset)
2088 # We require gettext to always be present
2089 glib_conf.set('HAVE_DCGETTEXT', 1)
2090 glib_conf.set('HAVE_GETTEXT', 1)
2092 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
2094 # libmount is only used by gio, but we need to fetch the libs to generate the
2095 # pkg-config file below
2097 if host_system == 'linux'
2098 libmount_dep = dependency('mount', version : '>=2.23', required : get_option('libmount'))
2099 glib_conf.set('HAVE_LIBMOUNT', libmount_dep.found())
2102 if host_system == 'windows'
2103 winsock2 = cc.find_library('ws2_32')
2107 if host_system == 'linux'
2108 selinux_dep = dependency('libselinux', version: '>=2.2', required: get_option('selinux'))
2110 glib_conf.set('HAVE_SELINUX', selinux_dep.found())
2114 if host_system != 'windows' and get_option('xattr')
2115 # either glibc or libattr can provide xattr support
2116 # for both of them, we check for getxattr being in
2117 # the library and a valid xattr header.
2120 if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
2121 glib_conf.set('HAVE_SYS_XATTR_H', 1)
2122 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
2123 #failure. try libattr
2124 elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
2125 glib_conf.set('HAVE_ATTR_XATTR_H', 1)
2126 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
2127 xattr_dep = [cc.find_library('xattr')]
2129 error('No getxattr implementation found in C library or libxattr')
2132 glib_conf.set('HAVE_XATTR', 1)
2133 if cc.compiles(glib_conf_prefix + '''
2135 #ifdef HAVE_SYS_TYPES_H
2136 #include <sys/types.h>
2138 #ifdef HAVE_SYS_XATTR_H
2139 #include <sys/xattr.h>
2140 #elif HAVE_ATTR_XATTR_H
2141 #include <attr/xattr.h>
2145 ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
2148 name : 'XATTR_NOFOLLOW')
2149 glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
2153 # If strlcpy is present (BSD and similar), check that it conforms to the BSD
2154 # specification. Specifically Solaris 8's strlcpy() does not, see
2155 # https://bugzilla.gnome.org/show_bug.cgi?id=53933 for further context.
2156 if cc.has_function('strlcpy')
2158 rres = cc.run('''#include <stdlib.h>
2162 (void) strlcpy (p, "hi", 10);
2163 if (strlcat (p, "bye", 0) != 3)
2167 name : 'OpenBSD strlcpy/strlcat')
2168 if rres.compiled() and rres.returncode() == 0
2169 glib_conf.set('HAVE_STRLCPY', 1)
2171 elif meson.get_cross_property('have_strlcpy', false)
2172 glib_conf.set('HAVE_STRLCPY', 1)
2176 cmdline_test_code = '''
2178 #include <sys/stat.h>
2186 /* This code is a dumbed-down version of g_file_get_contents() */
2190 #define BUFSIZE 1024
2191 char result[BUFSIZE];
2192 struct stat stat_buf;
2194 int fd = open ("/proc/self/cmdline", O_RDONLY|O_BINARY);
2197 if (fstat (fd, &stat_buf))
2200 if (stat_buf.st_size > 0 && S_ISREG (stat_buf.st_mode))
2202 if (read (fd, result, BUFSIZE) <= 0)
2207 FILE *f = fdopen (fd, "r");
2211 if (fread (result, 1, BUFSIZE, f) <= 0)
2221 exit (__getcmdline ());
2225 rres = cc.run(cmdline_test_code, name : '/proc/self/cmdline')
2226 have_proc_self_cmdline = rres.compiled() and rres.returncode() == 0
2228 have_proc_self_cmdline = meson.get_cross_property('have_proc_self_cmdline', false)
2231 glib_conf.set('HAVE_PROC_SELF_CMDLINE', have_proc_self_cmdline)
2233 python = import('python').find_installation('python3')
2234 # used for '#!/usr/bin/env <name>'
2235 python_name = 'python3'
2237 python_version = python.language_version()
2238 python_version_req = '>=3.5'
2239 if not python_version.version_compare(python_version_req)
2240 error('Requires Python @0@, @1@ found.'.format(python_version_req, python_version))
2243 # Determine which user environment-dependent files that we want to install
2244 have_bash = find_program('bash', required : false).found() # For completion scripts
2245 bash_comp_dep = dependency('bash-completion', version: '>=2.0', required: false)
2246 have_sh = find_program('sh', required : false).found() # For glib-gettextize
2248 # Some installed tests require a custom environment
2249 env_program = find_program('env', required: installed_tests_enabled)
2251 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
2252 if host_system == 'sunos'
2253 glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
2254 glib_conf.set('_XOPEN_SOURCE', 2)
2255 glib_conf.set('__EXTENSIONS__',1)
2258 # Sadly Meson does not expose this value:
2259 # https://github.com/mesonbuild/meson/pull/3460
2260 if host_system == 'windows'
2261 # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
2262 # with no explanation. Do the same here for now but this could be revisited if
2264 export_dynamic_ldflags = []
2265 elif host_system == 'cygwin'
2266 export_dynamic_ldflags = ['-Wl,--export-all-symbols']
2267 elif host_system in ['darwin', 'ios']
2268 export_dynamic_ldflags = []
2269 elif host_system == 'sunos'
2270 export_dynamic_ldflags = []
2272 export_dynamic_ldflags = ['-Wl,--export-dynamic']
2277 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
2278 # Ensure MSVC-compatible struct packing convention is used when
2279 # compiling for Win32 with gcc. It is used for the whole project and exposed
2281 win32_cflags = ['-mms-bitfields']
2282 add_project_arguments(win32_cflags, language : 'c')
2284 # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
2285 win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi']
2286 elif host_system == 'cygwin'
2287 win32_ldflags = ['-luser32', '-lkernel32']
2291 want_dtrace = get_option('dtrace')
2292 enable_dtrace = false
2294 # Since dtrace support is opt-in we just error out if it was requested but
2295 # is not available. We don't bother with autodetection yet.
2298 error('GLib dtrace support not yet compatible with macOS dtrace')
2300 dtrace = find_program('dtrace', required : true) # error out if not found
2301 if not cc.has_header('sys/sdt.h')
2302 error('dtrace support needs sys/sdt.h header')
2304 # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
2305 dtrace_obj_gen = generator(dtrace,
2306 output : '@BASENAME@.o',
2307 arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2308 # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
2309 # -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
2310 dtrace_hdr_gen = generator(dtrace,
2311 output : '@BASENAME@.h',
2312 arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2313 glib_conf.set('HAVE_DTRACE', 1)
2314 enable_dtrace = true
2318 want_systemtap = get_option('systemtap')
2319 enable_systemtap = false
2321 if want_systemtap and enable_dtrace
2322 tapset_install_dir = get_option('tapset_install_dir')
2323 if tapset_install_dir == ''
2324 tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
2326 stp_cdata = configuration_data()
2327 stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
2328 stp_cdata.set('LT_CURRENT', minor_version * 100)
2329 stp_cdata.set('LT_REVISION', micro_version)
2330 enable_systemtap = true
2334 test_timeout_slow = 180
2336 pkg = import('pkgconfig')
2337 windows = import('windows')
2348 # xgettext is optional (on Windows for instance)
2349 if find_program('xgettext', required : get_option('nls')).found()
2353 # Install glib-gettextize executable, if a UNIX-style shell is found
2355 # These should not contain " quotes around the values
2356 gettextize_conf = configuration_data()
2357 gettextize_conf.set('PACKAGE', 'glib')
2358 gettextize_conf.set('VERSION', meson.project_version())
2359 gettextize_conf.set('prefix', glib_prefix)
2360 gettextize_conf.set('datarootdir', glib_datadir)
2361 gettextize_conf.set('datadir', glib_datadir)
2362 configure_file(input : 'glib-gettextize.in',
2363 install_dir : glib_bindir,
2364 output : 'glib-gettextize',
2365 configuration : gettextize_conf)
2368 # Install m4 macros that other projects use
2369 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
2370 install_dir : join_paths(get_option('datadir'), 'aclocal'))
2372 if host_system != 'windows'
2373 # Install Valgrind suppression file (except on Windows,
2374 # as Valgrind is currently not supported on Windows)
2375 install_data('glib.supp',
2376 install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
2379 configure_file(output : 'config.h', configuration : glib_conf)
2381 if host_system == 'windows'
2382 install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
2385 if get_option('man')
2386 xsltproc = find_program('xsltproc', required : true)
2387 xsltproc_command = [
2390 '--stringparam', 'man.output.quietly', '1',
2391 '--stringparam', 'funcsynopsis.style', 'ansi',
2392 '--stringparam', 'man.th.extra1.suppress', '1',
2393 '--stringparam', 'man.authors.section.enabled', '0',
2394 '--stringparam', 'man.copyright.section.enabled', '0',
2396 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
2399 man1_dir = join_paths(glib_prefix, get_option('mandir'), 'man1')
2402 gnome = import('gnome')
2403 subdir('docs/reference')