3 # NOTE: See the policy in docs/meson-version.md before changing the Meson dependency
4 meson_version : '>= 0.60.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')
68 glib_version = meson.project_version()
69 glib_api_version = '2.0'
70 version_arr = glib_version.split('.')
71 major_version = version_arr[0].to_int()
72 minor_version = version_arr[1].to_int()
73 micro_version = version_arr[2].to_int()
75 interface_age = minor_version.is_odd() ? 0 : micro_version
76 binary_age = 100 * minor_version + micro_version
79 # Maintain compatibility with previous libtool versioning
80 # current = minor * 100 + micro
81 current = binary_age - interface_age
82 library_version = '@0@.@1@.@2@'.format(soversion, current, interface_age)
83 darwin_versions = [current + 1, '@0@.@1@'.format(current + 1, interface_age)]
85 configinc = include_directories('.')
86 glibinc = include_directories('glib')
87 gobjectinc = include_directories('gobject')
88 gmoduleinc = include_directories('gmodule')
89 gioinc = include_directories('gio')
91 glib_prefix = get_option('prefix')
92 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
93 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
94 glib_libexecdir = join_paths(glib_prefix, get_option('libexecdir'))
95 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
96 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
97 glib_includedir = join_paths(glib_prefix, get_option('includedir'), 'glib-2.0')
98 if get_option('gio_module_dir') != ''
99 glib_giomodulesdir = join_paths(glib_prefix, get_option('gio_module_dir'))
101 glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
104 if get_option('multiarch')
105 # For multiarch/multilib distributions, install each architecture's
106 # build of executables used in packaging triggers (like gio-querymodules)
107 # to an architecture-dependent location, with a compatibility symlink
109 multiarch_bindir = get_option('libdir') / 'glib-2.0'
110 multiarch_libexecdir = multiarch_bindir
111 pkgconfig_multiarch_bindir = '${libdir}/glib-2.0'
113 # For single-architecture distributions, just install them into the PATH
114 # as was traditionally done.
115 multiarch_bindir = get_option('bindir')
116 multiarch_libexecdir = get_option('libexecdir')
117 pkgconfig_multiarch_bindir = '${bindir}'
120 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
122 if get_option('charsetalias_dir') != ''
123 glib_charsetaliasdir = join_paths(glib_prefix, get_option('charsetalias_dir'))
125 glib_charsetaliasdir = glib_libdir
128 glib_localstatedir = glib_prefix / get_option('localstatedir')
130 if get_option('runtime_dir') != ''
131 glib_runstatedir = glib_prefix / get_option('runtime_dir')
133 # While we’d normally prefix directories like this with, for example,
134 # glib_localstatedir, `/run` is a bit different in that it’s for runtime state
135 # rather than data files, so it’s typically functionally useless to use a
136 # prefixed version. No other processes will be using it. So we default to the
137 # unprefixed system `/run` directory.
138 glib_runstatedir = '/run'
141 # When building glib and gobject-introspection with subprojects, gobject-introspection
142 # requires to know the path of the sources and the build directory for the subproject.
143 # We provide it here with a variable.
144 glib_source_dir = meson.current_source_dir()
145 glib_build_dir = meson.current_build_dir()
147 installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
148 installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
149 installed_tests_enabled = get_option('installed_tests')
150 installed_tests_template = files('tests/template.test.in')
151 installed_tests_template_tap = files('tests/template-tap.test.in')
153 # Don’t build the tests unless we can run them (either natively, in an exe wrapper, or by installing them for later use)
154 build_tests = get_option('tests') and (meson.can_run_host_binaries() or installed_tests_enabled)
157 'G_DEBUG=gc-friendly',
158 'G_ENABLE_DIAGNOSTIC=1',
162 # Note: this may cause the tests output not to be printed when running in
163 # verbose mode, see https://github.com/mesonbuild/meson/issues/11185
164 # Can be changed it to 'exitcode' if required during development.
165 test_protocol = 'tap'
167 test_timeout_slow = 90
169 add_test_setup('default',
171 exclude_suites: ['flaky', 'failing'],
172 env: common_test_env,
173 timeout_multiplier: 2,
176 add_test_setup('unstable_tests',
177 env: common_test_env,
178 timeout_multiplier: 2,
179 # Empty test setup, used for having different results set for flaky tests
180 # Sadly we can't use (https://github.com/mesonbuild/meson/issues/10934):
181 #suites: ['flaky', 'unstable']
184 # Allow the tests to be easily run under valgrind using --setup=valgrind
185 valgrind = find_program('valgrind', required: false)
186 valgrind_suppression_file = files('tools' / 'glib.supp')[0]
187 valgrind_suppression_file_install_subdir = 'glib-2.0' / 'valgrind'
190 add_test_setup('valgrind',
191 exclude_suites: [ 'no-valgrind', 'flaky' ],
195 '--error-exitcode=1',
196 '--track-origins=yes',
198 '--leak-resolution=high',
200 '--show-leak-kinds=definite,possible',
201 '--show-error-list=yes',
202 '--suppressions=@0@'.format(meson.project_source_root() /
203 '@0@'.format(valgrind_suppression_file)),
205 env: common_test_env,
206 timeout_multiplier: 20,
210 add_project_arguments('-D_GNU_SOURCE', language: 'c')
212 if host_system == 'qnx'
213 add_project_arguments('-D_QNX_SOURCE', language: 'c')
216 # Disable strict aliasing;
217 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
218 if cc.has_argument('-fno-strict-aliasing')
219 add_project_arguments('-fno-strict-aliasing', language: 'c')
222 # dummy/empty dependency() object to declare fallbacks and simpler dependencies
223 not_found = dependency('', required: false)
225 ########################
226 # Configuration begins #
227 ########################
228 glib_conf = configuration_data()
229 glibconfig_conf = configuration_data()
231 # accumulated list of defines as we check for them, so we can easily
232 # use them later in test programs (autoconf does this automatically)
233 glib_conf_prefix = ''
235 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
236 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
237 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
238 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
239 glib_conf.set('GLIB_BINARY_AGE', binary_age)
240 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
241 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
242 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
243 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
244 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
245 glib_conf.set_quoted('PACKAGE_URL', '')
246 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
247 glib_conf.set('ENABLE_NLS', 1)
249 # used by the .rc.in files
250 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
252 glib_conf.set('_GNU_SOURCE', 1)
254 if host_system in ['windows', 'darwin']
255 # Poll doesn't work on devices on Windows, and macOS's poll() implementation is known to be broken
256 glib_conf.set('BROKEN_POLL', true)
259 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
260 # FIXME: Ideally we shouldn't depend on this on Windows and should use
261 # 64 bit capable Windows API that also works with MSVC.
262 # The autotools build did set this for mingw and while meson sets it
263 # for gcc/clang by default, it doesn't do so on Windows.
264 glib_conf.set('_FILE_OFFSET_BITS', 64)
267 glib_build_shared = false
268 glib_build_static = false
269 if get_option('default_library') == 'both'
270 glib_build_static = true
271 glib_build_shared = true
272 elif get_option('default_library') == 'static'
273 glib_build_static = true
274 elif get_option('default_library') == 'shared'
275 glib_build_shared = true
278 glib_build_both = glib_build_static and glib_build_shared
279 glib_build_static_only = glib_build_static and not glib_build_shared
280 glib_build_shared_only = glib_build_shared and not glib_build_static
282 if glib_build_shared and glib_build_static and (
283 host_system == 'windows' or host_system == 'cygwin')
284 error('On Windows default_library must be "shared" or "static" but not "both"')
287 if glib_build_static_only
288 glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
289 glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
290 glibconfig_conf.set('GIO_STATIC_COMPILATION', '1')
291 glibconfig_conf.set('GMODULE_STATIC_COMPILATION', '1')
292 glibconfig_conf.set('G_INTL_STATIC_COMPILATION', '1')
293 glibconfig_conf.set('FFI_STATIC_BUILD', '1')
296 # Cygwin glib port maintainers made it clear
297 # (via the patches they apply) that they want no
298 # part of glib W32 code, therefore we do not define
299 # G_PLATFORM_WIN32 for host_system == 'cygwin'.
300 # This makes G_PLATFORM_WIN32 a synonym for
302 if host_system == 'windows'
303 glib_os = '''#define G_OS_WIN32
304 #define G_PLATFORM_WIN32'''
305 elif host_system == 'cygwin'
306 glib_os = '''#define G_OS_UNIX
307 #define G_WITH_CYGWIN'''
309 glib_os = '#define G_OS_UNIX'
311 glibconfig_conf.set('glib_os', glib_os)
313 # We need to know the CRT being used to determine what .lib files we need on
314 # Visual Studio for dependencies that don't normally come with pkg-config files
316 vs_crt_opt = get_option('b_vscrt')
317 if vs_crt_opt in ['mdd', 'mtd']
319 elif vs_crt_opt == 'from_buildtype'
320 if get_option('buildtype') == 'debug'
325 # Use debug/optimization flags to determine whether to enable debug or disable
326 # cast checks. We have a non-production (debug) build if debug is true and if
327 # optimization is 0 or g; otherwise, we have a production build.
328 glib_debug_cflags = []
329 glib_debug = get_option('glib_debug')
330 if (glib_debug.enabled() or (
331 glib_debug.auto() and get_option('debug') and get_option('optimization') in [ '0', 'g' ]))
332 glib_debug_cflags += ['-DG_ENABLE_DEBUG']
333 message('Enabling various debug infrastructure')
335 glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
336 message('Disabling cast checks')
339 if not get_option('glib_assert')
340 glib_debug_cflags += ['-DG_DISABLE_ASSERT']
341 message('Disabling GLib asserts')
344 if not get_option('glib_checks')
345 glib_debug_cflags += ['-DG_DISABLE_CHECKS']
346 message('Disabling GLib checks')
349 add_project_arguments(glib_debug_cflags, language: 'c')
351 # check for header files
357 'dirent.h', # MSC does not come with this by default
392 'sys/time.h', # MSC does not come with this by default
409 define = 'HAVE_' + h.underscorify().to_upper()
410 glib_conf.set(define, 1)
411 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
415 # FreeBSD includes a malloc.h which always throws compilation error, so we have
416 # to use check_header() rather than has_header().
417 if cc.check_header('malloc.h')
418 glib_conf.set('HAVE_MALLOC_H', 1)
419 glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
422 if cc.check_header('linux/netlink.h')
423 glib_conf.set('HAVE_NETLINK', 1)
426 # Is statx() supported? Android systems don’t reliably support it as of August 2020.
431 #include <sys/stat.h>
435 struct statx stat_buf;
436 return statx (AT_FDCWD, "/", AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS | STATX_BTIME, &stat_buf);
439 if host_system != 'android' and cc.compiles(statx_code, name : 'statx() test')
440 glib_conf.set('HAVE_STATX', 1)
443 if glib_conf.has('HAVE_LOCALE_H')
444 if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
445 glib_conf.set('HAVE_LC_MESSAGES', 1)
449 struct_stat_blkprefix = '''
450 #include <sys/types.h>
451 #include <sys/stat.h>
455 #ifdef HAVE_SYS_STATFS_H
456 #include <sys/statfs.h>
458 #ifdef HAVE_SYS_PARAM_H
459 #include <sys/param.h>
461 #ifdef HAVE_SYS_MOUNT_H
462 #include <sys/mount.h>
467 [ 'stat', 'st_mtimensec' ],
468 [ 'stat', 'st_mtim.tv_nsec' ],
469 [ 'stat', 'st_atimensec' ],
470 [ 'stat', 'st_atim.tv_nsec' ],
471 [ 'stat', 'st_ctimensec' ],
472 [ 'stat', 'st_ctim.tv_nsec' ],
473 [ 'stat', 'st_birthtime' ],
474 [ 'stat', 'st_birthtimensec' ],
475 [ 'stat', 'st_birthtim' ],
476 [ 'stat', 'st_birthtim.tv_nsec' ],
477 [ 'stat', 'st_blksize', struct_stat_blkprefix ],
478 [ 'stat', 'st_blocks', struct_stat_blkprefix ],
479 [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
480 [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
481 [ 'dirent', 'd_type', '''#include <sys/types.h>
482 #include <dirent.h>''' ],
483 [ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
484 [ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
485 [ 'tm', 'tm_gmtoff', '#include <time.h>' ],
486 [ 'tm', '__tm_gmtoff', '#include <time.h>' ],
489 foreach m : struct_members
490 header_check_prefix = glib_conf_prefix
492 header_check_prefix = header_check_prefix + m[2]
494 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
496 if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
497 define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
498 glib_conf.set(define, 1)
499 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
505 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
506 warning_common_args = [
507 '-Wduplicated-branches',
508 '-Wimplicit-fallthrough',
509 '-Wmisleading-indentation',
510 '-Wmissing-field-initializers',
513 # Due to maintained deprecated code, we do not want to see unused parameters
514 '-Wno-unused-parameter',
515 # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
516 # building with -Wbad-function-cast.
517 '-Wno-cast-function-type',
518 # Due to function casts through (void*) we cannot support -Wpedantic:
519 # ./docs/toolchain-requirements.md#Function_pointer_conversions.
521 # A zero-length format string shouldn't be considered an issue.
522 '-Wno-format-zero-length',
523 # We explicitly require variadic macros
524 '-Wno-variadic-macros',
527 '-Werror=missing-include-dirs',
528 '-Werror=pointer-arith',
529 '-Werror=unused-result',
532 warning_c_args = warning_common_args + [
533 '-Wstrict-prototypes',
534 # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
535 # building with -Wbad-function-cast.
536 '-Wno-bad-function-cast',
537 '-Werror=implicit-function-declaration',
538 '-Werror=missing-prototypes',
539 '-Werror=pointer-sign',
540 '-Wno-string-plus-int',
542 warning_cxx_args = warning_common_args
543 warning_objc_args = warning_c_args
544 warning_c_link_args = [
547 if get_option('bsymbolic_functions')
548 warning_c_link_args += ['-Wl,-Bsymbolic-functions']
550 elif cc.get_id() == 'msvc'
552 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
553 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
554 # NOTE: Only add warnings here if you are sure they're spurious
555 '/wo4057', # 'operator': 'identifier1' differs in indirection to slightly different base types from 'identifier2'
556 '/wd4068', # unknown pragma
557 '/wo4090', # 'operation': different 'modifier' qualifiers
558 '/wd4100', # 'identifier': unreferenced formal parameter
559 '/wd4116', # unnamed type definition in parentheses
560 '/wo4125', # decimal digit terminates octal escape sequence
561 '/wd4127', # conditional expression is constant
562 '/wd4146', # unary minus operator applied to unsigned type, result still unsigned
563 '/wd4152', # nonstandard extension, function/data pointer conversion in expression
564 '/wd4201', # nonstandard extension used: nameless struct/union
565 '/wd4232', # nonstandard extension used: 'identifier': address of dllimport 'dllimport' is not static, identity not guaranteed
566 '/wo4245', # 'conversion_type': conversion from 'type1' to 'type2', signed/unsigned mismatch
567 '/wo4267', # 'variable': conversion from 'size_t' to 'type', possible loss of data
568 '/wd4334', # 'shift_operator': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
569 '/wo4389', # 'operator': signed/unsigned mismatch
570 '/wo4702', # unreachable code
571 '/wd4706', # assignment within conditional expression
574 warning_cxx_args = []
575 warning_objc_args = []
576 warning_c_link_args = []
579 warning_cxx_args = []
580 warning_objc_args = []
581 warning_c_link_args = []
584 add_project_arguments(cc.get_supported_arguments(warning_c_args), language: 'c')
586 add_project_arguments(cxx.get_supported_arguments(warning_cxx_args), language: 'cpp')
589 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
590 # means we cannot use that flag in add_project_link_arguments(), and must add
591 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
592 # because that is what the autotools build did.
593 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
595 glib_link_flags = cc.get_supported_link_arguments(warning_c_link_args)
597 # Windows SDK requirements and checks
598 if host_system == 'windows'
599 # Check whether we're building for UWP apps
602 #if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
603 #error "Not building for UWP"
605 if cc.compiles(code, name : 'building for UWP')
606 glib_conf.set('G_WINAPI_ONLY_APP', true)
607 # We require Windows 10+ on WinRT
608 glib_conf.set('_WIN32_WINNT', '0x0A00')
609 uwp_gio_deps = [cc.find_library('shcore'),
610 cc.find_library('runtimeobject')]
612 # We require Windows 7+ on Win32
613 glib_conf.set('_WIN32_WINNT', '0x0601')
629 'free_aligned_sized',
684 # _NSGetEnviron is available on iOS too, but its usage gets apps rejected from
685 # the app store since it's considered 'private API'
686 if host_system == 'darwin'
687 functions += ['_NSGetEnviron']
690 if glib_conf.has('HAVE_SYS_STATVFS_H')
691 functions += ['statvfs']
693 have_func_statvfs = false
695 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
696 functions += ['statfs']
698 have_func_statfs = false
700 if glib_conf.has('HAVE_SYS_PRCTL_H')
701 functions += ['prctl']
703 have_func_prctl = false
706 if host_system == 'windows'
707 iphlpapi_dep = cc.find_library('iphlpapi')
708 iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
709 foreach ifunc : iphlpapi_funcs
710 iphl_prefix = '''#define _WIN32_WINNT @0@
711 #include <winsock2.h>
712 #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
713 if cc.has_function(ifunc,
714 prefix : iphl_prefix,
715 dependencies : iphlpapi_dep)
716 idefine = 'HAVE_' + ifunc.underscorify().to_upper()
717 glib_conf.set(idefine, 1)
718 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
719 set_variable('have_func_' + ifunc, true)
721 set_variable('have_func_' + ifunc, false)
725 functions += ['if_indextoname', 'if_nametoindex']
728 # AIX splice is something else
729 if host_system != 'aix'
730 functions += ['splice']
733 foreach f : functions
734 if cc.has_function(f)
735 define = 'HAVE_' + f.underscorify().to_upper()
736 glib_conf.set(define, 1)
737 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
738 set_variable('have_func_' + f, true)
740 set_variable('have_func_' + f, false)
744 # Export the information about free_sized() so we can correctly define a macro
745 # wrapper around g_free()/g_free_sized() depending on whether it’s available
746 glibconfig_conf.set('G_HAVE_FREE_SIZED', have_func_free_sized)
748 # Check that stpcpy() is usable; must use header.
750 # https://github.com/mesonbuild/meson/issues/5628.
751 if cc.has_function('stpcpy', prefix : '#include <string.h>')
752 glib_conf.set('HAVE_STPCPY', 1)
755 if cc.has_function('memalign', prefix: '#include <stdlib.h>\n#include <malloc.h>')
756 glib_conf.set('HAVE_MEMALIGN', 1)
759 # For example on Openbsd, getservbyname_r() has a different signature.
760 # https://man.openbsd.org/getservbyname.3
761 if cc.compiles('''#include <netdb.h>
762 int main (int argc, char ** argv) {
763 int (*fcn)(const char *,
768 struct servent **) = getservbyname_r;
772 name : 'getservbyname_r()',
773 args: '-Werror=incompatible-pointer-types')
774 glib_conf.set('HAVE_GETSERVBYNAME_R', 1)
777 if cc.has_function('_aligned_malloc', prefix: '#include <malloc.h>')
778 glib_conf.set('HAVE__ALIGNED_MALLOC', 1)
781 if host_system != 'windows' and cc.has_function('aligned_alloc', prefix: '#include <stdlib.h>')
782 glib_conf.set('HAVE_ALIGNED_ALLOC', 1)
785 if host_system != 'windows' and cc.has_function('posix_memalign', prefix: '#include <stdlib.h>')
786 glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
789 # Check that posix_spawn() is usable; must use header
790 if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
791 glib_conf.set('HAVE_POSIX_SPAWN', 1)
794 # Check whether strerror_r returns char *
795 if have_func_strerror_r
796 if cc.compiles('''#define _GNU_SOURCE
799 char error_string[256];
800 char *ptr = strerror_r (-2, error_string, 256);
801 char c = *strerror_r (-2, error_string, 256);
802 return c != 0 && ptr != (void*) 0L;
805 name : 'strerror_r() returns char *')
806 glib_conf.set('STRERROR_R_CHAR_P', 1,
807 description: 'Defined if strerror_r returns char *')
811 # Special-case these functions that have alternative names on Windows/MSVC
812 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
813 glib_conf.set('HAVE_SNPRINTF', 1)
814 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
815 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
816 hack_define = '1\n#define snprintf _snprintf'
817 glib_conf.set('HAVE_SNPRINTF', hack_define)
818 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
821 if cc.has_function('strcasecmp', prefix: '#include <strings.h>')
822 glib_conf.set('HAVE_STRCASECMP', 1)
823 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
824 elif cc.has_function('_stricmp')
825 hack_define = '1\n#define strcasecmp _stricmp'
826 glib_conf.set('HAVE_STRCASECMP', hack_define)
827 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
830 if cc.has_function('strncasecmp', prefix: '#include <strings.h>')
831 glib_conf.set('HAVE_STRNCASECMP', 1)
832 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
833 elif cc.has_function('_strnicmp')
834 hack_define = '1\n#define strncasecmp _strnicmp'
835 glib_conf.set('HAVE_STRNCASECMP', hack_define)
836 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
839 if cc.has_header_symbol('sys/sysmacros.h', 'major')
840 glib_conf.set('MAJOR_IN_SYSMACROS', 1)
841 elif cc.has_header_symbol('sys/mkdev.h', 'major')
842 glib_conf.set('MAJOR_IN_MKDEV', 1)
843 elif cc.has_header_symbol('sys/types.h', 'major')
844 glib_conf.set('MAJOR_IN_TYPES', 1)
847 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
848 glib_conf.set('HAVE_RTLD_LAZY', 1)
851 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
852 glib_conf.set('HAVE_RTLD_NOW', 1)
855 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
856 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
859 have_rtld_next = false
860 if cc.has_header_symbol('dlfcn.h', 'RTLD_NEXT', args: '-D_GNU_SOURCE')
861 have_rtld_next = true
862 glib_conf.set('HAVE_RTLD_NEXT', 1)
865 if cc.has_type('loff_t', prefix: '#include <sys/types.h>')
866 glib_conf.set('HAVE_LOFF_T', 1)
869 # Check whether to use statfs or statvfs
870 # Some systems have both statfs and statvfs, pick the most "native" for these
871 if have_func_statfs and have_func_statvfs
872 # on solaris and irix, statfs doesn't even have the f_bavail field
873 if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
874 have_func_statfs = false
876 # at least on linux, statfs is the actual syscall
877 have_func_statvfs = false
881 glib_conf.set('USE_STATFS', 1)
882 stat_func_to_use = 'statfs'
883 elif have_func_statvfs
884 glib_conf.set('USE_STATVFS', 1)
885 stat_func_to_use = 'statvfs'
887 stat_func_to_use = 'neither'
889 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
891 if host_system == 'linux'
892 if cc.has_function('mkostemp',
893 prefix: '''#define _GNU_SOURCE
894 #include <stdlib.h>''')
895 glib_conf.set('HAVE_MKOSTEMP', 1)
900 glib_have_os_x_9_or_later = false
901 glib_have_carbon = false
902 glib_have_cocoa = false
903 if host_system == 'darwin'
904 add_languages('objc', native: false, required: true)
905 objcc = meson.get_compiler('objc')
907 add_project_arguments(objcc.get_supported_arguments(warning_objc_args), language: 'objc')
909 # Mac OS X Carbon support
910 glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
911 #include <CoreServices/CoreServices.h>''',
912 name : 'Mac OS X Carbon support')
915 glib_conf.set('HAVE_CARBON', true)
916 glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
917 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
918 #error Compiling for minimum OS X version before 10.9
920 name : 'OS X 9 or later')
923 # Mac OS X Cocoa support
924 glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
925 #ifdef GNUSTEP_BASE_VERSION
926 #error "Detected GNUstep, not Cocoa"
928 name : 'Mac OS X Cocoa support')
931 glib_conf.set('HAVE_COCOA', true)
932 osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
936 if host_system == 'qnx'
937 glib_conf.set('HAVE_QNX', 1)
941 if cc.compiles('''#include <linux/futex.h>
942 #include <sys/syscall.h>
944 int main (int argc, char ** argv) {
945 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
947 }''', name : 'futex(2) system call')
948 glib_conf.set('HAVE_FUTEX', 1)
950 if cc.compiles('''#include <linux/futex.h>
951 #include <sys/syscall.h>
953 int main (int argc, char ** argv) {
954 syscall (__NR_futex_time64, NULL, FUTEX_WAKE, FUTEX_WAIT);
956 }''', name : 'futex(2) system call')
957 glib_conf.set('HAVE_FUTEX_TIME64', 1)
960 # Check for eventfd(2)
961 if cc.links('''#include <sys/eventfd.h>
963 int main (int argc, char ** argv) {
964 eventfd (0, EFD_CLOEXEC);
966 }''', name : 'eventfd(2) system call')
967 glib_conf.set('HAVE_EVENTFD', 1)
970 # Check for pidfd_open(2)
971 if cc.links('''#include <sys/syscall.h>
972 #include <sys/wait.h>
973 #include <linux/wait.h>
975 int main (int argc, char ** argv) {
976 siginfo_t child_info = { 0, };
977 syscall (SYS_pidfd_open, 0, 0);
978 waitid (P_PIDFD, 0, &child_info, WEXITED | WNOHANG);
980 }''', name : 'pidfd_open(2) system call')
981 glib_conf.set('HAVE_PIDFD', 1)
984 # Check for __uint128_t (gcc) by checking for 128-bit division
985 uint128_t_src = '''int main() {
986 static __uint128_t v1 = 100;
987 static __uint128_t v2 = 10;
988 static __uint128_t u;
991 if cc.compiles(uint128_t_src, name : '__uint128_t available')
992 glib_conf.set('HAVE_UINT128_T', 1)
995 clock_gettime_test_code = '''
998 int main (int argc, char ** argv) {
999 return clock_gettime(CLOCK_REALTIME, &t);
1002 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
1003 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
1004 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
1005 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
1006 librt = cc.find_library('rt')
1009 dlopen_dlsym_test_code = '''
1013 int glib_underscore_test (void) { return 42; }
1014 int main (int argc, char ** argv) {
1015 void *f1 = (void*)0, *f2 = (void*)0, *handle;
1016 handle = dlopen ((void*)0, 0);
1018 f1 = dlsym (handle, "glib_underscore_test");
1019 f2 = dlsym (handle, "_glib_underscore_test");
1021 r = (!f2 || f1) ? puts ("1") : puts ("0");
1022 return r > 0 ? 0 : r;
1025 if cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
1026 have_dlopen_dlsym = true
1027 elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
1028 have_dlopen_dlsym = true
1029 libdl_dep = cc.find_library('dl')
1031 have_dlopen_dlsym = false
1034 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
1036 if cc.compiles(glib_conf_prefix + '''
1038 #ifdef HAVE_SYS_PARAM_H
1039 #include <sys/param.h>
1041 #ifdef HAVE_SYS_VFS_H
1042 #include <sys/vfs.h>
1044 #ifdef HAVE_SYS_MOUNT_H
1045 #include <sys/mount.h>
1047 #ifdef HAVE_SYS_STATFS_H
1048 #include <sys/statfs.h>
1050 void some_func (void) {
1053 }''', name : 'number of arguments to statfs() (n=2)')
1054 glib_conf.set('STATFS_ARGS', 2)
1055 elif cc.compiles(glib_conf_prefix + '''
1057 #ifdef HAVE_SYS_PARAM_H
1058 #include <sys/param.h>
1060 #ifdef HAVE_SYS_VFS_H
1061 #include <sys/vfs.h>
1063 #ifdef HAVE_SYS_MOUNT_H
1064 #include <sys/mount.h>
1066 #ifdef HAVE_SYS_STATFS_H
1067 #include <sys/statfs.h>
1069 void some_func (void) {
1071 statfs("/", &st, sizeof (st), 0);
1072 }''', name : 'number of arguments to statfs() (n=4)')
1073 glib_conf.set('STATFS_ARGS', 4)
1075 error('Unable to determine number of arguments to statfs()')
1079 # open takes O_DIRECTORY as an option
1080 #AC_MSG_CHECKING([])
1081 if cc.compiles('''#include <fcntl.h>
1082 #include <sys/types.h>
1083 #include <sys/stat.h>
1084 void some_func (void) {
1085 open(0, O_DIRECTORY, 0);
1086 }''', name : 'open() option O_DIRECTORY')
1087 glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
1090 # fcntl takes F_FULLFSYNC as an option
1091 # See https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html
1092 if cc.compiles('''#include <fcntl.h>
1093 #include <sys/types.h>
1094 #include <sys/stat.h>
1095 void some_func (void) {
1096 fcntl(0, F_FULLFSYNC, 0);
1097 }''', name : 'fcntl() option F_FULLFSYNC')
1098 glib_conf.set('HAVE_FCNTL_F_FULLFSYNC', 1)
1101 # Check whether there is a vsnprintf() function with C99 semantics installed.
1102 # (similar tests to AC_FUNC_VSNPRINTF_C99)
1103 # Check whether there is a snprintf() function with C99 semantics installed.
1104 # (similar tests to AC_FUNC_SNPRINTF_C99)
1105 # Check whether there is a printf() function with Unix98 semantics installed.
1106 # (similar tests to AC_FUNC_PRINTF_UNIX98)
1107 have_good_vsnprintf = false
1108 have_good_snprintf = false
1109 have_good_printf = false
1111 if host_system == 'windows' and (cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl')
1112 # Unfortunately the Visual Studio 2015+ implementations of C99-style
1113 # snprintf and vsnprintf don't seem to be quite good enough.
1114 # (Sorry, I don't know exactly what is the problem,
1115 # but it is related to floating point formatting and decimal point vs. comma.)
1116 # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
1117 # rigorous enough to notice, though.
1118 glib_conf.set('HAVE_C99_SNPRINTF', false)
1119 glib_conf.set('HAVE_C99_VSNPRINTF', false)
1120 glib_conf.set('HAVE_UNIX98_PRINTF', false)
1121 elif not cc_can_run and host_system in ['ios', 'darwin']
1122 # All these are true when compiling natively on macOS, so we should use good
1123 # defaults when building for iOS and tvOS.
1124 glib_conf.set('HAVE_C99_SNPRINTF', true)
1125 glib_conf.set('HAVE_C99_VSNPRINTF', true)
1126 glib_conf.set('HAVE_UNIX98_PRINTF', true)
1127 have_good_vsnprintf = true
1128 have_good_snprintf = true
1129 have_good_printf = true
1131 vsnprintf_c99_test_code = '''
1144 r = vsnprintf(buffer, 5, s, args);
1150 /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
1151 implementation. The above will return 7 but if you replace
1152 the size of the buffer with 0, it borks! */
1154 r = vsnprintf(buffer, 0, s, args);
1171 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
1172 if rres.compiled() and rres.returncode() == 0
1173 glib_conf.set('HAVE_C99_VSNPRINTF', 1)
1174 have_good_vsnprintf = true
1177 have_good_vsnprintf = meson.get_external_property('have_c99_vsnprintf', false)
1178 glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
1181 snprintf_c99_test_code = '''
1193 r = snprintf(buffer, 5, "1234567");
1198 r = snprintf(buffer, 0, "1234567");
1203 r = snprintf(NULL, 0, "1234567");
1219 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
1220 if rres.compiled() and rres.returncode() == 0
1221 glib_conf.set('HAVE_C99_SNPRINTF', 1)
1222 have_good_snprintf = true
1225 have_good_snprintf = meson.get_external_property('have_c99_snprintf', false)
1226 glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
1229 printf_unix98_test_code = '''
1239 sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
1240 if (strcmp ("2 3 1", buffer) == 0)
1246 rres = cc.run(printf_unix98_test_code, name : 'Unix98 printf positional parameters')
1247 if rres.compiled() and rres.returncode() == 0
1248 glib_conf.set('HAVE_UNIX98_PRINTF', 1)
1249 have_good_printf = true
1252 have_good_printf = meson.get_external_property('have_unix98_printf', false)
1253 glib_conf.set('HAVE_UNIX98_PRINTF', have_good_printf)
1257 if host_system == 'windows'
1258 glib_conf.set_quoted('EXEEXT', '.exe')
1260 glib_conf.set('EXEEXT', '')
1263 # Our printf is 'good' only if vsnpintf()/snprintf()/printf() supports C99 well enough
1264 use_system_printf = have_good_vsnprintf and have_good_snprintf and have_good_printf
1265 glib_conf.set('USE_SYSTEM_PRINTF', use_system_printf)
1266 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', use_system_printf)
1268 if not use_system_printf
1269 # gnulib has vasprintf so override the previous check
1270 glib_conf.set('HAVE_VASPRINTF', 1)
1273 # Check for nl_langinfo and CODESET
1274 if cc.links('''#include <langinfo.h>
1275 int main (int argc, char ** argv) {
1276 char *codeset = nl_langinfo (CODESET);
1278 }''', name : 'nl_langinfo and CODESET')
1279 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
1280 glib_conf.set('HAVE_CODESET', 1)
1283 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
1284 if cc.links('''#include <langinfo.h>
1285 int main (int argc, char ** argv) {
1287 str = nl_langinfo (PM_STR);
1288 str = nl_langinfo (D_T_FMT);
1289 str = nl_langinfo (D_FMT);
1290 str = nl_langinfo (T_FMT);
1291 str = nl_langinfo (T_FMT_AMPM);
1292 str = nl_langinfo (MON_1);
1293 str = nl_langinfo (ABMON_12);
1294 str = nl_langinfo (DAY_1);
1295 str = nl_langinfo (ABDAY_7);
1297 }''', name : 'nl_langinfo (PM_STR)')
1298 glib_conf.set('HAVE_LANGINFO_TIME', 1)
1300 if cc.links('''#include <langinfo.h>
1301 int main (int argc, char ** argv) {
1303 str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
1304 str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
1305 str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
1306 str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
1307 str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
1308 str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
1309 str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
1310 str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
1311 str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
1312 str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
1314 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
1315 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
1318 # Check for nl_langinfo and alternative month names
1319 if cc.links('''#ifndef _GNU_SOURCE
1320 # define _GNU_SOURCE
1322 #include <langinfo.h>
1323 int main (int argc, char ** argv) {
1325 str = nl_langinfo (ALTMON_1);
1326 str = nl_langinfo (ALTMON_2);
1327 str = nl_langinfo (ALTMON_3);
1328 str = nl_langinfo (ALTMON_4);
1329 str = nl_langinfo (ALTMON_5);
1330 str = nl_langinfo (ALTMON_6);
1331 str = nl_langinfo (ALTMON_7);
1332 str = nl_langinfo (ALTMON_8);
1333 str = nl_langinfo (ALTMON_9);
1334 str = nl_langinfo (ALTMON_10);
1335 str = nl_langinfo (ALTMON_11);
1336 str = nl_langinfo (ALTMON_12);
1338 }''', name : 'nl_langinfo (ALTMON_n)')
1339 glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
1342 # Check for nl_langinfo and abbreviated alternative month names
1343 if cc.links('''#ifndef _GNU_SOURCE
1344 # define _GNU_SOURCE
1346 #include <langinfo.h>
1347 int main (int argc, char ** argv) {
1349 str = nl_langinfo (_NL_ABALTMON_1);
1350 str = nl_langinfo (_NL_ABALTMON_2);
1351 str = nl_langinfo (_NL_ABALTMON_3);
1352 str = nl_langinfo (_NL_ABALTMON_4);
1353 str = nl_langinfo (_NL_ABALTMON_5);
1354 str = nl_langinfo (_NL_ABALTMON_6);
1355 str = nl_langinfo (_NL_ABALTMON_7);
1356 str = nl_langinfo (_NL_ABALTMON_8);
1357 str = nl_langinfo (_NL_ABALTMON_9);
1358 str = nl_langinfo (_NL_ABALTMON_10);
1359 str = nl_langinfo (_NL_ABALTMON_11);
1360 str = nl_langinfo (_NL_ABALTMON_12);
1362 }''', name : 'nl_langinfo (_NL_ABALTMON_n)')
1363 glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
1366 # Check for nl_langinfo and _NL_TIME_CODESET
1367 if cc.links('''#include <langinfo.h>
1368 int main (int argc, char ** argv) {
1369 char *codeset = nl_langinfo (_NL_TIME_CODESET);
1371 }''', name : 'nl_langinfo and _NL_TIME_CODESET')
1372 glib_conf.set('HAVE_LANGINFO_TIME_CODESET', 1)
1375 # Check if C compiler supports the 'signed' keyword
1376 if not cc.compiles('''signed char x;''', name : 'signed')
1377 glib_conf.set('signed', '/* NOOP */')
1380 # Check if the ptrdiff_t type exists
1381 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
1382 glib_conf.set('HAVE_PTRDIFF_T', 1)
1385 # Check for sig_atomic_t type
1386 if cc.links('''#include <signal.h>
1387 #include <sys/types.h>
1388 sig_atomic_t val = 42;
1389 int main (int argc, char ** argv) {
1390 return val == 42 ? 0 : 1;
1391 }''', name : 'sig_atomic_t')
1392 glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
1395 # Check if 'long long' works
1396 # jm_AC_TYPE_LONG_LONG
1397 if cc.compiles('''long long ll = 1LL;
1399 int some_func (void) {
1400 long long llmax = (long long) -1;
1401 return ll << i | ll >> i | llmax / ll | llmax % ll;
1402 }''', name : 'long long')
1403 glib_conf.set('HAVE_LONG_LONG', 1)
1404 have_long_long = true
1406 have_long_long = false
1409 # Test whether the compiler supports the 'long double' type.
1410 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
1411 long double foo = 0.0;
1412 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
1413 int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
1414 name : 'long double')
1415 glib_conf.set('HAVE_LONG_DOUBLE', 1)
1418 # Test whether <stddef.h> has the 'wchar_t' type.
1419 if cc.has_header_symbol('stddef.h', 'wchar_t')
1420 glib_conf.set('HAVE_WCHAR_T', 1)
1423 # Test whether <wchar.h> has the 'wint_t' type.
1424 if cc.has_header_symbol('wchar.h', 'wint_t')
1425 glib_conf.set('HAVE_WINT_T', 1)
1428 found_uintmax_t = false
1430 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
1431 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1432 # jm_AC_HEADER_INTTYPES_H
1433 if cc.compiles('''#include <sys/types.h>
1434 #include <inttypes.h>
1435 void some_func (void) {
1436 uintmax_t i = (uintmax_t) -1;
1437 }''', name : 'uintmax_t in inttypes.h')
1438 glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1439 found_uintmax_t = true
1442 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1443 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1444 # jm_AC_HEADER_STDINT_H
1445 if cc.compiles('''#include <sys/types.h>
1447 void some_func (void) {
1448 uintmax_t i = (uintmax_t) -1;
1449 }''', name : 'uintmax_t in stdint.h')
1450 glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1451 found_uintmax_t = true
1454 # Define intmax_t to 'long' or 'long long'
1455 # if it is not already defined in <stdint.h> or <inttypes.h>.
1456 # For simplicity, we assume that a header file defines 'intmax_t' if and
1457 # only if it defines 'uintmax_t'.
1459 glib_conf.set('HAVE_INTMAX_T', 1)
1461 glib_conf.set('intmax_t', 'long long')
1463 glib_conf.set('intmax_t', 'long')
1466 char_size = cc.sizeof('char')
1467 short_size = cc.sizeof('short')
1468 int_size = cc.sizeof('int')
1469 voidp_size = cc.sizeof('void*')
1470 long_size = cc.sizeof('long')
1472 long_long_size = cc.sizeof('long long')
1476 sizet_size = cc.sizeof('size_t')
1477 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1478 ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1480 ssizet_size = cc.sizeof('ssize_t', prefix : '#include <unistd.h>')
1483 # Some platforms (Apple) hard-code int64_t to long long instead of
1484 # using long on 64-bit architectures. This can cause type mismatch
1485 # warnings when trying to interface with code using the standard
1486 # library type. Test for the warnings and set gint64 to whichever
1488 if long_long_size == long_size
1489 if cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1490 #pragma options langlvl=stdc99
1492 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1499 }''', name : 'int64_t is long')
1500 int64_t_typedef = 'long'
1501 elif cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1502 #pragma options langlvl=stdc99
1504 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1509 long long *i2 = &i1;
1511 }''', name : 'int64_t is long long')
1512 int64_t_typedef = 'long long'
1517 char_align = cc.alignment('char')
1518 short_align = cc.alignment('short')
1519 int_align = cc.alignment('int')
1520 voidp_align = cc.alignment('void*')
1521 long_align = cc.alignment('long')
1522 long_long_align = cc.alignment('long long')
1523 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1524 # be 64-bit in C99, and it is available on all supported compilers
1525 sizet_align = cc.alignment('size_t')
1527 glib_conf.set('SIZEOF_CHAR', char_size)
1528 glib_conf.set('SIZEOF_INT', int_size)
1529 glib_conf.set('SIZEOF_SHORT', short_size)
1530 glib_conf.set('SIZEOF_LONG', long_size)
1531 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1532 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1533 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1534 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1535 glib_conf.set('SIZEOF_WCHAR_T', cc.sizeof('wchar_t', prefix: '#include <stddef.h>'))
1548 error('Compiler provides no native 16-bit integer type')
1550 glibconfig_conf.set('gint16', gint16)
1551 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1552 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1553 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1560 guint32_align = short_align
1566 guint32_align = int_align
1572 guint32_align = long_align
1574 error('Compiler provides no native 32-bit integer type')
1576 glibconfig_conf.set('gint32', gint32)
1577 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1578 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1579 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1587 gint64_constant='(val)'
1588 guint64_constant='(val)'
1589 guint64_align = int_align
1590 elif long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long')
1596 gint64_constant='(val##L)'
1597 guint64_constant='(val##UL)'
1598 guint64_align = long_align
1599 elif long_long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long long')
1600 gint64 = 'long long'
1601 glib_extension='G_GNUC_EXTENSION '
1602 gint64_modifier=int64_m
1603 gint64_format=int64_m + 'i'
1604 guint64_format=int64_m + 'u'
1605 gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1606 guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1607 guint64_align = long_long_align
1609 error('Compiler provides no native 64-bit integer type')
1611 glibconfig_conf.set('glib_extension', glib_extension)
1612 glibconfig_conf.set('gint64', gint64)
1613 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1614 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1615 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1616 glibconfig_conf.set('gint64_constant', gint64_constant)
1617 glibconfig_conf.set('guint64_constant', guint64_constant)
1619 if host_system == 'windows'
1620 glibconfig_conf.set('g_pid_type', 'void*')
1621 glibconfig_conf.set_quoted('g_pid_format', 'p')
1622 if host_machine.cpu_family() == 'x86_64'
1623 glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1625 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1627 glibconfig_conf.set('g_dir_separator', '\\\\')
1628 glibconfig_conf.set('g_searchpath_separator', ';')
1630 glibconfig_conf.set('g_pid_type', 'int')
1631 glibconfig_conf.set_quoted('g_pid_format', 'i')
1632 glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1633 glibconfig_conf.set('g_dir_separator', '/')
1634 glibconfig_conf.set('g_searchpath_separator', ':')
1637 g_sizet_compatibility = {
1638 'short': sizet_size == short_size,
1639 'int': sizet_size == int_size,
1640 'long': sizet_size == long_size,
1641 'long long': sizet_size == long_long_size,
1644 # Do separate checks for gcc/clang (and ignore other compilers for now), since
1645 # we need to explicitly pass -Werror to the compilers.
1646 # FIXME: https://github.com/mesonbuild/meson/issues/5399
1647 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
1648 foreach type_name, size_compatibility : g_sizet_compatibility
1649 g_sizet_compatibility += { type_name: size_compatibility and
1651 '''#include <stddef.h>
1652 size_t f (size_t *i) { return *i + 1; }
1654 unsigned ''' + type_name + ''' i = 0;
1659 name : 'GCC size_t typedef is ' + type_name), }
1663 if g_sizet_compatibility['short']
1664 glibconfig_conf.set('glib_size_type_define', 'short')
1665 glibconfig_conf.set_quoted('gsize_modifier', 'h')
1666 glibconfig_conf.set_quoted('gssize_modifier', 'h')
1667 glibconfig_conf.set_quoted('gsize_format', 'hu')
1668 glibconfig_conf.set_quoted('gssize_format', 'hi')
1669 glibconfig_conf.set('glib_msize_type', 'SHRT')
1670 elif g_sizet_compatibility['int']
1671 glibconfig_conf.set('glib_size_type_define', 'int')
1672 glibconfig_conf.set_quoted('gsize_modifier', '')
1673 glibconfig_conf.set_quoted('gssize_modifier', '')
1674 glibconfig_conf.set_quoted('gsize_format', 'u')
1675 glibconfig_conf.set_quoted('gssize_format', 'i')
1676 glibconfig_conf.set('glib_msize_type', 'INT')
1677 elif g_sizet_compatibility['long']
1678 glibconfig_conf.set('glib_size_type_define', 'long')
1679 glibconfig_conf.set_quoted('gsize_modifier', 'l')
1680 glibconfig_conf.set_quoted('gssize_modifier', 'l')
1681 glibconfig_conf.set_quoted('gsize_format', 'lu')
1682 glibconfig_conf.set_quoted('gssize_format', 'li')
1683 glibconfig_conf.set('glib_msize_type', 'LONG')
1684 elif g_sizet_compatibility['long long']
1685 glibconfig_conf.set('glib_size_type_define', 'long long')
1686 glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1687 glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1688 glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1689 glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1690 glibconfig_conf.set('glib_msize_type', 'INT64')
1692 error('Could not determine size of size_t.')
1695 if voidp_size == int_size
1696 glibconfig_conf.set('glib_intptr_type_define', 'int')
1697 glibconfig_conf.set_quoted('gintptr_modifier', '')
1698 glibconfig_conf.set_quoted('gintptr_format', 'i')
1699 glibconfig_conf.set_quoted('guintptr_format', 'u')
1700 glibconfig_conf.set('glib_gpi_cast', '(gint)')
1701 glibconfig_conf.set('glib_gpui_cast', '(guint)')
1702 elif voidp_size == long_size
1703 glibconfig_conf.set('glib_intptr_type_define', 'long')
1704 glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1705 glibconfig_conf.set_quoted('gintptr_format', 'li')
1706 glibconfig_conf.set_quoted('guintptr_format', 'lu')
1707 glibconfig_conf.set('glib_gpi_cast', '(glong)')
1708 glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1709 elif voidp_size == long_long_size
1710 glibconfig_conf.set('glib_intptr_type_define', 'long long')
1711 glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1712 glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1713 glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1714 glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1715 glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1717 error('Could not determine size of void *')
1720 if long_size != 8 and long_long_size != 8 and int_size != 8
1721 error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1724 glibconfig_conf.set('gintbits', int_size * 8)
1725 glibconfig_conf.set('glongbits', long_size * 8)
1726 glibconfig_conf.set('gsizebits', sizet_size * 8)
1727 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1729 # XXX: https://gitlab.gnome.org/GNOME/glib/issues/1413
1730 if host_system == 'windows'
1731 g_module_suffix = 'dll'
1733 g_module_suffix = 'so'
1735 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1737 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1738 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1739 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1740 glibconfig_conf.set('GLIB_VERSION', glib_version)
1742 glibconfig_conf.set('glib_void_p', voidp_size)
1743 glibconfig_conf.set('glib_long', long_size)
1744 glibconfig_conf.set('glib_size_t', sizet_size)
1745 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1746 if host_machine.endian() == 'big'
1747 glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1748 glibconfig_conf.set('g_bs_native', 'BE')
1749 glibconfig_conf.set('g_bs_alien', 'LE')
1751 glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1752 glibconfig_conf.set('g_bs_native', 'LE')
1753 glibconfig_conf.set('g_bs_alien', 'BE')
1756 # === va_copy checks ===
1760 # We check for G_VA_COPY_AS_ARRAY for historical reasons, but we no longer
1761 # use it: use Standard C va_copy() instead.
1763 va_list_val_copy_prog = '''
1766 void f (int i, ...) {
1767 va_list args1, args2;
1768 va_start (args1, i);
1770 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1772 va_end (args1); va_end (args2);
1780 rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1781 glib_va_val_copy = rres.compiled() and rres.returncode() == 0
1783 glib_va_val_copy = meson.get_external_property('va_val_copy', true)
1785 if not glib_va_val_copy
1786 glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1787 glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1789 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1791 # check for flavours of varargs macros
1792 g_have_iso_c_varargs = cc.compiles('''
1793 void some_func (void) {
1794 int a(int p1, int p2, int p3);
1795 #define call_a(...) a(1,__VA_ARGS__)
1797 }''', name : 'ISO C99 varargs macros in C')
1799 if not g_have_iso_c_varargs
1800 error('GLib requires a C compiler with support for C99 __VA_ARG__ in macros.')
1804 g_have_iso_cxx_varargs = cxx.compiles('''
1805 void some_func (void) {
1806 int a(int p1, int p2, int p3);
1807 #define call_a(...) a(1,__VA_ARGS__)
1809 }''', name : 'ISO C99 varargs macros in C++')
1811 if not g_have_iso_cxx_varargs
1812 error('GLib requires a C++ compiler with support for C99 __VA_ARG__ in macros.')
1816 g_have_gnuc_varargs = cc.compiles('''
1817 void some_func (void) {
1818 int a(int p1, int p2, int p3);
1819 #define call_a(params...) a(1,params)
1821 }''', name : 'GNUC varargs macros')
1823 if cc.has_header('alloca.h')
1824 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1826 has_syspoll = cc.has_header('sys/poll.h')
1827 has_systypes = cc.has_header('sys/types.h')
1829 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1831 has_winsock2 = cc.has_header('winsock2.h')
1833 if has_syspoll and has_systypes
1835 #include<sys/poll.h>
1836 #include<sys/types.h>'''
1839 #define _WIN32_WINNT @0@
1840 #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1843 error('FIX POLL* defines')
1847 [ 'POLLIN', 'g_pollin', 1 ],
1848 [ 'POLLOUT', 'g_pollout', 4 ],
1849 [ 'POLLPRI', 'g_pollpri', 2 ],
1850 [ 'POLLERR', 'g_pollerr', 8 ],
1851 [ 'POLLHUP', 'g_pollhup', 16 ],
1852 [ 'POLLNVAL', 'g_pollnval', 32 ],
1855 if has_syspoll and has_systypes
1856 foreach d : poll_defines
1857 val = cc.compute_int(d[0], prefix: poll_includes)
1858 glibconfig_conf.set(d[1], val)
1861 # Due to a missed bug in configure.ac the poll test
1862 # never succeeded on Windows and used some pre-defined
1863 # values as a fallback. Keep using them to maintain
1864 # ABI compatibility with autotools builds of glibs
1865 # and with *any* glib-using code compiled against them,
1866 # since these values end up in a public header glibconfig.h.
1867 foreach d : poll_defines
1868 glibconfig_conf.set(d[1], d[2])
1872 # Internet address families
1873 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1874 if host_system == 'windows'
1876 #include <winsock2.h>'''
1879 #include <sys/types.h>
1880 #include <sys/socket.h>'''
1884 [ 'AF_UNIX', 'g_af_unix' ],
1885 [ 'AF_INET', 'g_af_inet' ],
1886 [ 'AF_INET6', 'g_af_inet6' ],
1887 [ 'MSG_OOB', 'g_msg_oob' ],
1888 [ 'MSG_PEEK', 'g_msg_peek' ],
1889 [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1891 foreach d : inet_defines
1892 val = cc.compute_int(d[0], prefix: inet_includes)
1893 glibconfig_conf.set(d[1], val)
1896 if host_system == 'windows'
1899 have_ipv6 = cc.has_type('struct in6_addr', prefix: '#include <netinet/in.h>')
1901 glib_conf.set('HAVE_IPV6', have_ipv6)
1903 # We need to decide at configure time if GLib will use real atomic
1904 # operations ("lock free") or emulated ones with a mutex. This is
1905 # because we must put this information in glibconfig.h so we know if
1906 # it is safe or not to inline using compiler intrinsics directly from
1909 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1910 # user is interested in knowing if they can use the atomic ops across
1913 # We can currently support the atomic ops natively when building GLib
1914 # with recent versions of GCC or MSVC.
1916 # Note that the atomic ops are only available with GCC on x86 when
1917 # using -march=i486 or higher. If we detect that the atomic ops are
1918 # not available but would be available given the right flags, we want
1919 # to abort and advise the user to fix their CFLAGS. It's better to do
1920 # that then to silently fall back on emulated atomic ops just because
1921 # the user had the wrong build environment.
1922 atomictest = '''int main() {
1924 __sync_bool_compare_and_swap (&atomic, 2, 3);
1930 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1931 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1935 # We know that we can always use real ("lock free") atomic operations with MSVC
1936 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' or cc.links(atomictest, name : 'atomic ops')
1937 have_atomic_lock_free = true
1938 if cc.get_id() == 'gcc' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1939 # Old gcc release may provide
1940 # __sync_bool_compare_and_swap but doesn't define
1941 # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1942 glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1945 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
1946 sync_swap_test = '''
1949 __sync_swap (&atomic, 2);
1954 glib_conf.set('_GLIB_GCC_HAVE_SYNC_SWAP', cc.links(sync_swap_test, name : 'sync swap'))
1957 have_atomic_lock_free = false
1958 if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1959 error('GLib must be built with -march=i486 or later.')
1962 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1966 if get_option('force_posix_threads')
1967 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')
1970 # Determination of thread implementation
1971 if host_system == 'windows' and not get_option('force_posix_threads')
1973 threads_implementation = 'win32'
1974 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1975 glib_conf.set('THREADS_WIN32', 1)
1977 thread_dep = dependency('threads')
1978 threads_implementation = 'posix'
1979 pthread_prefix = '''
1981 # define _GNU_SOURCE
1983 #include <pthread.h>'''
1984 glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1985 glib_conf.set('THREADS_POSIX', 1)
1986 if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1987 glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1989 if cc.has_header_symbol('pthread.h', 'pthread_attr_setinheritsched')
1990 glib_conf.set('HAVE_PTHREAD_ATTR_SETINHERITSCHED', 1)
1992 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1993 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1995 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1996 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1998 if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1999 glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
2002 # Assume that pthread_setname_np is available in some form; same as configure
2003 if cc.links(pthread_prefix + '''
2005 pthread_setname_np("example");
2008 name : 'pthread_setname_np(const char*)',
2009 dependencies : thread_dep)
2011 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
2012 elif cc.links(pthread_prefix + '''
2014 pthread_setname_np(pthread_self(), "example");
2017 name : 'pthread_setname_np(pthread_t, const char*)',
2018 dependencies : thread_dep)
2019 # Linux, Solaris, etc.
2020 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
2021 elif cc.links(pthread_prefix + '''
2023 pthread_setname_np(pthread_self(), "%s", "example");
2026 name : 'pthread_setname_np(pthread_t, const char*, void*)',
2027 dependencies : thread_dep)
2029 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG', 1)
2030 elif cc.links(pthread_prefix + '''
2031 #include <pthread_np.h>
2033 pthread_set_name_np(pthread_self(), "example");
2036 name : 'pthread_set_name_np(pthread_t, const char*)',
2037 dependencies : thread_dep)
2038 # FreeBSD, DragonFlyBSD, OpenBSD, etc.
2039 glib_conf.set('HAVE_PTHREAD_SET_NAME_NP', 1)
2043 # FIXME: we should make it print the result and always return 0, so that
2044 # the output in meson shows up as green
2045 # volatile is needed here to avoid optimisations in the test
2046 stack_grows_check_prog = '''
2047 volatile int *a = 0, *b = 0;
2059 return b > a ? 0 : 1;
2063 rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
2064 growing_stack = rres.compiled() and rres.returncode() == 0
2066 growing_stack = meson.get_external_property('growing_stack', false)
2069 glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack)
2073 # We should never use the MinGW C library's iconv because it may not be
2074 # available in the actual runtime environment. On Windows, we always use
2075 # the built-in implementation
2076 if host_system == 'windows'
2077 # We have a #include "win_iconv.c" in gconvert.c on Windows, so we don't need
2078 # any external library for it
2081 libiconv = dependency('iconv')
2084 pcre2_req = '>=10.32'
2086 # Pick up pcre from the system, or if "--force-fallback-for libpcre2-8" was specified
2087 pcre2 = dependency('libpcre2-8', version: pcre2_req, required: false, default_options: ['default_library=static'])
2088 if not pcre2.found()
2089 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
2090 # MSVC: Search for the PCRE2 library by the configuration, which corresponds
2091 # to the output of CMake builds of PCRE2. Note that debugoptimized
2092 # is really a Release build with .PDB files.
2093 if vs_crt == 'debug'
2094 pcre2 = cc.find_library('pcre2d-8', required : false)
2096 pcre2 = cc.find_library('pcre2-8', required : false)
2101 # Try again with the fallback
2102 if not pcre2.found()
2103 pcre2 = dependency('libpcre2-8', version: pcre2_req, allow_fallback: true, default_options: ['default_library=static'])
2104 assert(pcre2.type_name() == 'internal')
2105 # static flags are automatically enabled by the subproject if it's built
2106 # with default_library=static
2107 use_pcre2_static_flag = false
2108 elif host_system == 'windows' and pcre2.type_name() != 'internal'
2109 pcre2_static = cc.links('''#define PCRE2_STATIC
2110 #define PCRE2_CODE_UNIT_WIDTH 8
2117 dependencies: pcre2,
2118 name : 'Windows system PCRE2 is a static build')
2119 use_pcre2_static_flag = pcre2_static
2121 use_pcre2_static_flag = false
2124 # Import the gvdb sources as a subproject to avoid having the copylib in-tree
2126 gvdb_dep = dependency('gvdb')
2128 libm = cc.find_library('m', required : false)
2129 libffi_dep = dependency('libffi', version : '>= 3.0.0')
2131 libz_dep = dependency('zlib')
2133 # First check in libc, fallback to libintl, and as last chance build
2134 # proxy-libintl subproject.
2135 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
2136 # implementations. This could be extended if issues are found in some platforms.
2138 libintl_prefix = '#include <libintl.h>'
2139 libintl = dependency('intl', required: false)
2140 if libintl.found() and libintl.type_name() != 'internal'
2141 # libintl supports different threading APIs, which may not
2142 # require additional flags, but it defaults to using pthreads if
2143 # found. Meson's "threads" dependency does not allow you to
2144 # prefer pthreads. We may not be using pthreads for glib itself
2145 # either so just link the library to satisfy libintl rather than
2146 # also defining the macros with the -pthread flag.
2148 # Meson's builtin dependency lookup as of 0.60.0 doesn't check for
2149 # pthread, so we do this manually here.
2150 if cc.has_function('ngettext', dependencies : libintl, prefix: libintl_prefix)
2151 libintl_deps += [libintl]
2153 libintl_iconv = cc.find_library('iconv', required : false)
2154 if libintl_iconv.found() and cc.has_function('ngettext', args : osx_ldflags, dependencies : [libintl, libintl_iconv])
2155 libintl_deps += [libintl, libintl_iconv]
2157 libintl_pthread = cc.find_library('pthread', required : false)
2158 if libintl_pthread.found() and cc.has_function('ngettext', dependencies : [libintl, libintl_pthread], prefix: libintl_prefix)
2159 libintl_deps += [libintl, libintl_pthread]
2161 libintl = disabler()
2167 if libintl.found() and libintl.type_name() != 'internal'
2168 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset', dependencies: libintl_deps, prefix: libintl_prefix)
2170 # using proxy-libintl fallback
2171 libintl = dependency('intl', allow_fallback: true)
2172 assert(libintl.type_name() == 'internal')
2173 libintl_deps = [libintl]
2174 have_bind_textdomain_codeset = true # proxy-libintl supports it
2177 glib_conf.set('HAVE_BIND_TEXTDOMAIN_CODESET', have_bind_textdomain_codeset)
2179 # We require gettext to always be present
2180 glib_conf.set('HAVE_DCGETTEXT', 1)
2181 glib_conf.set('HAVE_GETTEXT', 1)
2183 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
2185 glib_conf.set_quoted('GLIB_LOCALSTATEDIR', glib_localstatedir)
2186 glib_conf.set_quoted('GLIB_RUNSTATEDIR', glib_runstatedir)
2188 # libmount is only used by gio, but we need to fetch the libs to generate the
2189 # pkg-config file below
2191 if host_system == 'linux'
2192 libmount_dep = dependency('mount', version : '>=2.23', required : get_option('libmount'))
2193 glib_conf.set('HAVE_LIBMOUNT', libmount_dep.found())
2196 if host_system == 'windows'
2197 winsock2 = cc.find_library('ws2_32')
2199 winsock2 = not_found
2203 if host_system == 'linux'
2204 selinux_dep = dependency('libselinux', version: '>=2.2', required: get_option('selinux'))
2206 glib_conf.set('HAVE_SELINUX', selinux_dep.found())
2210 if host_system != 'windows' and get_option('xattr')
2211 # either glibc or libattr can provide xattr support
2212 # for both of them, we check for getxattr being in
2213 # the library and a valid xattr header.
2216 if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
2217 glib_conf.set('HAVE_SYS_XATTR_H', 1)
2218 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
2219 #failure. try libattr
2220 elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
2221 glib_conf.set('HAVE_ATTR_XATTR_H', 1)
2222 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
2223 xattr_dep = [cc.find_library('xattr')]
2225 error('No getxattr implementation found in C library or libxattr')
2228 glib_conf.set('HAVE_XATTR', 1)
2229 if cc.compiles(glib_conf_prefix + '''
2231 #ifdef HAVE_SYS_TYPES_H
2232 #include <sys/types.h>
2234 #ifdef HAVE_SYS_XATTR_H
2235 #include <sys/xattr.h>
2236 #elif HAVE_ATTR_XATTR_H
2237 #include <attr/xattr.h>
2241 ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
2244 name : 'XATTR_NOFOLLOW')
2245 glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
2249 # If strlcpy is present (BSD and similar), check that it conforms to the BSD
2250 # specification. Specifically Solaris 8's strlcpy() does not, see
2251 # https://bugzilla.gnome.org/show_bug.cgi?id=53933 for further context.
2252 if cc.has_function('strlcpy')
2254 rres = cc.run('''#include <stdlib.h>
2258 (void) strlcpy (p, "hi", 10);
2259 if (strlcat (p, "bye", 0) != 3)
2263 name : 'OpenBSD strlcpy/strlcat')
2264 if rres.compiled() and rres.returncode() == 0
2265 glib_conf.set('HAVE_STRLCPY', 1)
2267 elif meson.get_external_property('have_strlcpy', false)
2268 glib_conf.set('HAVE_STRLCPY', 1)
2272 cmdline_test_code = '''
2274 #include <sys/stat.h>
2282 /* This code is a dumbed-down version of g_file_get_contents() */
2286 #define BUFSIZE 1024
2287 char result[BUFSIZE];
2288 struct stat stat_buf;
2290 int fd = open ("/proc/self/cmdline", O_RDONLY|O_BINARY);
2293 if (fstat (fd, &stat_buf))
2296 if (stat_buf.st_size > 0 && S_ISREG (stat_buf.st_mode))
2298 if (read (fd, result, BUFSIZE) <= 0)
2303 FILE *f = fdopen (fd, "r");
2307 if (fread (result, 1, BUFSIZE, f) <= 0)
2317 exit (__getcmdline ());
2321 rres = cc.run(cmdline_test_code, name : '/proc/self/cmdline')
2322 have_proc_self_cmdline = rres.compiled() and rres.returncode() == 0
2324 have_proc_self_cmdline = meson.get_external_property('have_proc_self_cmdline', false)
2327 glib_conf.set('HAVE_PROC_SELF_CMDLINE', have_proc_self_cmdline)
2329 python = import('python').find_installation()
2330 # used for '#!/usr/bin/env <name>'
2331 python_name = 'python3'
2333 python_version = python.language_version()
2334 python_version_req = '>=3.5'
2335 if not python_version.version_compare(python_version_req)
2336 error('Requires Python @0@, @1@ found.'.format(python_version_req, python_version))
2339 # Determine which user environment-dependent files that we want to install
2340 bash = find_program('bash', required : false)
2341 have_bash = bash.found() # For completion scripts
2342 bash_comp_dep = dependency('bash-completion', version: '>=2.0', required: false)
2343 have_sh = find_program('sh', required : false).found() # For glib-gettextize
2344 have_pkg_config = find_program('pkg-config', required: false).found()
2346 # Some installed tests require a custom environment
2347 env_program = find_program('env', required: installed_tests_enabled)
2349 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
2350 if host_system == 'sunos'
2351 glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
2352 glib_conf.set('_XOPEN_SOURCE', 2)
2353 glib_conf.set('__EXTENSIONS__',1)
2356 # Sadly Meson does not expose this value:
2357 # https://github.com/mesonbuild/meson/pull/3460
2358 if host_system == 'windows'
2359 # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
2360 # with no explanation. Do the same here for now but this could be revisited if
2362 export_dynamic_ldflags = []
2363 elif host_system == 'cygwin'
2364 export_dynamic_ldflags = ['-Wl,--export-all-symbols']
2365 elif host_system in ['darwin', 'ios']
2366 export_dynamic_ldflags = []
2367 elif host_system == 'sunos'
2368 export_dynamic_ldflags = []
2370 export_dynamic_ldflags = ['-Wl,--export-dynamic']
2375 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
2376 # Ensure MSVC-compatible struct packing convention is used when
2377 # compiling for Win32 with gcc. It is used for the whole project and exposed
2379 if not cc.compiles('''
2380 struct _GTestMSBitfields
2386 typedef char _StaticCheck[sizeof(struct _GTestMSBitfields) != sizeof(int) ? 1 : -1];
2389 Your compiler does not have ms-bitfields packing by default.
2390 Please use gcc >= 4.7 or clang >= 12: GLib will drop -mms-bitfields in the future.
2393 win32_cflags = ['-mms-bitfields']
2394 add_project_arguments(win32_cflags, language : 'c')
2396 # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
2397 win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi', '-luuid']
2398 elif host_system == 'cygwin'
2399 win32_ldflags = ['-luser32', '-lkernel32']
2403 want_dtrace = get_option('dtrace')
2404 enable_dtrace = false
2406 # Since dtrace support is opt-in we just error out if it was requested but
2407 # is not available. We don't bother with autodetection yet.
2410 error('GLib dtrace support not yet compatible with macOS dtrace')
2412 dtrace = find_program('dtrace', required : true) # error out if not found
2413 if not cc.has_header('sys/sdt.h')
2414 error('dtrace support needs sys/sdt.h header')
2416 # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
2417 dtrace_obj_gen = generator(dtrace,
2418 output : '@BASENAME@.o',
2419 arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2420 dtrace_hdr_gen = generator(python,
2421 output : '@BASENAME@.h',
2422 arguments : ['-c', '''
2423 import subprocess, sys
2424 subprocess.run(sys.argv[1:], check=True)
2425 output = sys.argv[6]
2426 with open(output) as f:
2428 contents = contents.replace("define STAP_HAS_SEMAPHORES 1",
2429 "undef STAP_HAS_SEMAPHORES")
2430 contents = contents.replace("define _SDT_HAS_SEMAPHORES 1",
2431 "undef _SDT_HAS_SEMAPHORES")
2432 with open(output, "w") as f:
2434 ''', dtrace.full_path(), '-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2435 glib_conf.set('HAVE_DTRACE', 1)
2436 enable_dtrace = true
2439 if cc.has_header_symbol('sys/ptrace.h', 'PTRACE_O_EXITKILL')
2440 glib_conf.set('HAVE_PTRACE_O_EXITKILL', 1)
2444 want_systemtap = get_option('systemtap')
2445 enable_systemtap = false
2447 if want_systemtap and enable_dtrace
2448 tapset_install_dir = get_option('tapset_install_dir')
2449 if tapset_install_dir == ''
2450 tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
2452 stp_cdata = configuration_data()
2453 stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
2454 stp_cdata.set('LT_CURRENT', minor_version * 100)
2455 stp_cdata.set('LT_REVISION', micro_version)
2456 enable_systemtap = true
2459 pkg = import('pkgconfig')
2460 windows = import('windows')
2469 # xgettext is optional (on Windows for instance)
2470 if find_program('xgettext', required : get_option('nls')).found()
2474 # Install m4 macros that other projects use
2475 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
2476 install_dir : get_option('datadir') / 'aclocal',
2477 install_tag : 'devel',
2480 # Check whether we support overriding the invalid parameter handler on Windows for _get_osfhandle(),
2481 # g_fsync() (i.e. _commit()), etc
2482 if host_system == 'windows'
2483 if cc.has_function('_set_thread_local_invalid_parameter_handler', prefix: '#include <stdlib.h>')
2484 glib_conf.set('HAVE__SET_THREAD_LOCAL_INVALID_PARAMETER_HANDLER', 1)
2486 if cc.has_function('_set_invalid_parameter_handler', prefix: '#include <stdlib.h>')
2487 glib_conf.set('HAVE__SET_INVALID_PARAMETER_HANDLER', 1)
2489 if cc.has_header_symbol('crtdbg.h', '_CrtSetReportMode')
2490 glib_conf.set('HAVE__CRT_SET_REPORT_MODE', 1)
2494 configure_file(output : 'config.h', configuration : glib_conf)
2496 if get_option('man')
2497 xsltproc = find_program('xsltproc', required : true)
2498 xsltproc_command = [
2501 '--stringparam', 'man.output.quietly', '1',
2502 '--stringparam', 'funcsynopsis.style', 'ansi',
2503 '--stringparam', 'man.th.extra1.suppress', '1',
2504 '--stringparam', 'man.authors.section.enabled', '0',
2505 '--stringparam', 'man.copyright.section.enabled', '0',
2507 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
2510 man1_dir = join_paths(glib_prefix, get_option('mandir'), 'man1')
2513 gnome = import('gnome')
2514 subdir('docs/reference')
2517 'host cpu' : host_machine.cpu_family(),
2518 'host endian' : host_machine.endian(),
2519 'host system' : host_system,
2520 'C Compiler' : cc.get_id(),
2521 'C++ Compiler' : have_cxx ? cxx.get_id() : 'none',
2522 'shared build' : glib_build_shared,
2523 'static build' : glib_build_static,
2524 }, section: 'Build environment')
2526 if build_machine.system() != host_system
2528 'build cpu' : build_machine.cpu_family(),
2529 'build endian' : build_machine.endian(),
2530 'build system' : build_machine.system(),
2531 }, section: 'Build environment')
2535 'prefix' : glib_prefix,
2536 'bindir' : glib_bindir,
2537 'libexecdir' : glib_libexecdir,
2538 'pkgdatadir' : glib_pkgdatadir,
2539 'datadir' : glib_datadir,
2540 'includedir' : glib_includedir,
2541 'giomodulesdir' : glib_giomodulesdir,
2542 'localstatedir' : glib_localstatedir,
2543 'runstatedir' : glib_runstatedir,
2544 }, section: 'Directories')
2546 if get_option('multiarch')
2548 'multiarch bindir' : glib_bindir,
2549 'multiarch libexecdir' : glib_libexecdir,
2550 }, section: 'Directories')
2554 summary('tapset dir', get_option('tapset_install_dir'), section: 'Directories')
2557 if host_system == 'linux'
2559 'selinux' : selinux_dep.found(),
2560 'libmount' : libmount_dep.found(),
2561 }, section: 'Options')
2565 'xattr' : xattr_dep.length() > 0,
2566 'man' : get_option('man'),
2567 'dtrace' : get_option('dtrace'),
2568 'systemtap' : enable_systemtap,
2569 'sysprof' : libsysprof_capture_dep.found(),
2570 'gtk_doc' : get_option('gtk_doc'),
2571 'bsymbolic_functions' : get_option('bsymbolic_functions'),
2572 'force_posix_threads' : get_option('force_posix_threads'),
2573 'tests' : get_option('tests'),
2574 'installed_tests' : get_option('installed_tests'),
2575 'nls' : get_option('nls'),
2576 'oss_fuzz' : get_option('oss_fuzz'),
2577 'glib_debug' : get_option('glib_debug'),
2578 'glib_assert' : get_option('glib_assert'),
2579 'glib_checks' : get_option('glib_checks'),
2580 'libelf' : get_option('libelf'),
2581 'multiarch' : get_option('multiarch'),
2582 }, section: 'Options')