3 # NOTE: See the policy in docs/meson-version.md before changing the Meson dependency
4 meson_version : '>= 0.60.0',
6 'buildtype=debugoptimized',
12 cc = meson.get_compiler('c')
13 have_cxx = add_languages('cpp', native: false, required: get_option('oss_fuzz').enabled())
15 cxx = meson.get_compiler('cpp')
18 cc_can_run = meson.can_run_host_binaries()
20 if cc.get_argument_syntax() == 'msvc'
21 # Ignore several spurious warnings for things glib does very commonly
23 add_project_arguments('/FImsvc_recommended_pragmas.h',language : 'c')
26 if cc.get_id() == 'msvc'
27 # Set the input and exec encoding to utf-8, like is the default with GCC
28 add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c')
29 # Disable SAFESEH with MSVC for plugins and libs that use external deps that
30 # are built with MinGW
31 noseh_link_args = ['/SAFESEH:NO']
34 # -mms-bitfields vs -fnative-struct ?
37 host_system = host_machine.system()
39 if host_system == 'darwin'
40 ios_test_code = '''#include <TargetConditionals.h>
41 #if ! TARGET_OS_IPHONE
42 #error "Not iOS/tvOS/watchOS/iPhoneSimulator"
44 if cc.compiles(ios_test_code, name : 'building for iOS')
49 glib_version = meson.project_version()
50 glib_api_version = '2.0'
51 version_arr = glib_version.split('.')
52 major_version = version_arr[0].to_int()
53 minor_version = version_arr[1].to_int()
54 micro_version = version_arr[2].to_int()
56 interface_age = minor_version.is_odd() ? 0 : micro_version
57 binary_age = 100 * minor_version + micro_version
60 # Maintain compatibility with previous libtool versioning
61 # current = minor * 100 + micro
62 current = binary_age - interface_age
63 library_version = '@0@.@1@.@2@'.format(soversion, current, interface_age)
64 darwin_versions = [current + 1, '@0@.@1@'.format(current + 1, interface_age)]
66 configinc = include_directories('.')
67 glibinc = include_directories('glib')
68 gobjectinc = include_directories('gobject')
69 gmoduleinc = include_directories('gmodule')
70 gioinc = include_directories('gio')
72 glib_prefix = get_option('prefix')
73 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
74 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
75 glib_libexecdir = join_paths(glib_prefix, get_option('libexecdir'))
76 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
77 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
78 glib_includedir = join_paths(glib_prefix, get_option('includedir'))
79 if get_option('gio_module_dir') != ''
80 glib_giomodulesdir = join_paths(glib_prefix, get_option('gio_module_dir'))
82 glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
85 if get_option('multiarch')
86 # For multiarch/multilib distributions, install each architecture's
87 # build of executables used in packaging triggers (like gio-querymodules)
88 # to an architecture-dependent location, with a compatibility symlink
90 multiarch_bindir = get_option('libdir') / 'glib-2.0'
91 multiarch_libexecdir = multiarch_bindir
92 pkgconfig_multiarch_bindir = '${libdir}/glib-2.0'
94 # For single-architecture distributions, just install them into the PATH
95 # as was traditionally done.
96 multiarch_bindir = get_option('bindir')
97 multiarch_libexecdir = get_option('libexecdir')
98 pkgconfig_multiarch_bindir = '${bindir}'
101 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
103 if get_option('charsetalias_dir') != ''
104 glib_charsetaliasdir = join_paths(glib_prefix, get_option('charsetalias_dir'))
106 glib_charsetaliasdir = glib_libdir
109 glib_localstatedir = get_option('localstatedir')
110 if not glib_localstatedir.startswith('/')
111 # See https://mesonbuild.com/Builtin-options.html#directories
112 glib_localstatedir = join_paths(glib_prefix, glib_localstatedir)
115 installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
116 installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
117 installed_tests_enabled = get_option('installed_tests')
118 installed_tests_template = files('tests/template.test.in')
119 installed_tests_template_tap = files('tests/template-tap.test.in')
121 # Don’t build the tests unless we can run them (either natively, in an exe wrapper, or by installing them for later use)
122 build_tests = get_option('tests') and (meson.can_run_host_binaries() or installed_tests_enabled)
124 # Allow the tests to be easily run under valgrind using --setup=valgrind
125 valgrind = find_program('valgrind', required: false)
127 suppression_file = files('tools' / 'glib.supp')
129 add_test_setup('valgrind',
130 exclude_suites: [ 'no-valgrind' ],
134 '--error-exitcode=1',
135 '--track-origins=yes',
137 '--leak-resolution=high',
139 '--show-leak-kinds=definite,possible',
140 '--show-error-list=yes',
141 '--suppressions=@0@'.format(meson.project_source_root() /
142 '@0@'.format(suppression_file[0])),
144 timeout_multiplier: 10,
148 add_project_arguments('-D_GNU_SOURCE', language: 'c')
150 if host_system == 'qnx'
151 add_project_arguments('-D_QNX_SOURCE', language: 'c')
154 # Disable strict aliasing;
155 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
156 if cc.has_argument('-fno-strict-aliasing')
157 add_project_arguments('-fno-strict-aliasing', language: 'c')
160 # dummy/empty dependency() object to declare fallbacks and simpler dependencies
161 not_found = dependency('', required: false)
163 ########################
164 # Configuration begins #
165 ########################
166 glib_conf = configuration_data()
167 glibconfig_conf = configuration_data()
169 # accumulated list of defines as we check for them, so we can easily
170 # use them later in test programs (autoconf does this automatically)
171 glib_conf_prefix = ''
173 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
174 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
175 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
176 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
177 glib_conf.set('GLIB_BINARY_AGE', binary_age)
178 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
179 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
180 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
181 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
182 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
183 glib_conf.set_quoted('PACKAGE_URL', '')
184 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
185 glib_conf.set('ENABLE_NLS', 1)
187 # used by the .rc.in files
188 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
190 glib_conf.set('_GNU_SOURCE', 1)
192 if host_system in ['windows', 'darwin']
193 # Poll doesn't work on devices on Windows, and macOS's poll() implementation is known to be broken
194 glib_conf.set('BROKEN_POLL', true)
197 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
198 # FIXME: Ideally we shouldn't depend on this on Windows and should use
199 # 64 bit capable Windows API that also works with MSVC.
200 # The autotools build did set this for mingw and while meson sets it
201 # for gcc/clang by default, it doesn't do so on Windows.
202 glib_conf.set('_FILE_OFFSET_BITS', 64)
205 # Check for GNU visibility attributes
206 g_have_gnuc_visibility = cc.compiles('''
208 __attribute__ ((visibility ("hidden")))
213 __attribute__ ((visibility ("internal")))
218 __attribute__ ((visibility ("default")))
230 # Not supported by MSVC, but MSVC also won't support visibility,
231 # so it's OK to pass -Werror explicitly. Replace with
232 # override_options : 'werror=true' once that is supported
234 name : 'GNU C visibility attributes test')
236 if g_have_gnuc_visibility
237 glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
240 # Detect and set symbol visibility
241 glib_hidden_visibility_args = []
242 if get_option('default_library') != 'static'
243 if host_system == 'windows' or host_system == 'cygwin'
244 if get_option('default_library') != 'shared'
245 error('On Windows default_library must be "shared" or "static" but not "both"')
247 glib_conf.set('DLL_EXPORT', true)
248 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
249 glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
250 elif cc.has_argument('-fvisibility=hidden')
251 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
252 glib_hidden_visibility_args = ['-fvisibility=hidden']
254 elif cc.has_argument('-fvisibility=hidden')
255 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
256 glib_hidden_visibility_args = ['-fvisibility=hidden']
260 if get_option('default_library') == 'static'
261 glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
262 glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
263 glibconfig_conf.set('G_INTL_STATIC_COMPILATION', '1')
264 glibconfig_conf.set('FFI_STATIC_BUILD', '1')
267 # Cygwin glib port maintainers made it clear
268 # (via the patches they apply) that they want no
269 # part of glib W32 code, therefore we do not define
270 # G_PLATFORM_WIN32 for host_system == 'cygwin'.
271 # This makes G_PLATFORM_WIN32 a synonym for
273 if host_system == 'windows'
274 glib_os = '''#define G_OS_WIN32
275 #define G_PLATFORM_WIN32'''
276 elif host_system == 'cygwin'
277 glib_os = '''#define G_OS_UNIX
278 #define G_WITH_CYGWIN'''
280 glib_os = '#define G_OS_UNIX'
282 glibconfig_conf.set('glib_os', glib_os)
284 # We need to know the CRT being used to determine what .lib files we need on
285 # Visual Studio for dependencies that don't normally come with pkg-config files
287 vs_crt_opt = get_option('b_vscrt')
288 if vs_crt_opt in ['mdd', 'mtd']
290 elif vs_crt_opt == 'from_buildtype'
291 if get_option('buildtype') == 'debug'
296 # Use debug/optimization flags to determine whether to enable debug or disable
297 # cast checks. We have a non-production (debug) build if debug is true and if
298 # optimization is 0 or g; otherwise, we have a production build.
299 glib_debug_cflags = []
300 glib_debug = get_option('glib_debug')
301 optimized_build = get_option('optimization') not in [ '0', 'g' ]
302 if glib_debug.enabled() or (glib_debug.auto() and get_option('debug') and not optimized_build)
303 glib_debug_cflags += ['-DG_ENABLE_DEBUG']
304 message('Enabling various debug infrastructure')
306 glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
307 message('Disabling cast checks')
310 if not get_option('glib_assert')
311 glib_debug_cflags += ['-DG_DISABLE_ASSERT']
312 message('Disabling GLib asserts')
315 if not get_option('glib_checks')
316 glib_debug_cflags += ['-DG_DISABLE_CHECKS']
317 message('Disabling GLib checks')
320 add_project_arguments(glib_debug_cflags, language: 'c')
322 # check for header files
328 'dirent.h', # MSC does not come with this by default
362 'sys/time.h', # MSC does not come with this by default
379 define = 'HAVE_' + h.underscorify().to_upper()
380 glib_conf.set(define, 1)
381 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
385 # FreeBSD includes a malloc.h which always throws compilation error, so we have
386 # to use check_header() rather than has_header().
387 if cc.check_header('malloc.h')
388 glib_conf.set('HAVE_MALLOC_H', 1)
389 glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
392 if cc.has_header('linux/netlink.h')
393 glib_conf.set('HAVE_NETLINK', 1)
396 # Is statx() supported? Android systems don’t reliably support it as of August 2020.
401 #include <sys/stat.h>
405 struct statx stat_buf;
406 return statx (AT_FDCWD, "/", AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS | STATX_BTIME, &stat_buf);
409 if host_system != 'android' and cc.compiles(statx_code, name : 'statx() test')
410 glib_conf.set('HAVE_STATX', 1)
413 if glib_conf.has('HAVE_LOCALE_H')
414 if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
415 glib_conf.set('HAVE_LC_MESSAGES', 1)
419 struct_stat_blkprefix = '''
420 #include <sys/types.h>
421 #include <sys/stat.h>
425 #ifdef HAVE_SYS_STATFS_H
426 #include <sys/statfs.h>
428 #ifdef HAVE_SYS_PARAM_H
429 #include <sys/param.h>
431 #ifdef HAVE_SYS_MOUNT_H
432 #include <sys/mount.h>
437 [ 'stat', 'st_mtimensec' ],
438 [ 'stat', 'st_mtim.tv_nsec' ],
439 [ 'stat', 'st_atimensec' ],
440 [ 'stat', 'st_atim.tv_nsec' ],
441 [ 'stat', 'st_ctimensec' ],
442 [ 'stat', 'st_ctim.tv_nsec' ],
443 [ 'stat', 'st_birthtime' ],
444 [ 'stat', 'st_birthtimensec' ],
445 [ 'stat', 'st_birthtim' ],
446 [ 'stat', 'st_birthtim.tv_nsec' ],
447 [ 'stat', 'st_blksize', struct_stat_blkprefix ],
448 [ 'stat', 'st_blocks', struct_stat_blkprefix ],
449 [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
450 [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
451 [ 'dirent', 'd_type', '''#include <sys/types.h>
452 #include <dirent.h>''' ],
453 [ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
454 [ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
455 [ 'tm', 'tm_gmtoff', '#include <time.h>' ],
456 [ 'tm', '__tm_gmtoff', '#include <time.h>' ],
459 foreach m : struct_members
460 header_check_prefix = glib_conf_prefix
462 header_check_prefix = header_check_prefix + m[2]
464 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
466 if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
467 define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
468 glib_conf.set(define, 1)
469 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
475 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
476 warning_common_args = [
477 '-Wduplicated-branches',
478 '-Wimplicit-fallthrough',
479 '-Wmisleading-indentation',
481 # Due to maintained deprecated code, we do not want to see unused parameters
482 '-Wno-unused-parameter',
483 # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
484 # building with -Wbad-function-cast.
485 '-Wno-cast-function-type',
486 # Due to function casts through (void*) we cannot support -Wpedantic:
487 # https://wiki.gnome.org/Projects/GLib/CompilerRequirements#Function_pointer_conversions.
489 # A zero-length format string shouldn't be considered an issue.
490 '-Wno-format-zero-length',
491 # We explicitly require variadic macros
492 '-Wno-variadic-macros',
495 '-Werror=missing-include-dirs',
496 '-Werror=pointer-arith',
497 '-Werror=unused-result',
500 warning_c_args = warning_common_args + [
501 '-Wstrict-prototypes',
502 # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
503 # building with -Wbad-function-cast.
504 '-Wno-bad-function-cast',
505 '-Werror=declaration-after-statement',
506 '-Werror=implicit-function-declaration',
507 '-Werror=missing-prototypes',
508 '-Werror=pointer-sign',
510 warning_cxx_args = warning_common_args
511 warning_objc_args = warning_c_args
512 warning_c_link_args = [
515 if get_option('bsymbolic_functions')
516 warning_c_link_args += ['-Wl,-Bsymbolic-functions']
518 elif cc.get_id() == 'msvc'
520 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
521 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
522 # NOTE: Only add warnings here if you are sure they're spurious
523 '/wo4057', # 'operator': 'identifier1' differs in indirection to slightly different base types from 'identifier2'
524 '/wd4068', # unknown pragma
525 '/wo4090', # 'operation': different 'modifier' qualifiers
526 '/wd4100', # 'identifier': unreferenced formal parameter
527 '/wd4116', # unnamed type definition in parentheses
528 '/wo4125', # decimal digit terminates octal escape sequence
529 '/wd4127', # conditional expression is constant
530 '/wd4146', # unary minus operator applied to unsigned type, result still unsigned
531 '/wd4152', # nonstandard extension, function/data pointer conversion in expression
532 '/wd4201', # nonstandard extension used: nameless struct/union
533 '/wd4232', # nonstandard extension used: 'identifier': address of dllimport 'dllimport' is not static, identity not guaranteed
534 '/wo4245', # 'conversion_type': conversion from 'type1' to 'type2', signed/unsigned mismatch
535 '/wo4267', # 'variable': conversion from 'size_t' to 'type', possible loss of data
536 '/wd4334', # 'shift_operator': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
537 '/wo4389', # 'operator': signed/unsigned mismatch
538 '/wo4702', # unreachable code
539 '/wd4706', # assignment within conditional expression
542 warning_cxx_args = []
543 warning_objc_args = []
544 warning_c_link_args = []
547 warning_cxx_args = []
548 warning_objc_args = []
549 warning_c_link_args = []
552 add_project_arguments(cc.get_supported_arguments(warning_c_args), language: 'c')
554 add_project_arguments(cxx.get_supported_arguments(warning_cxx_args), language: 'cpp')
557 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
558 # means we cannot use that flag in add_project_link_arguments(), and must add
559 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
560 # because that is what the autotools build did.
561 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
563 glib_link_flags = cc.get_supported_link_arguments(warning_c_link_args)
565 # Windows SDK requirements and checks
566 if host_system == 'windows'
567 # Check whether we're building for UWP apps
570 #if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
571 #error "Not building for UWP"
573 if cc.compiles(code, name : 'building for UWP')
574 glib_conf.set('G_WINAPI_ONLY_APP', true)
575 # We require Windows 10+ on WinRT
576 glib_conf.set('_WIN32_WINNT', '0x0A00')
577 uwp_gio_deps = [cc.find_library('shcore'),
578 cc.find_library('runtimeobject')]
580 # We require Windows 7+ on Win32
581 glib_conf.set('_WIN32_WINNT', '0x0601')
648 # _NSGetEnviron is available on iOS too, but its usage gets apps rejected from
649 # the app store since it's considered 'private API'
650 if host_system == 'darwin'
651 functions += ['_NSGetEnviron']
654 if glib_conf.has('HAVE_SYS_STATVFS_H')
655 functions += ['statvfs']
657 have_func_statvfs = false
659 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
660 functions += ['statfs']
662 have_func_statfs = false
665 if host_system == 'windows'
666 iphlpapi_dep = cc.find_library('iphlpapi')
667 iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
668 foreach ifunc : iphlpapi_funcs
669 iphl_prefix = '''#define _WIN32_WINNT @0@
670 #include <winsock2.h>
671 #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
672 if cc.has_function(ifunc,
673 prefix : iphl_prefix,
674 dependencies : iphlpapi_dep)
675 idefine = 'HAVE_' + ifunc.underscorify().to_upper()
676 glib_conf.set(idefine, 1)
677 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
678 set_variable('have_func_' + ifunc, true)
680 set_variable('have_func_' + ifunc, false)
684 functions += ['if_indextoname', 'if_nametoindex']
687 # AIX splice is something else
688 if host_system != 'aix'
689 functions += ['splice']
692 foreach f : functions
693 if cc.has_function(f)
694 define = 'HAVE_' + f.underscorify().to_upper()
695 glib_conf.set(define, 1)
696 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
697 set_variable('have_func_' + f, true)
699 set_variable('have_func_' + f, false)
703 # Check that stpcpy() is usable; must use header.
704 # cc.has_function() in some cases (clang, gcc 10+) assumes that if the
705 # compiler provides a builtin of the same name that the function exists, while
706 # it's in fact not provided by any header or library. This is true for
707 # stpcpy() on Windows using clang and gcc as well as posix_memalign() using
708 # gcc on Windows. Skip these checks on Windows for now to avoid false
709 # positives. See https://github.com/mesonbuild/meson/pull/7116,
710 # https://github.com/mesonbuild/meson/issues/3672 and
711 # https://github.com/mesonbuild/meson/issues/5628.
712 # FIXME: Once meson no longer returns success for stpcpy() and
713 # posix_memalign() on Windows using GCC and clang we can remove this.
714 if host_system != 'windows' and cc.has_function('stpcpy', prefix : '#include <string.h>')
715 glib_conf.set('HAVE_STPCPY', 1)
718 if cc.has_function('memalign', prefix: '#include <stdlib.h>\n#include <malloc.h>')
719 glib_conf.set('HAVE_MEMALIGN', 1)
722 if cc.has_function('_aligned_malloc', prefix: '#include <malloc.h>')
723 glib_conf.set('HAVE__ALIGNED_MALLOC', 1)
726 if host_system != 'windows' and cc.has_function('aligned_alloc', prefix: '#include <stdlib.h>')
727 glib_conf.set('HAVE_ALIGNED_ALLOC', 1)
730 if host_system != 'windows' and cc.has_function('posix_memalign', prefix: '#include <stdlib.h>')
731 glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
734 # Check that posix_spawn() is usable; must use header
735 if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
736 glib_conf.set('HAVE_POSIX_SPAWN', 1)
739 # Check whether strerror_r returns char *
740 if have_func_strerror_r
741 if cc.compiles('''#define _GNU_SOURCE
744 char error_string[256];
745 char *ptr = strerror_r (-2, error_string, 256);
746 char c = *strerror_r (-2, error_string, 256);
747 return c != 0 && ptr != (void*) 0L;
750 name : 'strerror_r() returns char *')
751 glib_conf.set('STRERROR_R_CHAR_P', 1,
752 description: 'Defined if strerror_r returns char *')
756 # Special-case these functions that have alternative names on Windows/MSVC
757 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
758 glib_conf.set('HAVE_SNPRINTF', 1)
759 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
760 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
761 hack_define = '1\n#define snprintf _snprintf'
762 glib_conf.set('HAVE_SNPRINTF', hack_define)
763 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
766 if cc.has_function('strcasecmp', prefix: '#include <strings.h>')
767 glib_conf.set('HAVE_STRCASECMP', 1)
768 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
769 elif cc.has_function('_stricmp')
770 hack_define = '1\n#define strcasecmp _stricmp'
771 glib_conf.set('HAVE_STRCASECMP', hack_define)
772 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
775 if cc.has_function('strncasecmp', prefix: '#include <strings.h>')
776 glib_conf.set('HAVE_STRNCASECMP', 1)
777 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
778 elif cc.has_function('_strnicmp')
779 hack_define = '1\n#define strncasecmp _strnicmp'
780 glib_conf.set('HAVE_STRNCASECMP', hack_define)
781 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
784 if cc.has_header_symbol('sys/sysmacros.h', 'major')
785 glib_conf.set('MAJOR_IN_SYSMACROS', 1)
786 elif cc.has_header_symbol('sys/mkdev.h', 'major')
787 glib_conf.set('MAJOR_IN_MKDEV', 1)
788 elif cc.has_header_symbol('sys/types.h', 'major')
789 glib_conf.set('MAJOR_IN_TYPES', 1)
792 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
793 glib_conf.set('HAVE_RTLD_LAZY', 1)
796 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
797 glib_conf.set('HAVE_RTLD_NOW', 1)
800 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
801 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
804 have_rtld_next = false
805 if cc.has_header_symbol('dlfcn.h', 'RTLD_NEXT', args: '-D_GNU_SOURCE')
806 have_rtld_next = true
807 glib_conf.set('HAVE_RTLD_NEXT', 1)
810 # Check whether to use statfs or statvfs
811 # Some systems have both statfs and statvfs, pick the most "native" for these
812 if have_func_statfs and have_func_statvfs
813 # on solaris and irix, statfs doesn't even have the f_bavail field
814 if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
815 have_func_statfs = false
817 # at least on linux, statfs is the actual syscall
818 have_func_statvfs = false
822 glib_conf.set('USE_STATFS', 1)
823 stat_func_to_use = 'statfs'
824 elif have_func_statvfs
825 glib_conf.set('USE_STATVFS', 1)
826 stat_func_to_use = 'statvfs'
828 stat_func_to_use = 'neither'
830 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
832 if host_system == 'linux'
833 if cc.has_function('mkostemp',
834 prefix: '''#define _GNU_SOURCE
835 #include <stdlib.h>''')
836 glib_conf.set('HAVE_MKOSTEMP', 1)
840 glib_have_os_x_9_or_later = false
841 glib_have_carbon = false
842 glib_have_cocoa = false
843 if host_system == 'darwin'
844 add_languages('objc', native: false, required: true)
845 objcc = meson.get_compiler('objc')
847 add_project_arguments(objcc.get_supported_arguments(warning_objc_args), language: 'objc')
849 # Mac OS X Carbon support
850 glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
851 #include <CoreServices/CoreServices.h>''',
852 name : 'Mac OS X Carbon support')
855 glib_conf.set('HAVE_CARBON', true)
856 glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
857 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
858 #error Compiling for minimum OS X version before 10.9
860 name : 'OS X 9 or later')
863 # Mac OS X Cocoa support
864 glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
865 #ifdef GNUSTEP_BASE_VERSION
866 #error "Detected GNUstep, not Cocoa"
868 name : 'Mac OS X Cocoa support')
871 glib_conf.set('HAVE_COCOA', true)
875 if host_system == 'qnx'
876 glib_conf.set('HAVE_QNX', 1)
880 if cc.links('''#include <linux/futex.h>
881 #include <sys/syscall.h>
883 int main (int argc, char ** argv) {
884 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
886 }''', name : 'futex(2) system call')
887 glib_conf.set('HAVE_FUTEX', 1)
890 # Check for eventfd(2)
891 if cc.links('''#include <sys/eventfd.h>
893 int main (int argc, char ** argv) {
894 eventfd (0, EFD_CLOEXEC);
896 }''', name : 'eventfd(2) system call')
897 glib_conf.set('HAVE_EVENTFD', 1)
900 # Check for pidfd_open(2)
901 if cc.links('''#include <sys/syscall.h>
902 #include <sys/wait.h>
903 #include <linux/wait.h>
905 int main (int argc, char ** argv) {
906 siginfo_t child_info = { 0, };
907 syscall (SYS_pidfd_open, 0, 0);
908 waitid (P_PIDFD, 0, &child_info, WEXITED | WNOHANG);
910 }''', name : 'pidfd_open(2) system call')
911 glib_conf.set('HAVE_PIDFD', 1)
914 # Check for __uint128_t (gcc) by checking for 128-bit division
915 uint128_t_src = '''int main() {
916 static __uint128_t v1 = 100;
917 static __uint128_t v2 = 10;
918 static __uint128_t u;
921 if cc.compiles(uint128_t_src, name : '__uint128_t available')
922 glib_conf.set('HAVE_UINT128_T', 1)
925 clock_gettime_test_code = '''
928 int main (int argc, char ** argv) {
929 return clock_gettime(CLOCK_REALTIME, &t);
932 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
933 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
934 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
935 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
936 librt = cc.find_library('rt')
939 dlopen_dlsym_test_code = '''
941 int glib_underscore_test (void) { return 42; }
942 int main (int argc, char ** argv) {
943 void *f1 = (void*)0, *f2 = (void*)0, *handle;
944 handle = dlopen ((void*)0, 0);
946 f1 = dlsym (handle, "glib_underscore_test");
947 f2 = dlsym (handle, "_glib_underscore_test");
952 if cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
953 have_dlopen_dlsym = true
954 elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
955 have_dlopen_dlsym = true
956 libdl_dep = cc.find_library('dl')
958 have_dlopen_dlsym = false
961 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
963 if cc.compiles(glib_conf_prefix + '''
965 #ifdef HAVE_SYS_PARAM_H
966 #include <sys/param.h>
968 #ifdef HAVE_SYS_VFS_H
971 #ifdef HAVE_SYS_MOUNT_H
972 #include <sys/mount.h>
974 #ifdef HAVE_SYS_STATFS_H
975 #include <sys/statfs.h>
977 void some_func (void) {
980 }''', name : 'number of arguments to statfs() (n=2)')
981 glib_conf.set('STATFS_ARGS', 2)
982 elif cc.compiles(glib_conf_prefix + '''
984 #ifdef HAVE_SYS_PARAM_H
985 #include <sys/param.h>
987 #ifdef HAVE_SYS_VFS_H
990 #ifdef HAVE_SYS_MOUNT_H
991 #include <sys/mount.h>
993 #ifdef HAVE_SYS_STATFS_H
994 #include <sys/statfs.h>
996 void some_func (void) {
998 statfs("/", &st, sizeof (st), 0);
999 }''', name : 'number of arguments to statfs() (n=4)')
1000 glib_conf.set('STATFS_ARGS', 4)
1002 error('Unable to determine number of arguments to statfs()')
1006 # open takes O_DIRECTORY as an option
1007 #AC_MSG_CHECKING([])
1008 if cc.compiles('''#include <fcntl.h>
1009 #include <sys/types.h>
1010 #include <sys/stat.h>
1011 void some_func (void) {
1012 open(0, O_DIRECTORY, 0);
1013 }''', name : 'open() option O_DIRECTORY')
1014 glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
1017 # fcntl takes F_FULLFSYNC as an option
1018 # See https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html
1019 if cc.compiles('''#include <fcntl.h>
1020 #include <sys/types.h>
1021 #include <sys/stat.h>
1022 void some_func (void) {
1023 fcntl(0, F_FULLFSYNC, 0);
1024 }''', name : 'fcntl() option F_FULLFSYNC')
1025 glib_conf.set('HAVE_FCNTL_F_FULLFSYNC', 1)
1028 # Check whether there is a vsnprintf() function with C99 semantics installed.
1029 # (similar tests to AC_FUNC_VSNPRINTF_C99)
1030 # Check whether there is a snprintf() function with C99 semantics installed.
1031 # (similar tests to AC_FUNC_SNPRINTF_C99)
1032 # Check whether there is a printf() function with Unix98 semantics installed.
1033 # (similar tests to AC_FUNC_PRINTF_UNIX98)
1034 have_good_vsnprintf = false
1035 have_good_snprintf = false
1036 have_good_printf = false
1038 if host_system == 'windows' and (cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl')
1039 # Unfortunately the Visual Studio 2015+ implementations of C99-style
1040 # snprintf and vsnprintf don't seem to be quite good enough.
1041 # (Sorry, I don't know exactly what is the problem,
1042 # but it is related to floating point formatting and decimal point vs. comma.)
1043 # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
1044 # rigorous enough to notice, though.
1045 glib_conf.set('HAVE_C99_SNPRINTF', false)
1046 glib_conf.set('HAVE_C99_VSNPRINTF', false)
1047 glib_conf.set('HAVE_UNIX98_PRINTF', false)
1048 elif not cc_can_run and host_system in ['ios', 'darwin']
1049 # All these are true when compiling natively on macOS, so we should use good
1050 # defaults when building for iOS and tvOS.
1051 glib_conf.set('HAVE_C99_SNPRINTF', true)
1052 glib_conf.set('HAVE_C99_VSNPRINTF', true)
1053 glib_conf.set('HAVE_UNIX98_PRINTF', true)
1054 have_good_vsnprintf = true
1055 have_good_snprintf = true
1056 have_good_printf = true
1058 vsnprintf_c99_test_code = '''
1071 r = vsnprintf(buffer, 5, s, args);
1077 /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
1078 implementation. The above will return 7 but if you replace
1079 the size of the buffer with 0, it borks! */
1081 r = vsnprintf(buffer, 0, s, args);
1098 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
1099 if rres.compiled() and rres.returncode() == 0
1100 glib_conf.set('HAVE_C99_VSNPRINTF', 1)
1101 have_good_vsnprintf = true
1104 have_good_vsnprintf = meson.get_external_property('have_c99_vsnprintf', false)
1105 glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
1108 snprintf_c99_test_code = '''
1120 r = snprintf(buffer, 5, "1234567");
1125 r = snprintf(buffer, 0, "1234567");
1130 r = snprintf(NULL, 0, "1234567");
1146 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
1147 if rres.compiled() and rres.returncode() == 0
1148 glib_conf.set('HAVE_C99_SNPRINTF', 1)
1149 have_good_snprintf = true
1152 have_good_snprintf = meson.get_external_property('have_c99_snprintf', false)
1153 glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
1156 printf_unix98_test_code = '''
1166 sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
1167 if (strcmp ("2 3 1", buffer) == 0)
1173 rres = cc.run(printf_unix98_test_code, name : 'Unix98 printf positional parameters')
1174 if rres.compiled() and rres.returncode() == 0
1175 glib_conf.set('HAVE_UNIX98_PRINTF', 1)
1176 have_good_printf = true
1179 have_good_printf = meson.get_external_property('have_unix98_printf', false)
1180 glib_conf.set('HAVE_UNIX98_PRINTF', have_good_printf)
1184 if host_system == 'windows'
1185 glib_conf.set_quoted('EXEEXT', '.exe')
1187 glib_conf.set('EXEEXT', '')
1190 # Our printf is 'good' only if vsnpintf()/snprintf()/printf() supports C99 well enough
1191 use_system_printf = have_good_vsnprintf and have_good_snprintf and have_good_printf
1192 glib_conf.set('USE_SYSTEM_PRINTF', use_system_printf)
1193 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', use_system_printf)
1195 if not use_system_printf
1196 # gnulib has vasprintf so override the previous check
1197 glib_conf.set('HAVE_VASPRINTF', 1)
1200 # Check for nl_langinfo and CODESET
1201 if cc.links('''#include <langinfo.h>
1202 int main (int argc, char ** argv) {
1203 char *codeset = nl_langinfo (CODESET);
1205 }''', name : 'nl_langinfo and CODESET')
1206 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
1207 glib_conf.set('HAVE_CODESET', 1)
1210 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
1211 if cc.links('''#include <langinfo.h>
1212 int main (int argc, char ** argv) {
1214 str = nl_langinfo (PM_STR);
1215 str = nl_langinfo (D_T_FMT);
1216 str = nl_langinfo (D_FMT);
1217 str = nl_langinfo (T_FMT);
1218 str = nl_langinfo (T_FMT_AMPM);
1219 str = nl_langinfo (MON_1);
1220 str = nl_langinfo (ABMON_12);
1221 str = nl_langinfo (DAY_1);
1222 str = nl_langinfo (ABDAY_7);
1224 }''', name : 'nl_langinfo (PM_STR)')
1225 glib_conf.set('HAVE_LANGINFO_TIME', 1)
1227 if cc.links('''#include <langinfo.h>
1228 int main (int argc, char ** argv) {
1230 str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
1231 str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
1232 str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
1233 str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
1234 str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
1235 str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
1236 str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
1237 str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
1238 str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
1239 str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
1241 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
1242 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
1245 # Check for nl_langinfo and alternative month names
1246 if cc.links('''#ifndef _GNU_SOURCE
1247 # define _GNU_SOURCE
1249 #include <langinfo.h>
1250 int main (int argc, char ** argv) {
1252 str = nl_langinfo (ALTMON_1);
1253 str = nl_langinfo (ALTMON_2);
1254 str = nl_langinfo (ALTMON_3);
1255 str = nl_langinfo (ALTMON_4);
1256 str = nl_langinfo (ALTMON_5);
1257 str = nl_langinfo (ALTMON_6);
1258 str = nl_langinfo (ALTMON_7);
1259 str = nl_langinfo (ALTMON_8);
1260 str = nl_langinfo (ALTMON_9);
1261 str = nl_langinfo (ALTMON_10);
1262 str = nl_langinfo (ALTMON_11);
1263 str = nl_langinfo (ALTMON_12);
1265 }''', name : 'nl_langinfo (ALTMON_n)')
1266 glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
1269 # Check for nl_langinfo and abbreviated alternative month names
1270 if cc.links('''#ifndef _GNU_SOURCE
1271 # define _GNU_SOURCE
1273 #include <langinfo.h>
1274 int main (int argc, char ** argv) {
1276 str = nl_langinfo (_NL_ABALTMON_1);
1277 str = nl_langinfo (_NL_ABALTMON_2);
1278 str = nl_langinfo (_NL_ABALTMON_3);
1279 str = nl_langinfo (_NL_ABALTMON_4);
1280 str = nl_langinfo (_NL_ABALTMON_5);
1281 str = nl_langinfo (_NL_ABALTMON_6);
1282 str = nl_langinfo (_NL_ABALTMON_7);
1283 str = nl_langinfo (_NL_ABALTMON_8);
1284 str = nl_langinfo (_NL_ABALTMON_9);
1285 str = nl_langinfo (_NL_ABALTMON_10);
1286 str = nl_langinfo (_NL_ABALTMON_11);
1287 str = nl_langinfo (_NL_ABALTMON_12);
1289 }''', name : 'nl_langinfo (_NL_ABALTMON_n)')
1290 glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
1293 # Check for nl_langinfo and _NL_TIME_CODESET
1294 if cc.links('''#include <langinfo.h>
1295 int main (int argc, char ** argv) {
1296 char *codeset = nl_langinfo (_NL_TIME_CODESET);
1298 }''', name : 'nl_langinfo and _NL_TIME_CODESET')
1299 glib_conf.set('HAVE_LANGINFO_TIME_CODESET', 1)
1302 # Check if C compiler supports the 'signed' keyword
1303 if not cc.compiles('''signed char x;''', name : 'signed')
1304 glib_conf.set('signed', '/* NOOP */')
1307 # Check if the ptrdiff_t type exists
1308 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
1309 glib_conf.set('HAVE_PTRDIFF_T', 1)
1312 # Check for sig_atomic_t type
1313 if cc.links('''#include <signal.h>
1314 #include <sys/types.h>
1315 sig_atomic_t val = 42;
1316 int main (int argc, char ** argv) {
1317 return val == 42 ? 0 : 1;
1318 }''', name : 'sig_atomic_t')
1319 glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
1322 # Check if 'long long' works
1323 # jm_AC_TYPE_LONG_LONG
1324 if cc.compiles('''long long ll = 1LL;
1326 int some_func (void) {
1327 long long llmax = (long long) -1;
1328 return ll << i | ll >> i | llmax / ll | llmax % ll;
1329 }''', name : 'long long')
1330 glib_conf.set('HAVE_LONG_LONG', 1)
1331 have_long_long = true
1333 have_long_long = false
1336 # Test whether the compiler supports the 'long double' type.
1337 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
1338 long double foo = 0.0;
1339 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
1340 int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
1341 name : 'long double')
1342 glib_conf.set('HAVE_LONG_DOUBLE', 1)
1345 # Test whether <stddef.h> has the 'wchar_t' type.
1346 if cc.has_header_symbol('stddef.h', 'wchar_t')
1347 glib_conf.set('HAVE_WCHAR_T', 1)
1350 # Test whether <wchar.h> has the 'wint_t' type.
1351 if cc.has_header_symbol('wchar.h', 'wint_t')
1352 glib_conf.set('HAVE_WINT_T', 1)
1355 found_uintmax_t = false
1357 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
1358 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1359 # jm_AC_HEADER_INTTYPES_H
1360 if cc.compiles('''#include <sys/types.h>
1361 #include <inttypes.h>
1362 void some_func (void) {
1363 uintmax_t i = (uintmax_t) -1;
1364 }''', name : 'uintmax_t in inttypes.h')
1365 glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1366 found_uintmax_t = true
1369 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1370 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1371 # jm_AC_HEADER_STDINT_H
1372 if cc.compiles('''#include <sys/types.h>
1374 void some_func (void) {
1375 uintmax_t i = (uintmax_t) -1;
1376 }''', name : 'uintmax_t in stdint.h')
1377 glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1378 found_uintmax_t = true
1381 # Define intmax_t to 'long' or 'long long'
1382 # if it is not already defined in <stdint.h> or <inttypes.h>.
1383 # For simplicity, we assume that a header file defines 'intmax_t' if and
1384 # only if it defines 'uintmax_t'.
1386 glib_conf.set('HAVE_INTMAX_T', 1)
1388 glib_conf.set('intmax_t', 'long long')
1390 glib_conf.set('intmax_t', 'long')
1393 char_size = cc.sizeof('char')
1394 short_size = cc.sizeof('short')
1395 int_size = cc.sizeof('int')
1396 voidp_size = cc.sizeof('void*')
1397 long_size = cc.sizeof('long')
1399 long_long_size = cc.sizeof('long long')
1403 sizet_size = cc.sizeof('size_t')
1404 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1405 ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1407 ssizet_size = cc.sizeof('ssize_t', prefix : '#include <unistd.h>')
1410 # Some platforms (Apple) hard-code int64_t to long long instead of
1411 # using long on 64-bit architectures. This can cause type mismatch
1412 # warnings when trying to interface with code using the standard
1413 # library type. Test for the warnings and set gint64 to whichever
1415 if long_long_size == long_size
1416 if cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1417 #pragma options langlvl=stdc99
1419 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1426 }''', name : 'int64_t is long')
1427 int64_t_typedef = 'long'
1428 elif cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1429 #pragma options langlvl=stdc99
1431 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1436 long long *i2 = &i1;
1438 }''', name : 'int64_t is long long')
1439 int64_t_typedef = 'long long'
1444 char_align = cc.alignment('char')
1445 short_align = cc.alignment('short')
1446 int_align = cc.alignment('int')
1447 voidp_align = cc.alignment('void*')
1448 long_align = cc.alignment('long')
1449 long_long_align = cc.alignment('long long')
1450 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1451 # be 64-bit in C99, and it is available on all supported compilers
1452 sizet_align = cc.alignment('size_t')
1454 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1456 glib_conf.set('SIZEOF_CHAR', char_size)
1457 glib_conf.set('SIZEOF_INT', int_size)
1458 glib_conf.set('SIZEOF_SHORT', short_size)
1459 glib_conf.set('SIZEOF_LONG', long_size)
1460 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1461 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1462 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1463 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1464 glib_conf.set('SIZEOF_WCHAR_T', cc.sizeof('wchar_t', prefix: '#include <stddef.h>'))
1477 error('Compiler provides no native 16-bit integer type')
1479 glibconfig_conf.set('gint16', gint16)
1480 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1481 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1482 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1489 guint32_align = short_align
1495 guint32_align = int_align
1501 guint32_align = long_align
1503 error('Compiler provides no native 32-bit integer type')
1505 glibconfig_conf.set('gint32', gint32)
1506 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1507 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1508 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1509 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1517 gint64_constant='(val)'
1518 guint64_constant='(val)'
1519 guint64_align = int_align
1520 elif long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long')
1526 gint64_constant='(val##L)'
1527 guint64_constant='(val##UL)'
1528 guint64_align = long_align
1529 elif long_long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long long')
1530 gint64 = 'long long'
1531 glib_extension='G_GNUC_EXTENSION '
1532 gint64_modifier=int64_m
1533 gint64_format=int64_m + 'i'
1534 guint64_format=int64_m + 'u'
1535 gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1536 guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1537 guint64_align = long_long_align
1539 error('Compiler provides no native 64-bit integer type')
1541 glibconfig_conf.set('glib_extension', glib_extension)
1542 glibconfig_conf.set('gint64', gint64)
1543 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1544 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1545 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1546 glibconfig_conf.set('gint64_constant', gint64_constant)
1547 glibconfig_conf.set('guint64_constant', guint64_constant)
1548 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1550 if host_system == 'windows'
1551 glibconfig_conf.set('g_pid_type', 'void*')
1552 glibconfig_conf.set_quoted('g_pid_format', 'p')
1553 if host_machine.cpu_family() == 'x86_64'
1554 glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1556 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1558 glibconfig_conf.set('g_dir_separator', '\\\\')
1559 glibconfig_conf.set('g_searchpath_separator', ';')
1561 glibconfig_conf.set('g_pid_type', 'int')
1562 glibconfig_conf.set_quoted('g_pid_format', 'i')
1563 glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1564 glibconfig_conf.set('g_dir_separator', '/')
1565 glibconfig_conf.set('g_searchpath_separator', ':')
1568 g_sizet_compatibility = {
1569 'short': sizet_size == short_size,
1570 'int': sizet_size == int_size,
1571 'long': sizet_size == long_size,
1572 'long long': sizet_size == long_long_size,
1575 # Do separate checks for gcc/clang (and ignore other compilers for now), since
1576 # we need to explicitly pass -Werror to the compilers.
1577 # FIXME: https://github.com/mesonbuild/meson/issues/5399
1578 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
1579 foreach type_name, size_compatibility : g_sizet_compatibility
1580 g_sizet_compatibility += { type_name: size_compatibility and
1582 '''#include <stddef.h>
1583 size_t f (size_t *i) { return *i + 1; }
1585 unsigned ''' + type_name + ''' i = 0;
1590 name : 'GCC size_t typedef is ' + type_name), }
1594 if g_sizet_compatibility['short']
1595 glibconfig_conf.set('glib_size_type_define', 'short')
1596 glibconfig_conf.set_quoted('gsize_modifier', 'h')
1597 glibconfig_conf.set_quoted('gssize_modifier', 'h')
1598 glibconfig_conf.set_quoted('gsize_format', 'hu')
1599 glibconfig_conf.set_quoted('gssize_format', 'hi')
1600 glibconfig_conf.set('glib_msize_type', 'SHRT')
1601 elif g_sizet_compatibility['int']
1602 glibconfig_conf.set('glib_size_type_define', 'int')
1603 glibconfig_conf.set_quoted('gsize_modifier', '')
1604 glibconfig_conf.set_quoted('gssize_modifier', '')
1605 glibconfig_conf.set_quoted('gsize_format', 'u')
1606 glibconfig_conf.set_quoted('gssize_format', 'i')
1607 glibconfig_conf.set('glib_msize_type', 'INT')
1608 elif g_sizet_compatibility['long']
1609 glibconfig_conf.set('glib_size_type_define', 'long')
1610 glibconfig_conf.set_quoted('gsize_modifier', 'l')
1611 glibconfig_conf.set_quoted('gssize_modifier', 'l')
1612 glibconfig_conf.set_quoted('gsize_format', 'lu')
1613 glibconfig_conf.set_quoted('gssize_format', 'li')
1614 glibconfig_conf.set('glib_msize_type', 'LONG')
1615 elif g_sizet_compatibility['long long']
1616 glibconfig_conf.set('glib_size_type_define', 'long long')
1617 glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1618 glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1619 glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1620 glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1621 glibconfig_conf.set('glib_msize_type', 'INT64')
1623 error('Could not determine size of size_t.')
1626 if voidp_size == int_size
1627 glibconfig_conf.set('glib_intptr_type_define', 'int')
1628 glibconfig_conf.set_quoted('gintptr_modifier', '')
1629 glibconfig_conf.set_quoted('gintptr_format', 'i')
1630 glibconfig_conf.set_quoted('guintptr_format', 'u')
1631 glibconfig_conf.set('glib_gpi_cast', '(gint)')
1632 glibconfig_conf.set('glib_gpui_cast', '(guint)')
1633 elif voidp_size == long_size
1634 glibconfig_conf.set('glib_intptr_type_define', 'long')
1635 glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1636 glibconfig_conf.set_quoted('gintptr_format', 'li')
1637 glibconfig_conf.set_quoted('guintptr_format', 'lu')
1638 glibconfig_conf.set('glib_gpi_cast', '(glong)')
1639 glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1640 elif voidp_size == long_long_size
1641 glibconfig_conf.set('glib_intptr_type_define', 'long long')
1642 glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1643 glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1644 glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1645 glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1646 glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1648 error('Could not determine size of void *')
1651 if long_size != 8 and long_long_size != 8 and int_size != 8
1652 error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1655 glibconfig_conf.set('gintbits', int_size * 8)
1656 glibconfig_conf.set('glongbits', long_size * 8)
1657 glibconfig_conf.set('gsizebits', sizet_size * 8)
1658 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1660 # XXX: https://gitlab.gnome.org/GNOME/glib/issues/1413
1661 if host_system == 'windows'
1662 g_module_suffix = 'dll'
1664 g_module_suffix = 'so'
1666 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1668 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1669 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1670 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1671 glibconfig_conf.set('GLIB_VERSION', glib_version)
1673 glibconfig_conf.set('glib_void_p', voidp_size)
1674 glibconfig_conf.set('glib_long', long_size)
1675 glibconfig_conf.set('glib_size_t', sizet_size)
1676 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1677 if host_machine.endian() == 'big'
1678 glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1679 glibconfig_conf.set('g_bs_native', 'BE')
1680 glibconfig_conf.set('g_bs_alien', 'LE')
1682 glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1683 glibconfig_conf.set('g_bs_native', 'LE')
1684 glibconfig_conf.set('g_bs_alien', 'BE')
1687 # === va_copy checks ===
1688 # we currently check for all three va_copy possibilities, so we get
1689 # all results in config.log for bug reports.
1692 foreach try_func : [ '__va_copy', 'va_copy' ]
1693 if cc.compiles('''#include <stdarg.h>
1696 # include "msvc_recommended_pragmas.h"
1698 void f (int i, ...) {
1699 va_list args1, args2;
1700 va_start (args1, i);
1702 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1704 va_end (args1); va_end (args2);
1709 }'''.format(try_func),
1710 name : try_func + ' check')
1711 va_copy_func = try_func
1714 if va_copy_func != ''
1715 glib_conf.set('G_VA_COPY', va_copy_func)
1716 glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1718 glib_vacopy = '/* #undef G_VA_COPY */'
1721 va_list_val_copy_prog = '''
1724 void f (int i, ...) {
1725 va_list args1, args2;
1726 va_start (args1, i);
1728 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1730 va_end (args1); va_end (args2);
1738 rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1739 glib_va_val_copy = rres.compiled() and rres.returncode() == 0
1741 glib_va_val_copy = meson.get_external_property('va_val_copy', true)
1743 if not glib_va_val_copy
1744 glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1745 glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1747 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1749 # check for flavours of varargs macros
1750 g_have_iso_c_varargs = cc.compiles('''
1751 void some_func (void) {
1752 int a(int p1, int p2, int p3);
1753 #define call_a(...) a(1,__VA_ARGS__)
1755 }''', name : 'ISO C99 varargs macros in C')
1757 if not g_have_iso_c_varargs
1758 error('GLib requires a C compiler with support for C99 __VA_ARG__ in macros.')
1762 g_have_iso_cxx_varargs = cxx.compiles('''
1763 void some_func (void) {
1764 int a(int p1, int p2, int p3);
1765 #define call_a(...) a(1,__VA_ARGS__)
1767 }''', name : 'ISO C99 varargs macros in C++')
1769 if not g_have_iso_cxx_varargs
1770 error('GLib requires a C++ compiler with support for C99 __VA_ARG__ in macros.')
1774 g_have_gnuc_varargs = cc.compiles('''
1775 void some_func (void) {
1776 int a(int p1, int p2, int p3);
1777 #define call_a(params...) a(1,params)
1779 }''', name : 'GNUC varargs macros')
1781 if cc.has_header('alloca.h')
1782 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1784 has_syspoll = cc.has_header('sys/poll.h')
1785 has_systypes = cc.has_header('sys/types.h')
1787 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1789 has_winsock2 = cc.has_header('winsock2.h')
1791 if has_syspoll and has_systypes
1793 #include<sys/poll.h>
1794 #include<sys/types.h>'''
1797 #define _WIN32_WINNT @0@
1798 #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1801 error('FIX POLL* defines')
1805 [ 'POLLIN', 'g_pollin', 1 ],
1806 [ 'POLLOUT', 'g_pollout', 4 ],
1807 [ 'POLLPRI', 'g_pollpri', 2 ],
1808 [ 'POLLERR', 'g_pollerr', 8 ],
1809 [ 'POLLHUP', 'g_pollhup', 16 ],
1810 [ 'POLLNVAL', 'g_pollnval', 32 ],
1813 if has_syspoll and has_systypes
1814 foreach d : poll_defines
1815 val = cc.compute_int(d[0], prefix: poll_includes)
1816 glibconfig_conf.set(d[1], val)
1819 # Due to a missed bug in configure.ac the poll test
1820 # never succeeded on Windows and used some pre-defined
1821 # values as a fallback. Keep using them to maintain
1822 # ABI compatibility with autotools builds of glibs
1823 # and with *any* glib-using code compiled against them,
1824 # since these values end up in a public header glibconfig.h.
1825 foreach d : poll_defines
1826 glibconfig_conf.set(d[1], d[2])
1830 # Internet address families
1831 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1832 if host_system == 'windows'
1834 #include <winsock2.h>'''
1837 #include <sys/types.h>
1838 #include <sys/socket.h>'''
1842 [ 'AF_UNIX', 'g_af_unix' ],
1843 [ 'AF_INET', 'g_af_inet' ],
1844 [ 'AF_INET6', 'g_af_inet6' ],
1845 [ 'MSG_OOB', 'g_msg_oob' ],
1846 [ 'MSG_PEEK', 'g_msg_peek' ],
1847 [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1849 foreach d : inet_defines
1850 val = cc.compute_int(d[0], prefix: inet_includes)
1851 glibconfig_conf.set(d[1], val)
1854 if host_system == 'windows'
1857 have_ipv6 = cc.has_type('struct in6_addr', prefix: '#include <netinet/in.h>')
1859 glib_conf.set('HAVE_IPV6', have_ipv6)
1861 # We need to decide at configure time if GLib will use real atomic
1862 # operations ("lock free") or emulated ones with a mutex. This is
1863 # because we must put this information in glibconfig.h so we know if
1864 # it is safe or not to inline using compiler intrinsics directly from
1867 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1868 # user is interested in knowing if they can use the atomic ops across
1871 # We can currently support the atomic ops natively when building GLib
1872 # with recent versions of GCC or MSVC.
1874 # Note that the atomic ops are only available with GCC on x86 when
1875 # using -march=i486 or higher. If we detect that the atomic ops are
1876 # not available but would be available given the right flags, we want
1877 # to abort and advise the user to fix their CFLAGS. It's better to do
1878 # that then to silently fall back on emulated atomic ops just because
1879 # the user had the wrong build environment.
1880 atomictest = '''int main() {
1882 __sync_bool_compare_and_swap (&atomic, 2, 3);
1888 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1889 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1893 # We know that we can always use real ("lock free") atomic operations with MSVC
1894 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' or cc.links(atomictest, name : 'atomic ops')
1895 have_atomic_lock_free = true
1896 if cc.get_id() == 'gcc' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1897 # Old gcc release may provide
1898 # __sync_bool_compare_and_swap but doesn't define
1899 # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1900 glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1903 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
1904 sync_swap_test = '''
1907 __sync_swap (&atomic, 2);
1912 glib_conf.set('_GLIB_GCC_HAVE_SYNC_SWAP', cc.links(sync_swap_test, name : 'sync swap'))
1915 have_atomic_lock_free = false
1916 if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1917 error('GLib must be built with -march=i486 or later.')
1920 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1924 if get_option('force_posix_threads')
1925 warning('DEPRECATION: Option \'force_posix_threads\' is deprecated and will be removed after GLib 2.72; please file an issue with your use case if you still require it')
1928 # Determination of thread implementation
1929 if host_system == 'windows' and not get_option('force_posix_threads')
1931 threads_implementation = 'win32'
1932 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1933 glib_conf.set('THREADS_WIN32', 1)
1935 thread_dep = dependency('threads')
1936 threads_implementation = 'posix'
1937 pthread_prefix = '''
1939 # define _GNU_SOURCE
1941 #include <pthread.h>'''
1942 glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1943 glib_conf.set('THREADS_POSIX', 1)
1944 if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1945 glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1947 if cc.has_header_symbol('pthread.h', 'pthread_attr_setinheritsched')
1948 glib_conf.set('HAVE_PTHREAD_ATTR_SETINHERITSCHED', 1)
1950 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1951 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1953 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1954 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1956 if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1957 glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1960 if cc.has_header_symbol('sys/syscall.h', 'SYS_sched_getattr')
1961 glib_conf.set('HAVE_SYS_SCHED_GETATTR', 1)
1964 # Assume that pthread_setname_np is available in some form; same as configure
1965 if cc.links(pthread_prefix + '''
1967 pthread_setname_np("example");
1970 name : 'pthread_setname_np(const char*)',
1971 dependencies : thread_dep)
1973 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1974 elif cc.links(pthread_prefix + '''
1976 pthread_setname_np(pthread_self(), "example");
1979 name : 'pthread_setname_np(pthread_t, const char*)',
1980 dependencies : thread_dep)
1981 # Linux, Solaris, etc.
1982 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1983 elif cc.links(pthread_prefix + '''
1985 pthread_setname_np(pthread_self(), "%s", "example");
1988 name : 'pthread_setname_np(pthread_t, const char*, void*)',
1989 dependencies : thread_dep)
1991 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG', 1)
1992 elif cc.links(pthread_prefix + '''
1993 #include <pthread_np.h>
1995 pthread_set_name_np(pthread_self(), "example");
1998 name : 'pthread_set_name_np(pthread_t, const char*)',
1999 dependencies : thread_dep)
2000 # FreeBSD, DragonFlyBSD, OpenBSD, etc.
2001 glib_conf.set('HAVE_PTHREAD_SET_NAME_NP', 1)
2005 # FIXME: we should make it print the result and always return 0, so that
2006 # the output in meson shows up as green
2007 # volatile is needed here to avoid optimisations in the test
2008 stack_grows_check_prog = '''
2009 volatile int *a = 0, *b = 0;
2021 return b > a ? 0 : 1;
2025 rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
2026 growing_stack = rres.compiled() and rres.returncode() == 0
2028 growing_stack = meson.get_external_property('growing_stack', false)
2031 glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack)
2035 # We should never use the MinGW C library's iconv because it may not be
2036 # available in the actual runtime environment. On Windows, we always use
2037 # the built-in implementation
2038 if host_system == 'windows'
2039 # We have a #include "win_iconv.c" in gconvert.c on Windows, so we don't need
2040 # any external library for it
2043 libiconv = dependency('iconv')
2046 pcre2 = dependency('libpcre2-8', version: '>= 10.32', required : false)
2047 if not pcre2.found()
2048 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
2049 # MSVC: Search for the PCRE2 library by the configuration, which corresponds
2050 # to the output of CMake builds of PCRE2. Note that debugoptimized
2051 # is really a Release build with .PDB files.
2052 if vs_crt == 'debug'
2053 pcre2 = cc.find_library('pcre2d-8', required : false)
2055 pcre2 = cc.find_library('pcre2-8', required : false)
2060 # Try again with the fallback
2061 if not pcre2.found()
2062 pcre2 = dependency('libpcre2-8', required : true, fallback : ['pcre2', 'libpcre2_8'])
2063 use_pcre2_static_flag = true
2064 elif host_system == 'windows'
2065 pcre2_static = cc.links('''#define PCRE2_STATIC
2066 #define PCRE2_CODE_UNIT_WIDTH 8
2073 dependencies: pcre2,
2074 name : 'Windows system PCRE2 is a static build')
2075 use_pcre2_static_flag = pcre2_static
2077 use_pcre2_static_flag = false
2080 # Import the gvdb sources as a subproject to avoid having the copylib in-tree
2082 gvdb_dep = dependency('gvdb')
2084 libm = cc.find_library('m', required : false)
2085 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
2087 libz_dep = dependency('zlib')
2089 # First check in libc, fallback to libintl, and as last chance build
2090 # proxy-libintl subproject.
2091 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
2092 # implementations. This could be extended if issues are found in some platforms.
2094 libintl = dependency('intl', required: false)
2096 # libintl supports different threading APIs, which may not
2097 # require additional flags, but it defaults to using pthreads if
2098 # found. Meson's "threads" dependency does not allow you to
2099 # prefer pthreads. We may not be using pthreads for glib itself
2100 # either so just link the library to satisfy libintl rather than
2101 # also defining the macros with the -pthread flag.
2103 # Meson's builtin dependency lookup as of 0.60.0 doesn't check for
2104 # pthread, so we do this manually here.
2105 if cc.has_function('ngettext', dependencies : libintl)
2106 libintl_deps += [libintl]
2108 libintl_pthread = cc.find_library('pthread', required : false)
2109 if libintl_pthread.found() and cc.has_function('ngettext', dependencies : [libintl, libintl_pthread])
2110 libintl_deps += [libintl, libintl_pthread]
2112 libintl = disabler()
2118 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset', dependencies: libintl_deps)
2120 libintl = subproject('proxy-libintl').get_variable('intl_dep')
2121 libintl_deps = [libintl]
2122 have_bind_textdomain_codeset = true # proxy-libintl supports it
2125 glib_conf.set('HAVE_BIND_TEXTDOMAIN_CODESET', have_bind_textdomain_codeset)
2127 # We require gettext to always be present
2128 glib_conf.set('HAVE_DCGETTEXT', 1)
2129 glib_conf.set('HAVE_GETTEXT', 1)
2131 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
2133 # libmount is only used by gio, but we need to fetch the libs to generate the
2134 # pkg-config file below
2136 if host_system == 'linux'
2137 libmount_dep = dependency('mount', version : '>=2.23', required : get_option('libmount'))
2138 glib_conf.set('HAVE_LIBMOUNT', libmount_dep.found())
2141 if host_system == 'windows'
2142 winsock2 = cc.find_library('ws2_32')
2144 winsock2 = not_found
2148 if host_system == 'linux'
2149 selinux_dep = dependency('libselinux', version: '>=2.2', required: get_option('selinux'))
2151 glib_conf.set('HAVE_SELINUX', selinux_dep.found())
2155 if host_system != 'windows' and get_option('xattr')
2156 # either glibc or libattr can provide xattr support
2157 # for both of them, we check for getxattr being in
2158 # the library and a valid xattr header.
2161 if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
2162 glib_conf.set('HAVE_SYS_XATTR_H', 1)
2163 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
2164 #failure. try libattr
2165 elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
2166 glib_conf.set('HAVE_ATTR_XATTR_H', 1)
2167 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
2168 xattr_dep = [cc.find_library('xattr')]
2170 error('No getxattr implementation found in C library or libxattr')
2173 glib_conf.set('HAVE_XATTR', 1)
2174 if cc.compiles(glib_conf_prefix + '''
2176 #ifdef HAVE_SYS_TYPES_H
2177 #include <sys/types.h>
2179 #ifdef HAVE_SYS_XATTR_H
2180 #include <sys/xattr.h>
2181 #elif HAVE_ATTR_XATTR_H
2182 #include <attr/xattr.h>
2186 ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
2189 name : 'XATTR_NOFOLLOW')
2190 glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
2194 # If strlcpy is present (BSD and similar), check that it conforms to the BSD
2195 # specification. Specifically Solaris 8's strlcpy() does not, see
2196 # https://bugzilla.gnome.org/show_bug.cgi?id=53933 for further context.
2197 if cc.has_function('strlcpy')
2199 rres = cc.run('''#include <stdlib.h>
2203 (void) strlcpy (p, "hi", 10);
2204 if (strlcat (p, "bye", 0) != 3)
2208 name : 'OpenBSD strlcpy/strlcat')
2209 if rres.compiled() and rres.returncode() == 0
2210 glib_conf.set('HAVE_STRLCPY', 1)
2212 elif meson.get_external_property('have_strlcpy', false)
2213 glib_conf.set('HAVE_STRLCPY', 1)
2217 cmdline_test_code = '''
2219 #include <sys/stat.h>
2227 /* This code is a dumbed-down version of g_file_get_contents() */
2231 #define BUFSIZE 1024
2232 char result[BUFSIZE];
2233 struct stat stat_buf;
2235 int fd = open ("/proc/self/cmdline", O_RDONLY|O_BINARY);
2238 if (fstat (fd, &stat_buf))
2241 if (stat_buf.st_size > 0 && S_ISREG (stat_buf.st_mode))
2243 if (read (fd, result, BUFSIZE) <= 0)
2248 FILE *f = fdopen (fd, "r");
2252 if (fread (result, 1, BUFSIZE, f) <= 0)
2262 exit (__getcmdline ());
2266 rres = cc.run(cmdline_test_code, name : '/proc/self/cmdline')
2267 have_proc_self_cmdline = rres.compiled() and rres.returncode() == 0
2269 have_proc_self_cmdline = meson.get_external_property('have_proc_self_cmdline', false)
2272 glib_conf.set('HAVE_PROC_SELF_CMDLINE', have_proc_self_cmdline)
2274 python = import('python').find_installation('python3')
2275 # used for '#!/usr/bin/env <name>'
2276 python_name = 'python3'
2278 python_version = python.language_version()
2279 python_version_req = '>=3.5'
2280 if not python_version.version_compare(python_version_req)
2281 error('Requires Python @0@, @1@ found.'.format(python_version_req, python_version))
2284 # Determine which user environment-dependent files that we want to install
2285 have_bash = find_program('bash', required : false).found() # For completion scripts
2286 bash_comp_dep = dependency('bash-completion', version: '>=2.0', required: false)
2287 have_sh = find_program('sh', required : false).found() # For glib-gettextize
2289 # Some installed tests require a custom environment
2290 env_program = find_program('env', required: installed_tests_enabled)
2292 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
2293 if host_system == 'sunos'
2294 glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
2295 glib_conf.set('_XOPEN_SOURCE', 2)
2296 glib_conf.set('__EXTENSIONS__',1)
2299 # Sadly Meson does not expose this value:
2300 # https://github.com/mesonbuild/meson/pull/3460
2301 if host_system == 'windows'
2302 # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
2303 # with no explanation. Do the same here for now but this could be revisited if
2305 export_dynamic_ldflags = []
2306 elif host_system == 'cygwin'
2307 export_dynamic_ldflags = ['-Wl,--export-all-symbols']
2308 elif host_system in ['darwin', 'ios']
2309 export_dynamic_ldflags = []
2310 elif host_system == 'sunos'
2311 export_dynamic_ldflags = []
2313 export_dynamic_ldflags = ['-Wl,--export-dynamic']
2318 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
2319 # Ensure MSVC-compatible struct packing convention is used when
2320 # compiling for Win32 with gcc. It is used for the whole project and exposed
2322 win32_cflags = ['-mms-bitfields']
2323 add_project_arguments(win32_cflags, language : 'c')
2325 # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
2326 win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi', '-luuid']
2327 elif host_system == 'cygwin'
2328 win32_ldflags = ['-luser32', '-lkernel32']
2332 want_dtrace = get_option('dtrace')
2333 enable_dtrace = false
2335 # Since dtrace support is opt-in we just error out if it was requested but
2336 # is not available. We don't bother with autodetection yet.
2339 error('GLib dtrace support not yet compatible with macOS dtrace')
2341 dtrace = find_program('dtrace', required : true) # error out if not found
2342 if not cc.has_header('sys/sdt.h')
2343 error('dtrace support needs sys/sdt.h header')
2345 # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
2346 dtrace_obj_gen = generator(dtrace,
2347 output : '@BASENAME@.o',
2348 arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2349 # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
2350 # -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
2351 dtrace_hdr_gen = generator(dtrace,
2352 output : '@BASENAME@.h',
2353 arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2354 glib_conf.set('HAVE_DTRACE', 1)
2355 enable_dtrace = true
2359 want_systemtap = get_option('systemtap')
2360 enable_systemtap = false
2362 if want_systemtap and enable_dtrace
2363 tapset_install_dir = get_option('tapset_install_dir')
2364 if tapset_install_dir == ''
2365 tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
2367 stp_cdata = configuration_data()
2368 stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
2369 stp_cdata.set('LT_CURRENT', minor_version * 100)
2370 stp_cdata.set('LT_REVISION', micro_version)
2371 enable_systemtap = true
2375 test_timeout_slow = 180
2377 pkg = import('pkgconfig')
2378 windows = import('windows')
2387 # xgettext is optional (on Windows for instance)
2388 if find_program('xgettext', required : get_option('nls')).found()
2392 # Install m4 macros that other projects use
2393 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
2394 install_dir : join_paths(get_option('datadir'), 'aclocal'))
2396 configure_file(output : 'config.h', configuration : glib_conf)
2398 if host_system == 'windows'
2399 install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
2402 if get_option('man')
2403 xsltproc = find_program('xsltproc', required : true)
2404 xsltproc_command = [
2407 '--stringparam', 'man.output.quietly', '1',
2408 '--stringparam', 'funcsynopsis.style', 'ansi',
2409 '--stringparam', 'man.th.extra1.suppress', '1',
2410 '--stringparam', 'man.authors.section.enabled', '0',
2411 '--stringparam', 'man.copyright.section.enabled', '0',
2413 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
2416 man1_dir = join_paths(glib_prefix, get_option('mandir'), 'man1')
2419 gnome = import('gnome')
2420 subdir('docs/reference')