3 # NOTE: See the policy in docs/meson-version.md before changing the Meson dependency
4 meson_version : '>= 1.2.0',
6 'buildtype=debugoptimized',
14 cc = meson.get_compiler('c')
17 foreach std : ['90', '99', '11', '17']
18 arg = (cc.get_id() == 'msvc' ? '/std:' : '-std=') + 'c' + std
19 if cc.has_argument(arg)
20 c_standards += { std: arg }
24 have_cxx = add_languages('cpp', native: false, required: get_option('oss_fuzz').enabled())
26 cxx = meson.get_compiler('cpp')
29 foreach std : ['98', '03', '11', '14', '17', '20', '2b', 'latest']
30 arg = (cxx.get_id() == 'msvc' ? '/std:' : '-std=') + 'c++' + std
31 if cxx.has_argument(arg)
32 cxx_standards += { std: arg }
37 cc_can_run = meson.can_run_host_binaries()
39 if cc.get_argument_syntax() == 'msvc'
40 # Ignore several spurious warnings for things glib does very commonly
42 add_project_arguments('/FIglib/msvc_recommended_pragmas.h', language : 'c')
45 if cc.get_id() == 'msvc'
46 # Set the input and exec encoding to utf-8, like is the default with GCC
47 add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c')
48 # Disable SAFESEH with MSVC for plugins and libs that use external deps that
49 # are built with MinGW
50 noseh_link_args = ['/SAFESEH:NO']
53 # -mms-bitfields vs -fnative-struct ?
56 host_system = host_machine.system()
58 if host_system == 'darwin'
59 ios_test_code = '''#include <TargetConditionals.h>
60 #if ! TARGET_OS_IPHONE
61 #error "Not iOS/tvOS/watchOS/iPhoneSimulator"
63 if cc.compiles(ios_test_code, name : 'building for iOS')
69 if host_system == 'linux'
70 musl_test_code = '''#include <stdlib.h>
71 #if defined __GLIBC__ || defined __UCLIBC__
72 #error "Not in glibc or uclibc"
74 if cc.compiles(musl_test_code, name : 'building for musl libc')
79 glib_version = meson.project_version()
80 glib_api_version = '2.0'
81 version_arr = glib_version.split('.')
82 major_version = version_arr[0].to_int()
83 minor_version = version_arr[1].to_int()
84 micro_version = version_arr[2].to_int()
86 interface_age = minor_version.is_odd() ? 0 : micro_version
87 binary_age = 100 * minor_version + micro_version
90 # Maintain compatibility with previous libtool versioning
91 # current = minor * 100 + micro
92 current = binary_age - interface_age
93 library_version = '@0@.@1@.@2@'.format(soversion, current, interface_age)
94 darwin_versions = [current + 1, '@0@.@1@'.format(current + 1, interface_age)]
96 configinc = include_directories('.')
97 glibinc = include_directories('glib')
98 gobjectinc = include_directories('gobject')
99 gmoduleinc = include_directories('gmodule')
100 gioinc = include_directories('gio')
101 girepoinc = include_directories('girepository')
103 glib_prefix = get_option('prefix')
104 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
105 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
106 glib_libexecdir = join_paths(glib_prefix, get_option('libexecdir'))
107 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
108 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
109 glib_includedir = join_paths(glib_prefix, get_option('includedir'), 'glib-2.0')
110 if get_option('gio_module_dir') != ''
111 glib_giomodulesdir = join_paths(glib_prefix, get_option('gio_module_dir'))
113 glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
116 if get_option('multiarch')
117 # For multiarch/multilib distributions, install each architecture's
118 # build of executables used in packaging triggers (like gio-querymodules)
119 # to an architecture-dependent location, with a compatibility symlink
121 multiarch_bindir = get_option('libdir') / 'glib-2.0'
122 multiarch_libexecdir = multiarch_bindir
123 pkgconfig_multiarch_bindir = '${libdir}/glib-2.0'
125 # For single-architecture distributions, just install them into the PATH
126 # as was traditionally done.
127 multiarch_bindir = get_option('bindir')
128 multiarch_libexecdir = get_option('libexecdir')
129 pkgconfig_multiarch_bindir = '${bindir}'
132 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
134 if get_option('charsetalias_dir') != ''
135 glib_charsetaliasdir = join_paths(glib_prefix, get_option('charsetalias_dir'))
137 glib_charsetaliasdir = glib_libdir
140 glib_localstatedir = glib_prefix / get_option('localstatedir')
142 if get_option('runtime_dir') != ''
143 glib_runstatedir = glib_prefix / get_option('runtime_dir')
145 # While we’d normally prefix directories like this with, for example,
146 # glib_localstatedir, `/run` is a bit different in that it’s for runtime state
147 # rather than data files, so it’s typically functionally useless to use a
148 # prefixed version. No other processes will be using it. So we default to the
149 # unprefixed system `/run` directory.
150 glib_runstatedir = '/run'
153 # When building glib and gobject-introspection with subprojects, gobject-introspection
154 # requires to know the path of the sources and the build directory for the subproject.
155 # We provide it here with a variable.
156 glib_source_dir = meson.current_source_dir()
157 glib_build_dir = meson.current_build_dir()
159 installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
160 installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
161 installed_tests_enabled = get_option('installed_tests')
162 installed_tests_template = files('tests/template.test.in')
163 installed_tests_template_tap = files('tests/template-tap.test.in')
165 # Don’t build the tests unless we can run them (either natively, in an exe wrapper, or by installing them for later use)
166 build_tests = get_option('tests') and (meson.can_run_host_binaries() or installed_tests_enabled)
169 'G_DEBUG=gc-friendly',
170 'G_ENABLE_DIAGNOSTIC=1',
174 if get_option('werror')
175 common_test_env += 'LINT_WARNINGS_ARE_ERRORS=1'
178 # Note: this may cause the tests output not to be printed when running in
179 # verbose mode, see https://github.com/mesonbuild/meson/issues/11185
180 # Can be changed it to 'exitcode' if required during development.
181 test_protocol = 'tap'
183 test_timeout_slow = 90
185 add_test_setup('default',
187 exclude_suites: ['flaky', 'failing'],
188 env: common_test_env,
189 timeout_multiplier: 2,
192 add_test_setup('unstable_tests',
193 env: common_test_env,
194 timeout_multiplier: 2,
195 # Empty test setup, used for having different results set for flaky tests
196 # Sadly we can't use (https://github.com/mesonbuild/meson/issues/10934):
197 #suites: ['flaky', 'unstable']
200 add_test_setup('thorough',
201 exclude_suites: ['flaky', 'failing', 'performance'],
202 env: common_test_env,
203 timeout_multiplier: 20,
204 exe_wrapper: [find_program('./.gitlab-ci/thorough-test-wrapper.sh', required: true)],
207 # Allow the tests to be easily run under valgrind using --setup=valgrind
208 valgrind = find_program('valgrind', required: false)
209 valgrind_suppression_file = files('tools' / 'glib.supp')[0]
210 valgrind_suppression_file_install_subdir = 'glib-2.0' / 'valgrind'
213 add_test_setup('valgrind',
214 exclude_suites: [ 'no-valgrind', 'flaky' ],
218 '--error-exitcode=1',
219 '--track-origins=yes',
221 '--leak-resolution=high',
223 '--show-leak-kinds=definite,possible',
224 '--show-error-list=yes',
225 '--suppressions=@0@'.format(meson.project_source_root() /
226 '@0@'.format(valgrind_suppression_file)),
228 env: common_test_env,
229 timeout_multiplier: 20,
233 add_project_arguments('-D_GNU_SOURCE', language: 'c')
235 if host_system == 'qnx'
236 add_project_arguments('-D_QNX_SOURCE', language: 'c')
239 if host_system == 'windows'
240 add_project_arguments(['-DUNICODE', '-D_UNICODE'], language: 'c')
243 # Disable strict aliasing;
244 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
245 if cc.has_argument('-fno-strict-aliasing')
246 add_project_arguments('-fno-strict-aliasing', language: 'c')
249 # dummy/empty dependency() object to declare fallbacks and simpler dependencies
250 not_found = dependency('', required: false)
252 ########################
253 # Configuration begins #
254 ########################
255 glib_conf = configuration_data()
256 glibconfig_conf = configuration_data()
258 # accumulated list of defines as we check for them, so we can easily
259 # use them later in test programs (autoconf does this automatically)
260 glib_conf_prefix = ''
262 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
263 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
264 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
265 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
266 glib_conf.set('GLIB_BINARY_AGE', binary_age)
267 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
268 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
269 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
270 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
271 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
272 glib_conf.set_quoted('PACKAGE_URL', '')
273 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
274 glib_conf.set('ENABLE_NLS', 1)
276 # used by the .rc.in files
277 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
279 glib_conf.set('_GNU_SOURCE', 1)
281 if host_system in ['windows', 'darwin']
282 # Poll doesn't work on devices on Windows, and macOS's poll() implementation is known to be broken
283 glib_conf.set('BROKEN_POLL', true)
286 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
287 # FIXME: Ideally we shouldn't depend on this on Windows and should use
288 # 64 bit capable Windows API that also works with MSVC.
289 # The autotools build did set this for mingw and while meson sets it
290 # for gcc/clang by default, it doesn't do so on Windows.
291 glib_conf.set('_FILE_OFFSET_BITS', 64)
294 glib_build_shared = false
295 glib_build_static = false
296 if get_option('default_library') == 'both'
297 glib_build_static = true
298 glib_build_shared = true
299 elif get_option('default_library') == 'static'
300 glib_build_static = true
301 elif get_option('default_library') == 'shared'
302 glib_build_shared = true
305 glib_build_both = glib_build_static and glib_build_shared
306 glib_build_static_only = glib_build_static and not glib_build_shared
307 glib_build_shared_only = glib_build_shared and not glib_build_static
309 if glib_build_shared and glib_build_static and (
310 host_system == 'windows' or host_system == 'cygwin')
311 error('On Windows default_library must be "shared" or "static" but not "both"')
314 if glib_build_static_only
315 glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
316 glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
317 glibconfig_conf.set('GIO_STATIC_COMPILATION', '1')
318 glibconfig_conf.set('GMODULE_STATIC_COMPILATION', '1')
319 glibconfig_conf.set('GI_STATIC_COMPILATION', '1')
320 glibconfig_conf.set('G_INTL_STATIC_COMPILATION', '1')
321 glibconfig_conf.set('FFI_STATIC_BUILD', '1')
324 # Cygwin glib port maintainers made it clear
325 # (via the patches they apply) that they want no
326 # part of glib W32 code, therefore we do not define
327 # G_PLATFORM_WIN32 for host_system == 'cygwin'.
328 # This makes G_PLATFORM_WIN32 a synonym for
330 if host_system == 'windows'
331 glib_os = '''#define G_OS_WIN32
332 #define G_PLATFORM_WIN32'''
333 elif host_system == 'cygwin'
334 glib_os = '''#define G_OS_UNIX
335 #define G_WITH_CYGWIN'''
337 glib_os = '#define G_OS_UNIX'
339 glibconfig_conf.set('glib_os', glib_os)
341 # We need to know the CRT being used to determine what .lib files we need on
342 # Visual Studio for dependencies that don't normally come with pkg-config files
344 vs_crt_opt = get_option('b_vscrt')
345 if vs_crt_opt in ['mdd', 'mtd']
347 elif vs_crt_opt == 'from_buildtype'
348 if get_option('buildtype') == 'debug'
353 # Use debug/optimization flags to determine whether to enable debug or disable
354 # cast checks. We have a non-production (debug) build if debug is true and if
355 # optimization is 0 or g; otherwise, we have a production build.
356 glib_debug_cflags = []
357 glib_debug = get_option('glib_debug')
358 if (glib_debug.enabled() or (
359 glib_debug.auto() and get_option('debug') and get_option('optimization') in [ '0', 'g' ]))
360 glib_debug_cflags += ['-DG_ENABLE_DEBUG']
361 message('Enabling various debug infrastructure')
363 glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
364 message('Disabling cast checks')
367 if not get_option('glib_assert')
368 glib_debug_cflags += ['-DG_DISABLE_ASSERT']
369 message('Disabling GLib asserts')
372 if not get_option('glib_checks')
373 glib_debug_cflags += ['-DG_DISABLE_CHECKS']
374 message('Disabling GLib checks')
377 add_project_arguments(glib_debug_cflags, language: 'c')
379 # check for header files
385 'dirent.h', # MSC does not come with this by default
421 'sys/time.h', # MSC does not come with this by default
439 define = 'HAVE_' + h.underscorify().to_upper()
440 glib_conf.set(define, 1)
441 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
445 # FreeBSD includes a malloc.h which always throws compilation error, so we have
446 # to use check_header() rather than has_header().
447 if cc.check_header('malloc.h')
448 glib_conf.set('HAVE_MALLOC_H', 1)
449 glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
452 if cc.check_header('linux/netlink.h')
453 glib_conf.set('HAVE_NETLINK', 1)
456 # Is statx() supported? Android systems don’t reliably support it as of August 2020.
461 #include <sys/stat.h>
465 struct statx stat_buf;
466 return statx (AT_FDCWD, "/", AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS | STATX_BTIME, &stat_buf);
469 if host_system != 'android' and cc.compiles(statx_code, name : 'statx() test')
470 glib_conf.set('HAVE_STATX', 1)
473 if glib_conf.has('HAVE_LOCALE_H')
474 if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
475 glib_conf.set('HAVE_LC_MESSAGES', 1)
479 struct_stat_blkprefix = '''
480 #include <sys/types.h>
481 #include <sys/stat.h>
485 #ifdef HAVE_SYS_STATFS_H
486 #include <sys/statfs.h>
488 #ifdef HAVE_SYS_PARAM_H
489 #include <sys/param.h>
491 #ifdef HAVE_SYS_MOUNT_H
492 #include <sys/mount.h>
497 [ 'stat', 'st_mtimensec' ],
498 [ 'stat', 'st_mtim.tv_nsec' ],
499 [ 'stat', 'st_atimensec' ],
500 [ 'stat', 'st_atim.tv_nsec' ],
501 [ 'stat', 'st_ctimensec' ],
502 [ 'stat', 'st_ctim.tv_nsec' ],
503 [ 'stat', 'st_birthtime' ],
504 [ 'stat', 'st_birthtimensec' ],
505 [ 'stat', 'st_birthtim' ],
506 [ 'stat', 'st_birthtim.tv_nsec' ],
507 [ 'stat', 'st_blksize', struct_stat_blkprefix ],
508 [ 'stat', 'st_blocks', struct_stat_blkprefix ],
509 [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
510 [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
511 [ 'dirent', 'd_type', '''#include <sys/types.h>
512 #include <dirent.h>''' ],
513 [ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
514 [ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
515 [ 'statvfs', 'f_type', '#include <sys/statvfs.h>' ],
516 [ 'tm', 'tm_gmtoff', '#include <time.h>' ],
517 [ 'tm', '__tm_gmtoff', '#include <time.h>' ],
520 foreach m : struct_members
521 header_check_prefix = glib_conf_prefix
523 header_check_prefix = header_check_prefix + m[2]
525 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
527 # Reimplement cc.has_member() to workaround compiler warning
528 # FIXME: https://github.com/mesonbuild/meson/pull/12818
529 code = header_check_prefix + '''
531 struct ''' + m[0] + ''' foo;
532 (void) ( foo.''' + m[1] + ''' );
536 if cc.compiles(code, name : 'type "struct ' + m[0] + '" has member "' + m[1] + '"')
537 define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
538 glib_conf.set(define, 1)
539 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
545 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
546 warning_common_args = [
547 '-Wduplicated-branches',
548 '-Wimplicit-fallthrough',
549 '-Wmisleading-indentation',
550 '-Wmissing-field-initializers',
553 # Due to maintained deprecated code, we do not want to see unused parameters
554 '-Wno-unused-parameter',
555 # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
556 # building with -Wbad-function-cast.
557 '-Wno-cast-function-type',
558 # Due to function casts through (void*) we cannot support -Wpedantic:
559 # ./docs/toolchain-requirements.md#Function_pointer_conversions.
561 # A zero-length format string shouldn't be considered an issue.
562 '-Wno-format-zero-length',
563 # We explicitly require variadic macros
564 '-Wno-variadic-macros',
567 '-Werror=missing-include-dirs',
568 '-Werror=pointer-arith',
569 '-Werror=unused-result',
572 warning_c_args = warning_common_args + [
573 '-Wstrict-prototypes',
574 # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
575 # building with -Wbad-function-cast.
576 '-Wno-bad-function-cast',
577 '-Werror=implicit-function-declaration',
578 '-Werror=missing-prototypes',
579 '-Werror=pointer-sign',
580 '-Wno-string-plus-int',
582 warning_cxx_args = warning_common_args
583 warning_objc_args = warning_c_args
584 warning_c_link_args = [
587 if get_option('bsymbolic_functions')
588 warning_c_link_args += ['-Wl,-Bsymbolic-functions']
590 elif cc.get_id() == 'msvc'
592 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
593 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
594 # NOTE: Only add warnings here if you are sure they're spurious
595 '/wo4057', # 'operator': 'identifier1' differs in indirection to slightly different base types from 'identifier2'
596 '/wd4068', # unknown pragma
597 '/wo4090', # 'operation': different 'modifier' qualifiers
598 '/wd4100', # 'identifier': unreferenced formal parameter
599 '/wd4116', # unnamed type definition in parentheses
600 '/wo4125', # decimal digit terminates octal escape sequence
601 '/wd4127', # conditional expression is constant
602 '/wd4146', # unary minus operator applied to unsigned type, result still unsigned
603 '/wd4152', # nonstandard extension, function/data pointer conversion in expression
604 '/wd4201', # nonstandard extension used: nameless struct/union
605 '/wd4232', # nonstandard extension used: 'identifier': address of dllimport 'dllimport' is not static, identity not guaranteed
606 '/wo4245', # 'conversion_type': conversion from 'type1' to 'type2', signed/unsigned mismatch
607 '/wo4267', # 'variable': conversion from 'size_t' to 'type', possible loss of data
608 '/wd4334', # 'shift_operator': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
609 '/wo4389', # 'operator': signed/unsigned mismatch
610 '/wo4702', # unreachable code
611 '/wd4706', # assignment within conditional expression
614 warning_cxx_args = []
615 warning_objc_args = []
616 warning_c_link_args = []
619 warning_cxx_args = []
620 warning_objc_args = []
621 warning_c_link_args = []
624 add_project_arguments(cc.get_supported_arguments(warning_c_args), language: 'c')
626 add_project_arguments(cxx.get_supported_arguments(warning_cxx_args), language: 'cpp')
629 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
630 # means we cannot use that flag in add_project_link_arguments(), and must add
631 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
632 # because that is what the autotools build did.
633 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
635 glib_link_flags = cc.get_supported_link_arguments(warning_c_link_args)
637 # Windows SDK requirements and checks
638 if host_system == 'windows'
639 # Check whether we're building for UWP apps
642 #if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
643 #error "Not building for UWP"
645 if cc.compiles(code, name : 'building for UWP')
646 glib_conf.set('G_WINAPI_ONLY_APP', true)
647 # We require Windows 10+ on WinRT
648 glib_conf.set('_WIN32_WINNT', '0x0A00')
649 uwp_gio_deps = [cc.find_library('shcore'),
650 cc.find_library('runtimeobject')]
652 # We require Windows 7+ on Win32
653 glib_conf.set('_WIN32_WINNT', '0x0601')
669 'free_aligned_sized',
725 # _NSGetEnviron is available on iOS too, but its usage gets apps rejected from
726 # the app store since it's considered 'private API'
727 if host_system == 'darwin'
728 functions += ['_NSGetEnviron']
731 if glib_conf.has('HAVE_SYS_STATVFS_H')
732 functions += ['statvfs']
734 have_func_statvfs = false
736 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
737 functions += ['statfs']
739 have_func_statfs = false
741 if glib_conf.has('HAVE_SYS_PRCTL_H')
742 functions += ['prctl']
744 have_func_prctl = false
747 if host_system == 'windows'
748 iphlpapi_dep = cc.find_library('iphlpapi')
749 iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
750 foreach ifunc : iphlpapi_funcs
751 iphl_prefix = '''#define _WIN32_WINNT @0@
752 #include <winsock2.h>
753 #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
754 if cc.has_function(ifunc,
755 prefix : iphl_prefix,
756 dependencies : iphlpapi_dep)
757 idefine = 'HAVE_' + ifunc.underscorify().to_upper()
758 glib_conf.set(idefine, 1)
759 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
760 set_variable('have_func_' + ifunc, true)
762 set_variable('have_func_' + ifunc, false)
766 functions += ['if_indextoname', 'if_nametoindex']
769 # AIX splice is something else
770 if host_system != 'aix'
771 functions += ['splice']
774 foreach f : functions
775 if cc.has_function(f)
776 define = 'HAVE_' + f.underscorify().to_upper()
777 glib_conf.set(define, 1)
778 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
779 set_variable('have_func_' + f, true)
781 set_variable('have_func_' + f, false)
785 # Export the information about free_sized() so we can correctly define a macro
786 # wrapper around g_free()/g_free_sized() depending on whether it’s available
787 glibconfig_conf.set('G_HAVE_FREE_SIZED', have_func_free_sized)
789 # Check that stpcpy() is usable; must use header.
791 # https://github.com/mesonbuild/meson/issues/5628.
792 if cc.has_function('stpcpy', prefix : '#include <string.h>')
793 glib_conf.set('HAVE_STPCPY', 1)
796 if cc.has_function('memalign', prefix: '#include <stdlib.h>\n#include <malloc.h>')
797 glib_conf.set('HAVE_MEMALIGN', 1)
800 # For example on Openbsd, getservbyname_r() has a different signature.
801 # https://man.openbsd.org/getservbyname.3
802 if cc.compiles('''#include <netdb.h>
803 int main (int argc, char ** argv) {
804 int (*fcn)(const char *,
809 struct servent **) = getservbyname_r;
813 name : 'getservbyname_r()',
814 args: '-Werror=incompatible-pointer-types')
815 glib_conf.set('HAVE_GETSERVBYNAME_R', 1)
818 if cc.has_function('_aligned_malloc', prefix: '#include <malloc.h>')
819 glib_conf.set('HAVE__ALIGNED_MALLOC', 1)
822 if host_system != 'windows' and cc.has_function('aligned_alloc', prefix: '#include <stdlib.h>')
823 glib_conf.set('HAVE_ALIGNED_ALLOC', 1)
826 if host_system != 'windows' and cc.has_function('posix_memalign', prefix: '#include <stdlib.h>')
827 glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
830 # Check that posix_spawn() is usable; must use header
831 if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
832 glib_conf.set('HAVE_POSIX_SPAWN', 1)
835 # Check whether strerror_r returns char *
836 if have_func_strerror_r
837 if cc.compiles('''#define _GNU_SOURCE
840 char error_string[256];
841 char *ptr = strerror_r (-2, error_string, 256);
842 char c = *strerror_r (-2, error_string, 256);
843 return c != 0 && ptr != (void*) 0L;
846 name : 'strerror_r() returns char *')
847 glib_conf.set('STRERROR_R_CHAR_P', 1,
848 description: 'Defined if strerror_r returns char *')
852 # Special-case these functions that have alternative names on Windows/MSVC
853 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
854 glib_conf.set('HAVE_SNPRINTF', 1)
855 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
856 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
857 hack_define = '1\n#define snprintf _snprintf'
858 glib_conf.set('HAVE_SNPRINTF', hack_define)
859 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
862 if cc.has_function('strcasecmp', prefix: '#include <strings.h>')
863 glib_conf.set('HAVE_STRCASECMP', 1)
864 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
865 elif cc.has_function('_stricmp')
866 hack_define = '1\n#define strcasecmp _stricmp'
867 glib_conf.set('HAVE_STRCASECMP', hack_define)
868 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
871 if cc.has_function('strncasecmp', prefix: '#include <strings.h>')
872 glib_conf.set('HAVE_STRNCASECMP', 1)
873 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
874 elif cc.has_function('_strnicmp')
875 hack_define = '1\n#define strncasecmp _strnicmp'
876 glib_conf.set('HAVE_STRNCASECMP', hack_define)
877 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
880 if cc.has_header_symbol('sys/sysmacros.h', 'major')
881 glib_conf.set('MAJOR_IN_SYSMACROS', 1)
882 elif cc.has_header_symbol('sys/mkdev.h', 'major')
883 glib_conf.set('MAJOR_IN_MKDEV', 1)
884 elif cc.has_header_symbol('sys/types.h', 'major')
885 glib_conf.set('MAJOR_IN_TYPES', 1)
888 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
889 glib_conf.set('HAVE_RTLD_LAZY', 1)
892 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
893 glib_conf.set('HAVE_RTLD_NOW', 1)
896 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
897 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
900 have_rtld_next = false
901 if cc.has_header_symbol('dlfcn.h', 'RTLD_NEXT', args: '-D_GNU_SOURCE')
902 have_rtld_next = true
903 glib_conf.set('HAVE_RTLD_NEXT', 1)
906 if cc.has_type('loff_t', prefix: '#include <sys/types.h>')
907 glib_conf.set('HAVE_LOFF_T', 1)
910 # Check whether to use statfs or statvfs
911 # Some systems have both statfs and statvfs, pick the most "native" for these
912 if have_func_statfs and have_func_statvfs
913 # on solaris and irix, statfs doesn't even have the f_bavail field
914 if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
915 have_func_statfs = false
917 # at least on linux, statfs is the actual syscall
918 have_func_statvfs = false
922 glib_conf.set('USE_STATFS', 1)
923 stat_func_to_use = 'statfs'
924 elif have_func_statvfs
925 glib_conf.set('USE_STATVFS', 1)
926 stat_func_to_use = 'statvfs'
928 stat_func_to_use = 'neither'
930 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
932 if host_system == 'linux'
933 if cc.has_function('mkostemp',
934 prefix: '''#define _GNU_SOURCE
935 #include <stdlib.h>''')
936 glib_conf.set('HAVE_MKOSTEMP', 1)
941 glib_have_os_x_9_or_later = false
942 glib_have_carbon = false
943 glib_have_cocoa = false
944 if host_system == 'darwin'
945 add_languages('objc', native: false, required: true)
946 objcc = meson.get_compiler('objc')
948 add_project_arguments(objcc.get_supported_arguments(warning_objc_args), language: 'objc')
950 # Mac OS X Carbon support
951 glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
952 #include <CoreServices/CoreServices.h>''',
953 name : 'Mac OS X Carbon support')
956 glib_conf.set('HAVE_CARBON', true)
957 glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
958 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
959 #error Compiling for minimum OS X version before 10.9
961 name : 'OS X 9 or later')
964 # Mac OS X Cocoa support
965 glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
966 #ifdef GNUSTEP_BASE_VERSION
967 #error "Detected GNUstep, not Cocoa"
969 name : 'Mac OS X Cocoa support')
972 glib_conf.set('HAVE_COCOA', true)
973 osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
977 if host_system == 'qnx'
978 glib_conf.set('HAVE_QNX', 1)
982 if cc.compiles('''#include <linux/futex.h>
983 #include <sys/syscall.h>
985 int main (int argc, char ** argv) {
986 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
988 }''', name : 'futex(2) system call')
989 glib_conf.set('HAVE_FUTEX', 1)
991 if cc.compiles('''#include <linux/futex.h>
992 #include <sys/syscall.h>
994 int main (int argc, char ** argv) {
995 syscall (__NR_futex_time64, NULL, FUTEX_WAKE, FUTEX_WAIT);
997 }''', name : 'futex(2) system call')
998 glib_conf.set('HAVE_FUTEX_TIME64', 1)
1001 # Check for eventfd(2)
1002 if cc.links('''#include <sys/eventfd.h>
1004 int main (int argc, char ** argv) {
1005 eventfd (0, EFD_CLOEXEC);
1007 }''', name : 'eventfd(2) system call')
1008 glib_conf.set('HAVE_EVENTFD', 1)
1011 # Check for pidfd_open(2)
1012 if cc.links('''#include <sys/syscall.h>
1013 #include <sys/wait.h>
1014 #include <linux/wait.h>
1016 int main (int argc, char ** argv) {
1017 siginfo_t child_info = { 0, };
1018 syscall (SYS_pidfd_open, 0, 0);
1019 waitid (P_PIDFD, 0, &child_info, WEXITED | WNOHANG);
1021 }''', name : 'pidfd_open(2) system call')
1022 glib_conf.set('HAVE_PIDFD', 1)
1025 # Check for __uint128_t (gcc) by checking for 128-bit division
1026 uint128_t_src = '''int main() {
1027 static __uint128_t v1 = 100;
1028 static __uint128_t v2 = 10;
1029 static __uint128_t u;
1033 if cc.compiles(uint128_t_src, name : '__uint128_t available')
1034 glib_conf.set('HAVE_UINT128_T', 1)
1037 clock_gettime_test_code = '''
1040 int main (int argc, char ** argv) {
1041 return clock_gettime(CLOCK_REALTIME, &t);
1044 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
1045 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
1046 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
1047 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
1048 librt = cc.find_library('rt')
1051 dlopen_dlsym_test_code = '''
1055 int glib_underscore_test (void) { return 42; }
1056 int main (int argc, char ** argv) {
1057 void *f1 = (void*)0, *f2 = (void*)0, *handle;
1058 handle = dlopen ((void*)0, 0);
1060 f1 = dlsym (handle, "glib_underscore_test");
1061 f2 = dlsym (handle, "_glib_underscore_test");
1063 r = (!f2 || f1) ? puts ("1") : puts ("0");
1064 return r > 0 ? 0 : r;
1067 if cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
1068 have_dlopen_dlsym = true
1069 elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
1070 have_dlopen_dlsym = true
1071 libdl_dep = cc.find_library('dl')
1073 have_dlopen_dlsym = false
1076 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
1078 if cc.compiles(glib_conf_prefix + '''
1080 #ifdef HAVE_SYS_PARAM_H
1081 #include <sys/param.h>
1083 #ifdef HAVE_SYS_VFS_H
1084 #include <sys/vfs.h>
1086 #ifdef HAVE_SYS_MOUNT_H
1087 #include <sys/mount.h>
1089 #ifdef HAVE_SYS_STATFS_H
1090 #include <sys/statfs.h>
1092 void some_func (void) {
1095 }''', name : 'number of arguments to statfs() (n=2)')
1096 glib_conf.set('STATFS_ARGS', 2)
1097 elif cc.compiles(glib_conf_prefix + '''
1099 #ifdef HAVE_SYS_PARAM_H
1100 #include <sys/param.h>
1102 #ifdef HAVE_SYS_VFS_H
1103 #include <sys/vfs.h>
1105 #ifdef HAVE_SYS_MOUNT_H
1106 #include <sys/mount.h>
1108 #ifdef HAVE_SYS_STATFS_H
1109 #include <sys/statfs.h>
1111 void some_func (void) {
1113 statfs("/", &st, sizeof (st), 0);
1114 }''', name : 'number of arguments to statfs() (n=4)')
1115 glib_conf.set('STATFS_ARGS', 4)
1117 error('Unable to determine number of arguments to statfs()')
1121 # open takes O_DIRECTORY as an option
1122 #AC_MSG_CHECKING([])
1123 if cc.compiles('''#include <fcntl.h>
1124 #include <sys/types.h>
1125 #include <sys/stat.h>
1126 void some_func (void) {
1127 open(".", O_DIRECTORY, 0);
1128 }''', name : 'open() option O_DIRECTORY')
1129 glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
1132 # fcntl takes F_FULLFSYNC as an option
1133 # See https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html
1134 if cc.compiles('''#include <fcntl.h>
1135 #include <sys/types.h>
1136 #include <sys/stat.h>
1137 void some_func (void) {
1138 fcntl(0, F_FULLFSYNC, 0);
1139 }''', name : 'fcntl() option F_FULLFSYNC')
1140 glib_conf.set('HAVE_FCNTL_F_FULLFSYNC', 1)
1143 # Check whether there is a vsnprintf() function with C99 semantics installed.
1144 # (similar tests to AC_FUNC_VSNPRINTF_C99)
1145 # Check whether there is a snprintf() function with C99 semantics installed.
1146 # (similar tests to AC_FUNC_SNPRINTF_C99)
1147 # Check whether there is a printf() function with Unix98 semantics installed.
1148 # (similar tests to AC_FUNC_PRINTF_UNIX98)
1149 have_good_vsnprintf = false
1150 have_good_snprintf = false
1151 have_good_printf = false
1153 if host_system == 'windows' and (cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl')
1154 # Unfortunately the Visual Studio 2015+ implementations of C99-style
1155 # snprintf and vsnprintf don't seem to be quite good enough.
1156 # (Sorry, I don't know exactly what is the problem,
1157 # but it is related to floating point formatting and decimal point vs. comma.)
1158 # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
1159 # rigorous enough to notice, though.
1160 glib_conf.set('HAVE_C99_SNPRINTF', false)
1161 glib_conf.set('HAVE_C99_VSNPRINTF', false)
1162 glib_conf.set('HAVE_UNIX98_PRINTF', false)
1163 elif not cc_can_run and host_system in ['ios', 'darwin']
1164 # All these are true when compiling natively on macOS, so we should use good
1165 # defaults when building for iOS and tvOS.
1166 glib_conf.set('HAVE_C99_SNPRINTF', true)
1167 glib_conf.set('HAVE_C99_VSNPRINTF', true)
1168 glib_conf.set('HAVE_UNIX98_PRINTF', true)
1169 have_good_vsnprintf = true
1170 have_good_snprintf = true
1171 have_good_printf = true
1173 vsnprintf_c99_test_code = '''
1186 r = vsnprintf(buffer, 5, s, args);
1192 /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
1193 implementation. The above will return 7 but if you replace
1194 the size of the buffer with 0, it borks! */
1196 r = vsnprintf(buffer, 0, s, args);
1213 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
1214 if rres.compiled() and rres.returncode() == 0
1215 glib_conf.set('HAVE_C99_VSNPRINTF', 1)
1216 have_good_vsnprintf = true
1219 have_good_vsnprintf = meson.get_external_property('have_c99_vsnprintf', false)
1220 glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
1223 snprintf_c99_test_code = '''
1234 r = snprintf(buffer, 5, "1234567");
1239 r = snprintf(buffer, 0, "1234567");
1244 r = snprintf(NULL, 0, "1234567");
1260 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
1261 if rres.compiled() and rres.returncode() == 0
1262 glib_conf.set('HAVE_C99_SNPRINTF', 1)
1263 have_good_snprintf = true
1266 have_good_snprintf = meson.get_external_property('have_c99_snprintf', false)
1267 glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
1270 printf_unix98_test_code = '''
1280 sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
1281 if (strcmp ("2 3 1", buffer) == 0)
1287 rres = cc.run(printf_unix98_test_code, name : 'Unix98 printf positional parameters')
1288 if rres.compiled() and rres.returncode() == 0
1289 glib_conf.set('HAVE_UNIX98_PRINTF', 1)
1290 have_good_printf = true
1293 have_good_printf = meson.get_external_property('have_unix98_printf', false)
1294 glib_conf.set('HAVE_UNIX98_PRINTF', have_good_printf)
1298 if host_system == 'windows'
1299 glib_conf.set_quoted('EXEEXT', '.exe')
1301 glib_conf.set('EXEEXT', '')
1304 # Our printf is 'good' only if vsnpintf()/snprintf()/printf() supports C99 well enough
1305 use_system_printf = have_good_vsnprintf and have_good_snprintf and have_good_printf
1306 glib_conf.set('USE_SYSTEM_PRINTF', use_system_printf)
1307 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', use_system_printf)
1309 if not use_system_printf
1310 # gnulib has vasprintf so override the previous check
1311 glib_conf.set('HAVE_VASPRINTF', 1)
1314 # Check for nl_langinfo and CODESET
1315 if cc.links('''#include <langinfo.h>
1316 int main (int argc, char ** argv) {
1317 char *codeset = nl_langinfo (CODESET);
1320 }''', name : 'nl_langinfo and CODESET')
1321 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
1322 glib_conf.set('HAVE_CODESET', 1)
1325 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
1326 have_langinfo_time = false
1327 if cc.links('''#include <langinfo.h>
1328 int main (int argc, char ** argv) {
1330 str = nl_langinfo (PM_STR);
1331 str = nl_langinfo (D_T_FMT);
1332 str = nl_langinfo (D_FMT);
1333 str = nl_langinfo (T_FMT);
1334 str = nl_langinfo (T_FMT_AMPM);
1335 str = nl_langinfo (MON_1);
1336 str = nl_langinfo (ABMON_12);
1337 str = nl_langinfo (DAY_1);
1338 str = nl_langinfo (ABDAY_7);
1341 }''', name : 'nl_langinfo (PM_STR)')
1342 have_langinfo_time = true
1343 glib_conf.set('HAVE_LANGINFO_TIME', 1)
1346 # Linux glibc supports ERA, but FreeBSD and macOS don’t
1347 if cc.links('''#include <langinfo.h>
1348 int main (int argc, char **argv) {
1350 str = nl_langinfo (ERA);
1351 str = nl_langinfo (ERA_D_T_FMT);
1352 str = nl_langinfo (ERA_D_FMT);
1353 str = nl_langinfo (ERA_T_FMT);
1354 str = nl_langinfo (_NL_TIME_ERA_NUM_ENTRIES);
1357 }''', name : 'nl_langinfo (ERA)')
1358 glib_conf.set('HAVE_LANGINFO_ERA', 1)
1359 if not have_langinfo_time
1360 error('nl_langinfo(ERA) is supported but more basic nl_langinfo() functionality like PM_STR is not')
1364 if cc.links('''#include <langinfo.h>
1365 int main (int argc, char ** argv) {
1367 str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
1368 str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
1369 str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
1370 str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
1371 str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
1372 str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
1373 str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
1374 str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
1375 str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
1376 str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
1379 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
1380 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
1381 if not have_langinfo_time
1382 error('nl_langinfo(_NL_CTYPE_OUTDIGITn_MB) is supported but more basic nl_langinfo() functionality like PM_STR is not')
1386 # Check for nl_langinfo and alternative month names
1387 if cc.links('''#ifndef _GNU_SOURCE
1388 # define _GNU_SOURCE
1390 #include <langinfo.h>
1391 int main (int argc, char ** argv) {
1393 str = nl_langinfo (ALTMON_1);
1394 str = nl_langinfo (ALTMON_2);
1395 str = nl_langinfo (ALTMON_3);
1396 str = nl_langinfo (ALTMON_4);
1397 str = nl_langinfo (ALTMON_5);
1398 str = nl_langinfo (ALTMON_6);
1399 str = nl_langinfo (ALTMON_7);
1400 str = nl_langinfo (ALTMON_8);
1401 str = nl_langinfo (ALTMON_9);
1402 str = nl_langinfo (ALTMON_10);
1403 str = nl_langinfo (ALTMON_11);
1404 str = nl_langinfo (ALTMON_12);
1407 }''', name : 'nl_langinfo (ALTMON_n)')
1408 glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
1409 if not have_langinfo_time
1410 error('nl_langinfo(ALTMON_n) is supported but more basic nl_langinfo() functionality like PM_STR is not')
1414 # Check for nl_langinfo and abbreviated alternative month names
1415 if cc.links('''#ifndef _GNU_SOURCE
1416 # define _GNU_SOURCE
1418 #include <langinfo.h>
1419 int main (int argc, char ** argv) {
1421 str = nl_langinfo (_NL_ABALTMON_1);
1422 str = nl_langinfo (_NL_ABALTMON_2);
1423 str = nl_langinfo (_NL_ABALTMON_3);
1424 str = nl_langinfo (_NL_ABALTMON_4);
1425 str = nl_langinfo (_NL_ABALTMON_5);
1426 str = nl_langinfo (_NL_ABALTMON_6);
1427 str = nl_langinfo (_NL_ABALTMON_7);
1428 str = nl_langinfo (_NL_ABALTMON_8);
1429 str = nl_langinfo (_NL_ABALTMON_9);
1430 str = nl_langinfo (_NL_ABALTMON_10);
1431 str = nl_langinfo (_NL_ABALTMON_11);
1432 str = nl_langinfo (_NL_ABALTMON_12);
1435 }''', name : 'nl_langinfo (_NL_ABALTMON_n)')
1436 glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
1437 if not have_langinfo_time
1438 error('nl_langinfo(_NL_ABALTMON_n) is supported but more basic nl_langinfo() functionality like PM_STR is not')
1442 # Check for nl_langinfo and _NL_TIME_CODESET
1443 if cc.links('''#include <langinfo.h>
1444 int main (int argc, char ** argv) {
1445 char *codeset = nl_langinfo (_NL_TIME_CODESET);
1448 }''', name : 'nl_langinfo and _NL_TIME_CODESET')
1449 glib_conf.set('HAVE_LANGINFO_TIME_CODESET', 1)
1450 if not have_langinfo_time
1451 error('nl_langinfo(_NL_TIME_CODESET) is supported but more basic nl_langinfo() functionality like PM_STR is not')
1455 # Check if C compiler supports the 'signed' keyword
1456 if not cc.compiles('''signed char x;''', name : 'signed')
1457 glib_conf.set('signed', '/* NOOP */')
1460 # Check if the ptrdiff_t type exists
1461 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
1462 glib_conf.set('HAVE_PTRDIFF_T', 1)
1465 # Check for sig_atomic_t type
1466 if cc.links('''#include <signal.h>
1467 #include <sys/types.h>
1468 sig_atomic_t val = 42;
1469 int main (int argc, char ** argv) {
1470 return val == 42 ? 0 : 1;
1471 }''', name : 'sig_atomic_t')
1472 glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
1475 # Check if 'long long' works
1476 # jm_AC_TYPE_LONG_LONG
1477 if cc.compiles('''long long ll = 1LL;
1479 int some_func (void) {
1480 long long llmax = (long long) -1;
1481 return ll << i | ll >> i | llmax / ll | llmax % ll;
1482 }''', name : 'long long')
1483 glib_conf.set('HAVE_LONG_LONG', 1)
1484 have_long_long = true
1486 have_long_long = false
1489 # Test whether the compiler supports the 'long double' type.
1490 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
1491 long double foo = 0.0;
1492 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
1493 int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
1494 name : 'long double')
1495 glib_conf.set('HAVE_LONG_DOUBLE', 1)
1498 # Test whether <stddef.h> has the 'wchar_t' type.
1499 if cc.has_header_symbol('stddef.h', 'wchar_t')
1500 glib_conf.set('HAVE_WCHAR_T', 1)
1503 # Test whether <wchar.h> has the 'wint_t' type.
1504 if cc.has_header_symbol('wchar.h', 'wint_t')
1505 glib_conf.set('HAVE_WINT_T', 1)
1508 found_uintmax_t = false
1510 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
1511 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1512 # jm_AC_HEADER_INTTYPES_H
1513 if cc.compiles('''#include <sys/types.h>
1514 #include <inttypes.h>
1515 void some_func (void) {
1516 uintmax_t i = (uintmax_t) -1;
1518 }''', name : 'uintmax_t in inttypes.h')
1519 glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1520 found_uintmax_t = true
1523 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1524 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1525 # jm_AC_HEADER_STDINT_H
1526 if cc.compiles('''#include <sys/types.h>
1528 void some_func (void) {
1529 uintmax_t i = (uintmax_t) -1;
1531 }''', name : 'uintmax_t in stdint.h')
1532 glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1533 found_uintmax_t = true
1536 # Define intmax_t to 'long' or 'long long'
1537 # if it is not already defined in <stdint.h> or <inttypes.h>.
1538 # For simplicity, we assume that a header file defines 'intmax_t' if and
1539 # only if it defines 'uintmax_t'.
1541 glib_conf.set('HAVE_INTMAX_T', 1)
1543 glib_conf.set('intmax_t', 'long long')
1545 glib_conf.set('intmax_t', 'long')
1548 char_size = cc.sizeof('char')
1549 short_size = cc.sizeof('short')
1550 int_size = cc.sizeof('int')
1551 voidp_size = cc.sizeof('void*')
1552 long_size = cc.sizeof('long')
1554 long_long_size = cc.sizeof('long long')
1558 sizet_size = cc.sizeof('size_t')
1559 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1560 ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1562 ssizet_size = cc.sizeof('ssize_t', prefix : '#include <unistd.h>')
1565 # Some platforms (Apple) hard-code int64_t to long long instead of
1566 # using long on 64-bit architectures. This can cause type mismatch
1567 # warnings when trying to interface with code using the standard
1568 # library type. Test for the warnings and set gint64 to whichever
1570 if long_long_size == long_size
1571 if cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1572 #pragma options langlvl=stdc99
1574 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1582 }''', name : 'int64_t is long')
1583 int64_t_typedef = 'long'
1584 elif cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1585 #pragma options langlvl=stdc99
1587 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1592 long long *i2 = &i1;
1595 }''', name : 'int64_t is long long')
1596 int64_t_typedef = 'long long'
1598 error('Cannot detect int64_t typedef')
1603 char_align = cc.alignment('char')
1604 short_align = cc.alignment('short')
1605 int_align = cc.alignment('int')
1606 voidp_align = cc.alignment('void*')
1607 long_align = cc.alignment('long')
1608 long_long_align = cc.alignment('long long')
1609 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1610 # be 64-bit in C99, and it is available on all supported compilers
1611 sizet_align = cc.alignment('size_t')
1613 glib_conf.set('SIZEOF_CHAR', char_size)
1614 glib_conf.set('SIZEOF_INT', int_size)
1615 glib_conf.set('SIZEOF_SHORT', short_size)
1616 glib_conf.set('SIZEOF_LONG', long_size)
1617 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1618 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1619 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1620 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1621 glib_conf.set('SIZEOF_WCHAR_T', cc.sizeof('wchar_t', prefix: '#include <stddef.h>'))
1634 error('Compiler provides no native 16-bit integer type')
1636 glibconfig_conf.set('gint16', gint16)
1637 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1638 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1639 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1646 guint32_align = short_align
1652 guint32_align = int_align
1658 guint32_align = long_align
1660 error('Compiler provides no native 32-bit integer type')
1662 glibconfig_conf.set('gint32', gint32)
1663 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1664 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1665 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1673 gint64_constant='(val)'
1674 guint64_constant='(val)'
1675 guint64_align = int_align
1676 elif long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long')
1682 gint64_constant='(val##L)'
1683 guint64_constant='(val##UL)'
1684 guint64_align = long_align
1685 elif long_long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long long')
1686 gint64 = 'long long'
1687 glib_extension='G_GNUC_EXTENSION '
1688 gint64_modifier=int64_m
1689 gint64_format=int64_m + 'i'
1690 guint64_format=int64_m + 'u'
1691 gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1692 guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1693 guint64_align = long_long_align
1695 error('Compiler provides no native 64-bit integer type')
1697 glibconfig_conf.set('glib_extension', glib_extension)
1698 glibconfig_conf.set('gint64', gint64)
1699 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1700 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1701 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1702 glibconfig_conf.set('gint64_constant', gint64_constant)
1703 glibconfig_conf.set('guint64_constant', guint64_constant)
1705 if host_system == 'windows'
1706 glibconfig_conf.set('g_pid_type', 'void*')
1707 glibconfig_conf.set_quoted('g_pid_format', 'p')
1708 if host_machine.cpu_family() == 'x86_64'
1709 glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1711 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1713 glibconfig_conf.set('g_dir_separator', '\\\\')
1714 glibconfig_conf.set('g_searchpath_separator', ';')
1716 glibconfig_conf.set('g_pid_type', 'int')
1717 glibconfig_conf.set_quoted('g_pid_format', 'i')
1718 glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1719 glibconfig_conf.set('g_dir_separator', '/')
1720 glibconfig_conf.set('g_searchpath_separator', ':')
1723 g_sizet_compatibility = {
1724 'short': sizet_size == short_size,
1725 'int': sizet_size == int_size,
1726 'long': sizet_size == long_size,
1727 'long long': sizet_size == long_long_size,
1730 # Do separate checks for gcc/clang (and ignore other compilers for now), since
1731 # we need to explicitly pass -Werror to the compilers.
1732 # FIXME: https://github.com/mesonbuild/meson/issues/5399
1733 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
1734 foreach type_name, size_compatibility : g_sizet_compatibility
1735 g_sizet_compatibility += { type_name: size_compatibility and
1737 '''#include <stddef.h>
1738 static size_t f (size_t *i) { return *i + 1; }
1740 unsigned ''' + type_name + ''' i = 0;
1745 name : 'GCC size_t typedef is ' + type_name), }
1749 if g_sizet_compatibility['short']
1750 glibconfig_conf.set('glib_size_type_define', 'short')
1751 glibconfig_conf.set_quoted('gsize_modifier', 'h')
1752 glibconfig_conf.set_quoted('gssize_modifier', 'h')
1753 glibconfig_conf.set_quoted('gsize_format', 'hu')
1754 glibconfig_conf.set_quoted('gssize_format', 'hi')
1755 glibconfig_conf.set('glib_msize_type', 'SHRT')
1756 elif g_sizet_compatibility['int']
1757 glibconfig_conf.set('glib_size_type_define', 'int')
1758 glibconfig_conf.set_quoted('gsize_modifier', '')
1759 glibconfig_conf.set_quoted('gssize_modifier', '')
1760 glibconfig_conf.set_quoted('gsize_format', 'u')
1761 glibconfig_conf.set_quoted('gssize_format', 'i')
1762 glibconfig_conf.set('glib_msize_type', 'INT')
1763 elif g_sizet_compatibility['long']
1764 glibconfig_conf.set('glib_size_type_define', 'long')
1765 glibconfig_conf.set_quoted('gsize_modifier', 'l')
1766 glibconfig_conf.set_quoted('gssize_modifier', 'l')
1767 glibconfig_conf.set_quoted('gsize_format', 'lu')
1768 glibconfig_conf.set_quoted('gssize_format', 'li')
1769 glibconfig_conf.set('glib_msize_type', 'LONG')
1770 elif g_sizet_compatibility['long long']
1771 glibconfig_conf.set('glib_size_type_define', 'long long')
1772 glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1773 glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1774 glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1775 glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1776 glibconfig_conf.set('glib_msize_type', 'INT64')
1778 error('Could not determine size of size_t.')
1781 if voidp_size == int_size
1782 glibconfig_conf.set('glib_intptr_type_define', 'int')
1783 glibconfig_conf.set_quoted('gintptr_modifier', '')
1784 glibconfig_conf.set_quoted('gintptr_format', 'i')
1785 glibconfig_conf.set_quoted('guintptr_format', 'u')
1786 glibconfig_conf.set('glib_gpi_cast', '(gint)')
1787 glibconfig_conf.set('glib_gpui_cast', '(guint)')
1788 elif voidp_size == long_size
1789 glibconfig_conf.set('glib_intptr_type_define', 'long')
1790 glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1791 glibconfig_conf.set_quoted('gintptr_format', 'li')
1792 glibconfig_conf.set_quoted('guintptr_format', 'lu')
1793 glibconfig_conf.set('glib_gpi_cast', '(glong)')
1794 glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1795 elif voidp_size == long_long_size
1796 glibconfig_conf.set('glib_intptr_type_define', 'long long')
1797 glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1798 glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1799 glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1800 glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1801 glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1803 error('Could not determine size of void *')
1806 if long_size != 8 and long_long_size != 8 and int_size != 8
1807 error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1810 glibconfig_conf.set('gintbits', int_size * 8)
1811 glibconfig_conf.set('glongbits', long_size * 8)
1812 glibconfig_conf.set('gsizebits', sizet_size * 8)
1813 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1815 # XXX: https://gitlab.gnome.org/GNOME/glib/issues/1413
1816 if host_system == 'windows'
1817 g_module_suffix = 'dll'
1819 g_module_suffix = 'so'
1821 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1823 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1824 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1825 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1826 glibconfig_conf.set('GLIB_VERSION', glib_version)
1828 glibconfig_conf.set('glib_void_p', voidp_size)
1829 glibconfig_conf.set('glib_long', long_size)
1830 glibconfig_conf.set('glib_size_t', sizet_size)
1831 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1832 if host_machine.endian() == 'big'
1833 glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1834 glibconfig_conf.set('g_bs_native', 'BE')
1835 glibconfig_conf.set('g_bs_alien', 'LE')
1837 glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1838 glibconfig_conf.set('g_bs_native', 'LE')
1839 glibconfig_conf.set('g_bs_alien', 'BE')
1842 # === va_copy checks ===
1846 # We check for G_VA_COPY_AS_ARRAY for historical reasons, but we no longer
1847 # use it: use Standard C va_copy() instead.
1849 va_list_val_copy_prog = '''
1852 void f (int i, ...) {
1853 va_list args1, args2;
1854 va_start (args1, i);
1856 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1858 va_end (args1); va_end (args2);
1866 rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1867 glib_va_val_copy = rres.compiled() and rres.returncode() == 0
1869 glib_va_val_copy = meson.get_external_property('va_val_copy', true)
1871 if not glib_va_val_copy
1872 glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1873 glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1875 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1877 # check for flavours of varargs macros
1878 g_have_iso_c_varargs = cc.compiles('''
1879 void some_func (void) {
1880 int a(int p1, int p2, int p3);
1881 #define call_a(...) a(1,__VA_ARGS__)
1883 }''', name : 'ISO C99 varargs macros in C')
1885 if not g_have_iso_c_varargs
1886 error('GLib requires a C compiler with support for C99 __VA_ARG__ in macros.')
1890 g_have_iso_cxx_varargs = cxx.compiles('''
1891 void some_func (void) {
1892 int a(int p1, int p2, int p3);
1893 #define call_a(...) a(1,__VA_ARGS__)
1895 }''', name : 'ISO C99 varargs macros in C++')
1897 if not g_have_iso_cxx_varargs
1898 error('GLib requires a C++ compiler with support for C99 __VA_ARG__ in macros.')
1902 g_have_gnuc_varargs = cc.compiles('''
1903 void some_func (void) {
1904 int a(int p1, int p2, int p3);
1905 #define call_a(params...) a(1,params)
1907 }''', name : 'GNUC varargs macros')
1909 if cc.has_header('alloca.h')
1910 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1912 has_syspoll = cc.has_header('sys/poll.h')
1913 has_systypes = cc.has_header('sys/types.h')
1915 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1917 has_winsock2 = cc.has_header('winsock2.h')
1919 if has_syspoll and has_systypes
1921 #include<sys/poll.h>
1922 #include<sys/types.h>'''
1925 #define _WIN32_WINNT @0@
1926 #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1929 error('FIX POLL* defines')
1933 [ 'POLLIN', 'g_pollin', 1 ],
1934 [ 'POLLOUT', 'g_pollout', 4 ],
1935 [ 'POLLPRI', 'g_pollpri', 2 ],
1936 [ 'POLLERR', 'g_pollerr', 8 ],
1937 [ 'POLLHUP', 'g_pollhup', 16 ],
1938 [ 'POLLNVAL', 'g_pollnval', 32 ],
1941 if has_syspoll and has_systypes
1942 foreach d : poll_defines
1943 val = cc.compute_int(d[0], prefix: poll_includes)
1944 glibconfig_conf.set(d[1], val)
1947 # Due to a missed bug in configure.ac the poll test
1948 # never succeeded on Windows and used some pre-defined
1949 # values as a fallback. Keep using them to maintain
1950 # ABI compatibility with autotools builds of glibs
1951 # and with *any* glib-using code compiled against them,
1952 # since these values end up in a public header glibconfig.h.
1953 foreach d : poll_defines
1954 glibconfig_conf.set(d[1], d[2])
1958 # Internet address families
1959 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1960 if host_system == 'windows'
1962 #include <winsock2.h>'''
1965 #include <sys/types.h>
1966 #include <sys/socket.h>'''
1970 [ 'AF_UNIX', 'g_af_unix' ],
1971 [ 'AF_INET', 'g_af_inet' ],
1972 [ 'AF_INET6', 'g_af_inet6' ],
1973 [ 'MSG_OOB', 'g_msg_oob' ],
1974 [ 'MSG_PEEK', 'g_msg_peek' ],
1975 [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1977 foreach d : inet_defines
1978 val = cc.compute_int(d[0], prefix: inet_includes)
1979 glibconfig_conf.set(d[1], val)
1982 if host_system == 'windows'
1985 have_ipv6 = cc.has_type('struct in6_addr', prefix: '#include <netinet/in.h>')
1987 glib_conf.set('HAVE_IPV6', have_ipv6)
1989 # We need to decide at configure time if GLib will use real atomic
1990 # operations ("lock free") or emulated ones with a mutex. This is
1991 # because we must put this information in glibconfig.h so we know if
1992 # it is safe or not to inline using compiler intrinsics directly from
1995 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1996 # user is interested in knowing if they can use the atomic ops across
1999 # We can currently support the atomic ops natively when building GLib
2000 # with recent versions of GCC or MSVC.
2002 # Note that the atomic ops are only available with GCC on x86 when
2003 # using -march=i486 or higher. If we detect that the atomic ops are
2004 # not available but would be available given the right flags, we want
2005 # to abort and advise the user to fix their CFLAGS. It's better to do
2006 # that then to silently fall back on emulated atomic ops just because
2007 # the user had the wrong build environment.
2008 atomictest = '''int main() {
2010 __sync_bool_compare_and_swap (&atomic, 2, 3);
2016 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
2017 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
2021 # We know that we can always use real ("lock free") atomic operations with MSVC
2022 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' or cc.links(atomictest, name : 'atomic ops')
2023 have_atomic_lock_free = true
2024 if cc.get_id() == 'gcc' and not cc.compiles(atomicdefine, name : 'atomic ops define')
2025 # Old gcc release may provide
2026 # __sync_bool_compare_and_swap but doesn't define
2027 # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
2028 glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
2031 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
2032 sync_swap_test = '''
2035 __sync_swap (&atomic, 2);
2040 glib_conf.set('_GLIB_GCC_HAVE_SYNC_SWAP', cc.links(sync_swap_test, name : 'sync swap'))
2043 have_atomic_lock_free = false
2044 if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
2045 error('GLib must be built with -march=i486 or later.')
2048 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
2052 if get_option('force_posix_threads')
2053 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')
2056 # Determination of thread implementation
2057 if host_system == 'windows' and not get_option('force_posix_threads')
2059 threads_implementation = 'win32'
2060 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
2061 glib_conf.set('THREADS_WIN32', 1)
2063 thread_dep = dependency('threads')
2064 threads_implementation = 'posix'
2065 pthread_prefix = '''
2067 # define _GNU_SOURCE
2069 #include <pthread.h>'''
2070 glibconfig_conf.set('g_threads_impl_def', 'POSIX')
2071 glib_conf.set('THREADS_POSIX', 1)
2072 if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
2073 glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
2075 if cc.has_header_symbol('pthread.h', 'pthread_attr_setinheritsched')
2076 glib_conf.set('HAVE_PTHREAD_ATTR_SETINHERITSCHED', 1)
2078 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
2079 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
2081 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
2082 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
2084 if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
2085 glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
2087 if cc.has_header_symbol('pthread.h', 'pthread_getaffinity_np', prefix : pthread_prefix)
2088 glib_conf.set('HAVE_PTHREAD_GETAFFINITY_NP', 1)
2091 # Assume that pthread_setname_np is available in some form; same as configure
2092 if cc.links(pthread_prefix + '''
2094 pthread_setname_np("example");
2097 name : 'pthread_setname_np(const char*)',
2098 dependencies : thread_dep)
2100 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
2101 elif cc.links(pthread_prefix + '''
2103 pthread_setname_np(pthread_self(), "example");
2106 name : 'pthread_setname_np(pthread_t, const char*)',
2107 dependencies : thread_dep)
2108 # Linux, Solaris, etc.
2109 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
2110 elif cc.links(pthread_prefix + '''
2112 pthread_setname_np(pthread_self(), "%s", "example");
2115 name : 'pthread_setname_np(pthread_t, const char*, void*)',
2116 dependencies : thread_dep)
2118 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG', 1)
2119 elif cc.links(pthread_prefix + '''
2120 #include <pthread_np.h>
2122 pthread_set_name_np(pthread_self(), "example");
2125 name : 'pthread_set_name_np(pthread_t, const char*)',
2126 dependencies : thread_dep)
2127 # FreeBSD, DragonFlyBSD, OpenBSD, etc.
2128 glib_conf.set('HAVE_PTHREAD_SET_NAME_NP', 1)
2132 # FIXME: we should make it print the result and always return 0, so that
2133 # the output in meson shows up as green
2134 # volatile is needed here to avoid optimisations in the test
2135 stack_grows_check_prog = '''
2136 volatile int *a = 0, *b = 0;
2148 return b > a ? 0 : 1;
2152 rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
2153 growing_stack = rres.compiled() and rres.returncode() == 0
2155 growing_stack = meson.get_external_property('growing_stack', false)
2158 glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack)
2162 # We should never use the MinGW C library's iconv because it may not be
2163 # available in the actual runtime environment. On Windows, we always use
2164 # the built-in implementation
2165 if host_system == 'windows'
2166 # We have a #include "win_iconv.c" in gconvert.c on Windows, so we don't need
2167 # any external library for it
2170 libiconv = dependency('iconv')
2173 pcre2_req = '>=10.32'
2175 # Pick up pcre from the system, or if "--force-fallback-for libpcre2-8" was specified
2176 pcre2 = dependency('libpcre2-8', version: pcre2_req, required: false, default_options: ['default_library=static'])
2177 if not pcre2.found()
2178 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
2179 # MSVC: Search for the PCRE2 library by the configuration, which corresponds
2180 # to the output of CMake builds of PCRE2. Note that debugoptimized
2181 # is really a Release build with .PDB files.
2182 if vs_crt == 'debug'
2183 pcre2 = cc.find_library('pcre2d-8', required : false)
2185 pcre2 = cc.find_library('pcre2-8', required : false)
2190 # Try again with the fallback
2191 if not pcre2.found()
2192 pcre2 = dependency('libpcre2-8', version: pcre2_req, allow_fallback: true, default_options: ['default_library=static'])
2193 assert(pcre2.type_name() == 'internal')
2194 # static flags are automatically enabled by the subproject if it's built
2195 # with default_library=static
2196 use_pcre2_static_flag = false
2197 elif host_system == 'windows' and pcre2.type_name() != 'internal'
2198 pcre2_static = cc.links('''#define PCRE2_STATIC
2199 #define PCRE2_CODE_UNIT_WIDTH 8
2206 dependencies: pcre2,
2207 name : 'Windows system PCRE2 is a static build')
2208 use_pcre2_static_flag = pcre2_static
2210 use_pcre2_static_flag = false
2213 # Import the gvdb sources as a subproject to avoid having the copylib in-tree
2215 gvdb_dep = dependency('gvdb')
2217 libm = cc.find_library('m', required : false)
2218 libffi_dep = dependency('libffi', version : '>= 3.0.0')
2220 libz_dep = dependency('zlib')
2222 # First check in libc, fallback to libintl, and as last chance build
2223 # proxy-libintl subproject.
2224 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
2225 # implementations. This could be extended if issues are found in some platforms.
2227 libintl_prefix = '#include <libintl.h>'
2228 libintl = dependency('intl', required: false)
2229 if libintl.found() and libintl.type_name() != 'internal'
2230 # libintl supports different threading APIs, which may not
2231 # require additional flags, but it defaults to using pthreads if
2232 # found. Meson's "threads" dependency does not allow you to
2233 # prefer pthreads. We may not be using pthreads for glib itself
2234 # either so just link the library to satisfy libintl rather than
2235 # also defining the macros with the -pthread flag.
2237 # Meson's builtin dependency lookup as of 0.60.0 doesn't check for
2238 # pthread, so we do this manually here.
2239 if cc.has_function('ngettext', dependencies : libintl, prefix: libintl_prefix)
2240 libintl_deps += [libintl]
2242 libintl_iconv = cc.find_library('iconv', required : false)
2243 if libintl_iconv.found() and cc.has_function('ngettext', args : osx_ldflags, dependencies : [libintl, libintl_iconv])
2244 libintl_deps += [libintl, libintl_iconv]
2246 libintl_pthread = cc.find_library('pthread', required : false)
2247 if libintl_pthread.found() and cc.has_function('ngettext', dependencies : [libintl, libintl_pthread], prefix: libintl_prefix)
2248 libintl_deps += [libintl, libintl_pthread]
2250 libintl = disabler()
2256 if libintl.found() and libintl.type_name() != 'internal'
2257 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset', dependencies: libintl_deps, prefix: libintl_prefix)
2259 # using proxy-libintl fallback
2260 libintl = dependency('intl', allow_fallback: true)
2261 assert(libintl.type_name() == 'internal')
2262 libintl_deps = [libintl]
2263 have_bind_textdomain_codeset = true # proxy-libintl supports it
2266 glib_conf.set('HAVE_BIND_TEXTDOMAIN_CODESET', have_bind_textdomain_codeset)
2268 # We require gettext to always be present
2269 glib_conf.set('HAVE_DCGETTEXT', 1)
2270 glib_conf.set('HAVE_GETTEXT', 1)
2272 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
2274 glib_conf.set_quoted('GLIB_LOCALSTATEDIR', glib_localstatedir)
2275 glib_conf.set_quoted('GLIB_RUNSTATEDIR', glib_runstatedir)
2277 # libmount is only used by gio, but we need to fetch the libs to generate the
2278 # pkg-config file below
2280 if host_system == 'linux'
2281 libmount_dep = dependency('mount', version : '>=2.23', required : get_option('libmount'))
2282 glib_conf.set('HAVE_LIBMOUNT', libmount_dep.found())
2284 if libmount_dep.found() and cc.has_function('mnt_monitor_veil_kernel', dependencies: libmount_dep)
2285 glib_conf.set('HAVE_MNT_MONITOR_VEIL_KERNEL', 1)
2289 if host_system == 'windows'
2290 winsock2 = cc.find_library('ws2_32')
2292 winsock2 = not_found
2296 if host_system == 'linux'
2297 selinux_dep = dependency('libselinux', version: '>=2.2', required: get_option('selinux'))
2299 glib_conf.set('HAVE_SELINUX', selinux_dep.found())
2303 if host_system != 'windows' and get_option('xattr')
2304 # either glibc or libattr can provide xattr support
2305 # for both of them, we check for getxattr being in
2306 # the library and a valid xattr header.
2309 if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
2310 glib_conf.set('HAVE_SYS_XATTR_H', 1)
2311 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
2312 #failure. try libattr
2313 elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
2314 glib_conf.set('HAVE_ATTR_XATTR_H', 1)
2315 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
2316 xattr_dep = [cc.find_library('xattr')]
2318 error('No getxattr implementation found in C library or libxattr')
2321 glib_conf.set('HAVE_XATTR', 1)
2322 if cc.compiles(glib_conf_prefix + '''
2324 #ifdef HAVE_SYS_TYPES_H
2325 #include <sys/types.h>
2327 #ifdef HAVE_SYS_XATTR_H
2328 #include <sys/xattr.h>
2329 #elif HAVE_ATTR_XATTR_H
2330 #include <attr/xattr.h>
2334 ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
2337 name : 'XATTR_NOFOLLOW')
2338 glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
2342 # If strlcpy is present (BSD and similar), check that it conforms to the BSD
2343 # specification. Specifically Solaris 8's strlcpy() does not, see
2344 # https://bugzilla.gnome.org/show_bug.cgi?id=53933 for further context.
2345 if cc.has_function('strlcpy')
2347 rres = cc.run('''#include <stdlib.h>
2351 (void) strlcpy (p, "hi", 10);
2352 if (strlcat (p, "bye", 0) != 3)
2356 name : 'OpenBSD strlcpy/strlcat')
2357 if rres.compiled() and rres.returncode() == 0
2358 glib_conf.set('HAVE_STRLCPY', 1)
2360 elif meson.get_external_property('have_strlcpy', false)
2361 glib_conf.set('HAVE_STRLCPY', 1)
2365 cmdline_test_code = '''
2367 #include <sys/stat.h>
2375 /* This code is a dumbed-down version of g_file_get_contents() */
2379 #define BUFSIZE 1024
2380 char result[BUFSIZE];
2381 struct stat stat_buf;
2383 int fd = open ("/proc/self/cmdline", O_RDONLY|O_BINARY);
2386 if (fstat (fd, &stat_buf))
2389 if (stat_buf.st_size > 0 && S_ISREG (stat_buf.st_mode))
2391 if (read (fd, result, BUFSIZE) <= 0)
2396 FILE *f = fdopen (fd, "r");
2400 if (fread (result, 1, BUFSIZE, f) <= 0)
2410 exit (__getcmdline ());
2414 rres = cc.run(cmdline_test_code, name : '/proc/self/cmdline')
2415 have_proc_self_cmdline = rres.compiled() and rres.returncode() == 0
2417 have_proc_self_cmdline = meson.get_external_property('have_proc_self_cmdline', false)
2420 glib_conf.set('HAVE_PROC_SELF_CMDLINE', have_proc_self_cmdline)
2422 python = import('python').find_installation(modules: ['packaging'])
2423 # used for '#!/usr/bin/env <name>'
2424 python_name = 'python3'
2426 python_version = python.language_version()
2427 python_version_req = '>=3.7'
2428 if not python_version.version_compare(python_version_req)
2429 error('Requires Python @0@, @1@ found.'.format(python_version_req, python_version))
2432 # Determine which user environment-dependent files that we want to install
2433 bash = find_program('bash', required : false)
2434 have_bash = bash.found() # For completion scripts
2435 bash_comp_dep = dependency('bash-completion', version: '>=2.0', required: false)
2436 have_sh = find_program('sh', required : false).found() # For glib-gettextize
2437 have_pkg_config = find_program('pkg-config', required: false).found()
2439 # Some installed tests require a custom environment
2440 env_program = find_program('env', required: installed_tests_enabled)
2442 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
2443 if host_system == 'sunos'
2444 glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
2445 glib_conf.set('_XOPEN_SOURCE', 2)
2446 glib_conf.set('__EXTENSIONS__',1)
2449 # Sadly Meson does not expose this value:
2450 # https://github.com/mesonbuild/meson/pull/3460
2451 if host_system == 'windows'
2452 # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
2453 # with no explanation. Do the same here for now but this could be revisited if
2455 export_dynamic_ldflags = []
2456 elif host_system == 'cygwin'
2457 export_dynamic_ldflags = ['-Wl,--export-all-symbols']
2458 elif host_system in ['darwin', 'ios']
2459 export_dynamic_ldflags = []
2460 elif host_system == 'sunos'
2461 export_dynamic_ldflags = []
2463 export_dynamic_ldflags = ['-Wl,--export-dynamic']
2468 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
2469 # Ensure MSVC-compatible struct packing convention is used when
2470 # compiling for Win32 with gcc. It is used for the whole project and exposed
2472 if not cc.compiles('''
2473 struct _GTestMSBitfields
2479 typedef char _StaticCheck[sizeof(struct _GTestMSBitfields) != sizeof(int) ? 1 : -1];
2482 Your compiler does not have ms-bitfields packing by default.
2483 Please use gcc >= 4.7 or clang >= 12: GLib will drop -mms-bitfields in the future.
2486 win32_cflags = ['-mms-bitfields']
2487 add_project_arguments(win32_cflags, language : 'c')
2489 # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
2490 win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi', '-luuid']
2491 elif host_system == 'cygwin'
2492 win32_ldflags = ['-luser32', '-lkernel32']
2496 want_dtrace = get_option('dtrace')
2497 enable_dtrace = false
2499 # Since dtrace support is opt-in we just error out if it was requested but
2500 # is not available. We don't bother with autodetection yet.
2503 error('GLib dtrace support not yet compatible with macOS dtrace')
2505 dtrace = find_program('dtrace', required : true) # error out if not found
2506 if not cc.has_header('sys/sdt.h')
2507 error('dtrace support needs sys/sdt.h header')
2509 # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
2510 dtrace_obj_gen = generator(dtrace,
2511 output : '@BASENAME@.o',
2512 arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2513 dtrace_hdr_gen = generator(python,
2514 output : '@BASENAME@.h',
2515 arguments : ['-c', '''
2516 import subprocess, sys
2517 subprocess.run(sys.argv[1:], check=True)
2518 output = sys.argv[6]
2519 with open(output) as f:
2521 contents = contents.replace("define STAP_HAS_SEMAPHORES 1",
2522 "undef STAP_HAS_SEMAPHORES")
2523 contents = contents.replace("define _SDT_HAS_SEMAPHORES 1",
2524 "undef _SDT_HAS_SEMAPHORES")
2525 with open(output, "w") as f:
2527 ''', dtrace.full_path(), '-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2528 glib_conf.set('HAVE_DTRACE', 1)
2529 enable_dtrace = true
2532 if cc.has_header_symbol('sys/ptrace.h', 'PTRACE_O_EXITKILL')
2533 glib_conf.set('HAVE_PTRACE_O_EXITKILL', 1)
2537 want_systemtap = get_option('systemtap')
2538 enable_systemtap = false
2540 if want_systemtap and enable_dtrace
2541 tapset_install_dir = get_option('tapset_install_dir')
2542 if tapset_install_dir == ''
2543 tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
2545 stp_cdata = configuration_data()
2546 stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
2547 stp_cdata.set('LT_CURRENT', minor_version * 100)
2548 stp_cdata.set('LT_REVISION', micro_version)
2549 enable_systemtap = true
2553 gir_scanner = find_program('g-ir-scanner', required: get_option('introspection'))
2554 enable_gir = get_option('introspection').allowed() and gir_scanner.found() and meson.can_run_host_binaries()
2556 if get_option('introspection').enabled() and not meson.can_run_host_binaries()
2557 error('Running binaries on the build host needs to be supported to build with -Dintrospection=enabled')
2564 pkg = import('pkgconfig')
2565 windows = import('windows')
2566 gnome = import('gnome')
2574 subdir('girepository')
2578 # xgettext is optional (on Windows for instance)
2579 if find_program('xgettext', required : get_option('nls')).found()
2583 # Install m4 macros that other projects use
2584 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
2585 install_dir : get_option('datadir') / 'aclocal',
2586 install_tag : 'devel',
2589 # Check whether we support overriding the invalid parameter handler on Windows for _get_osfhandle(),
2590 # g_fsync() (i.e. _commit()), etc
2591 if host_system == 'windows'
2592 if cc.has_function('_set_thread_local_invalid_parameter_handler', prefix: '#include <stdlib.h>')
2593 glib_conf.set('HAVE__SET_THREAD_LOCAL_INVALID_PARAMETER_HANDLER', 1)
2595 if cc.has_function('_set_invalid_parameter_handler', prefix: '#include <stdlib.h>')
2596 glib_conf.set('HAVE__SET_INVALID_PARAMETER_HANDLER', 1)
2598 if cc.has_header_symbol('crtdbg.h', '_CrtSetReportMode')
2599 glib_conf.set('HAVE__CRT_SET_REPORT_MODE', 1)
2603 configure_file(output : 'config.h', configuration : glib_conf)
2605 rst2man = find_program('rst2man', 'rst2man.py', required: get_option('man-pages'))
2608 '--syntax-highlight=none',
2610 man1_dir = join_paths(glib_prefix, get_option('mandir'), 'man1')
2613 gnome = import('gnome')
2614 subdir('docs/reference')
2617 'host cpu' : host_machine.cpu_family(),
2618 'host endian' : host_machine.endian(),
2619 'host system' : host_system,
2620 'C Compiler' : cc.get_id(),
2621 'C++ Compiler' : have_cxx ? cxx.get_id() : 'none',
2622 'shared build' : glib_build_shared,
2623 'static build' : glib_build_static,
2624 }, section: 'Build environment')
2626 if build_machine.system() != host_system
2628 'build cpu' : build_machine.cpu_family(),
2629 'build endian' : build_machine.endian(),
2630 'build system' : build_machine.system(),
2631 }, section: 'Build environment')
2636 'linux_libc' : linux_libc
2637 }, section: 'Build environment')
2641 'prefix' : glib_prefix,
2642 'bindir' : glib_bindir,
2643 'libexecdir' : glib_libexecdir,
2644 'pkgdatadir' : glib_pkgdatadir,
2645 'datadir' : glib_datadir,
2646 'includedir' : glib_includedir,
2647 'giomodulesdir' : glib_giomodulesdir,
2648 'localstatedir' : glib_localstatedir,
2649 'runstatedir' : glib_runstatedir,
2650 }, section: 'Directories')
2652 if get_option('multiarch')
2654 'multiarch bindir' : glib_bindir,
2655 'multiarch libexecdir' : glib_libexecdir,
2656 }, section: 'Directories')
2660 summary('tapset dir', get_option('tapset_install_dir'), section: 'Directories')
2663 if host_system == 'linux'
2665 'selinux' : selinux_dep.found(),
2666 'libmount' : libmount_dep.found(),
2667 }, section: 'Options')
2671 'xattr' : xattr_dep.length() > 0,
2672 'man-pages' : get_option('man-pages'),
2673 'dtrace' : get_option('dtrace'),
2674 'systemtap' : enable_systemtap,
2675 'sysprof' : libsysprof_capture_dep.found(),
2676 'documentation' : get_option('documentation'),
2677 'bsymbolic_functions' : get_option('bsymbolic_functions'),
2678 'force_posix_threads' : get_option('force_posix_threads'),
2679 'tests' : get_option('tests'),
2680 'installed_tests' : get_option('installed_tests'),
2681 'nls' : get_option('nls'),
2682 'oss_fuzz' : get_option('oss_fuzz'),
2683 'glib_debug' : get_option('glib_debug'),
2684 'glib_assert' : get_option('glib_assert'),
2685 'glib_checks' : get_option('glib_checks'),
2686 'libelf' : get_option('libelf'),
2687 'multiarch' : get_option('multiarch'),
2688 'introspection' : enable_gir,
2689 }, section: 'Options')