1 project('glib', 'c', 'cpp',
3 # NOTE: We keep this pinned at 0.49 because that's what Debian 10 ships
4 meson_version : '>= 0.49.2',
6 'buildtype=debugoptimized',
12 cc = meson.get_compiler('c')
13 cxx = meson.get_compiler('cpp')
15 cc_can_run = not meson.is_cross_build() or meson.has_exe_wrapper()
17 if cc.get_id() == 'msvc'
18 # Ignore several spurious warnings for things glib does very commonly
19 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
20 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
21 # NOTE: Only add warnings here if you are sure they're spurious
22 add_project_arguments('/wd4035', '/wd4715', '/wd4116',
23 '/wd4046', '/wd4068', '/wo4090', '/FImsvc_recommended_pragmas.h',language : 'c')
24 # Disable SAFESEH with MSVC for plugins and libs that use external deps that
25 # are built with MinGW
26 noseh_link_args = ['/SAFESEH:NO']
27 # Set the input and exec encoding to utf-8, like is the default with GCC
28 add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c')
31 # -mms-bitfields vs -fnative-struct ?
34 host_system = host_machine.system()
36 glib_version = meson.project_version()
37 glib_api_version = '2.0'
38 version_arr = glib_version.split('.')
39 major_version = version_arr[0].to_int()
40 minor_version = version_arr[1].to_int()
41 micro_version = version_arr[2].to_int()
43 interface_age = minor_version.is_odd() ? 0 : micro_version
44 binary_age = 100 * minor_version + micro_version
47 # Maintain compatibility with previous libtool versioning
48 # current = minor * 100 + micro
49 current = binary_age - interface_age
50 library_version = '@0@.@1@.@2@'.format(soversion, current, interface_age)
51 darwin_versions = [current + 1, '@0@.@1@'.format(current + 1, interface_age)]
53 configinc = include_directories('.')
54 glibinc = include_directories('glib')
55 gobjectinc = include_directories('gobject')
56 gmoduleinc = include_directories('gmodule')
57 gioinc = include_directories('gio')
59 glib_prefix = get_option('prefix')
60 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
61 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
62 glib_libexecdir = join_paths(glib_prefix, get_option('libexecdir'))
63 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
64 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
65 glib_includedir = join_paths(glib_prefix, get_option('includedir'))
66 if get_option('gio_module_dir') != ''
67 glib_giomodulesdir = join_paths(glib_prefix, get_option('gio_module_dir'))
69 glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
72 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
74 if get_option('charsetalias_dir') != ''
75 glib_charsetaliasdir = join_paths(glib_prefix, get_option('charsetalias_dir'))
77 glib_charsetaliasdir = glib_libdir
80 installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
81 installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
82 installed_tests_enabled = get_option('installed_tests')
83 installed_tests_template = files('template.test.in')
84 installed_tests_template_tap = files('template-tap.test.in')
86 # Don’t build the tests unless we can run them (either natively, in an exe wrapper, or by installing them for later use)
87 build_tests = not meson.is_cross_build() or (meson.is_cross_build() and meson.has_exe_wrapper()) or installed_tests_enabled
89 add_project_arguments('-D_GNU_SOURCE', language: 'c')
91 # Disable strict aliasing;
92 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
93 if cc.has_argument('-fno-strict-aliasing')
94 add_project_arguments('-fno-strict-aliasing', language: 'c')
97 ########################
98 # Configuration begins #
99 ########################
100 glib_conf = configuration_data()
101 glibconfig_conf = configuration_data()
103 # accumulated list of defines as we check for them, so we can easily
104 # use them later in test programs (autoconf does this automatically)
105 glib_conf_prefix = ''
107 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
108 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
109 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
110 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
111 glib_conf.set('GLIB_BINARY_AGE', binary_age)
112 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
113 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
114 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
115 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
116 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
117 glib_conf.set_quoted('PACKAGE_URL', '')
118 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
119 glib_conf.set('ENABLE_NLS', 1)
121 # used by the .rc.in files
122 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
124 glib_conf.set('_GNU_SOURCE', 1)
126 if host_system == 'windows'
127 # Poll doesn't work on devices on Windows
128 glib_conf.set('BROKEN_POLL', true)
131 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
132 # FIXME: Ideally we shouldn't depend on this on Windows and should use
133 # 64 bit capable Windows API that also works with MSVC.
134 # The autotools build did set this for mingw and while meson sets it
135 # for gcc/clang by default, it doesn't do so on Windows.
136 glib_conf.set('_FILE_OFFSET_BITS', 64)
139 # Check for GNU visibility attributes
140 g_have_gnuc_visibility = cc.compiles('''
142 __attribute__ ((visibility ("hidden")))
147 __attribute__ ((visibility ("internal")))
152 __attribute__ ((visibility ("default")))
164 # Not supported by MSVC, but MSVC also won't support visibility,
165 # so it's OK to pass -Werror explicitly. Replace with
166 # override_options : 'werror=true' once that is supported
168 name : 'GNU C visibility attributes test')
170 if g_have_gnuc_visibility
171 glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
174 # Detect and set symbol visibility
175 glib_hidden_visibility_args = []
176 if get_option('default_library') != 'static'
177 if host_system == 'windows' or host_system == 'cygwin'
178 glib_conf.set('DLL_EXPORT', true)
179 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
180 glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
181 elif cc.has_argument('-fvisibility=hidden')
182 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
183 glib_hidden_visibility_args = ['-fvisibility=hidden']
185 elif cc.has_argument('-fvisibility=hidden')
186 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
187 glib_hidden_visibility_args = ['-fvisibility=hidden']
191 if get_option('default_library') == 'static'
192 glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
193 glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
196 # Cygwin glib port maintainers made it clear
197 # (via the patches they apply) that they want no
198 # part of glib W32 code, therefore we do not define
199 # G_PLATFORM_WIN32 for host_system == 'cygwin'.
200 # This makes G_PLATFORM_WIN32 a synonym for
202 if host_system == 'windows'
203 glib_os = '''#define G_OS_WIN32
204 #define G_PLATFORM_WIN32'''
205 elif host_system == 'cygwin'
206 glib_os = '''#define G_OS_UNIX
207 #define G_WITH_CYGWIN'''
209 glib_os = '#define G_OS_UNIX'
211 glibconfig_conf.set('glib_os', glib_os)
213 # We need to know the build type to determine what .lib files we need on Visual Studio
214 # for dependencies that don't normally come with pkg-config files for Visual Studio builds
215 buildtype = get_option('buildtype')
217 glib_debug_cflags = []
218 if buildtype.startswith('debug')
219 glib_debug_cflags += ['-DG_ENABLE_DEBUG']
220 elif buildtype == 'release'
221 glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
224 add_project_arguments(glib_debug_cflags, language: 'c')
226 # check for header files
231 'dirent.h', # MSC does not come with this by default
265 'sys/time.h', # MSC does not come with this by default
282 define = 'HAVE_' + h.underscorify().to_upper()
283 glib_conf.set(define, 1)
284 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
288 # FIXME: Use cc.check_header from Meson 0.47.
289 # FreeBSD includes a malloc.h which always throw compilation error.
290 if cc.compiles('#include <malloc.h>', name : 'malloc.h')
291 glib_conf.set('HAVE_MALLOC_H', 1)
292 glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
295 if cc.has_header('linux/netlink.h')
296 glib_conf.set('HAVE_NETLINK', 1)
299 if glib_conf.has('HAVE_LOCALE_H')
300 if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
301 glib_conf.set('HAVE_LC_MESSAGES', 1)
305 struct_stat_blkprefix = '''
306 #include <sys/types.h>
307 #include <sys/stat.h>
311 #ifdef HAVE_SYS_STATFS_H
312 #include <sys/statfs.h>
314 #ifdef HAVE_SYS_PARAM_H
315 #include <sys/param.h>
317 #ifdef HAVE_SYS_MOUNT_H
318 #include <sys/mount.h>
323 [ 'stat', 'st_mtimensec' ],
324 [ 'stat', 'st_mtim.tv_nsec' ],
325 [ 'stat', 'st_atimensec' ],
326 [ 'stat', 'st_atim.tv_nsec' ],
327 [ 'stat', 'st_ctimensec' ],
328 [ 'stat', 'st_ctim.tv_nsec' ],
329 [ 'stat', 'st_birthtime' ],
330 [ 'stat', 'st_birthtimensec' ],
331 [ 'stat', 'st_birthtim' ],
332 [ 'stat', 'st_birthtim.tv_nsec' ],
333 [ 'stat', 'st_blksize', struct_stat_blkprefix ],
334 [ 'stat', 'st_blocks', struct_stat_blkprefix ],
335 [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
336 [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
337 [ 'dirent', 'd_type', '''#include <sys/types.h>
338 #include <dirent.h>''' ],
339 [ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
340 [ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
341 [ 'tm', 'tm_gmtoff', '#include <time.h>' ],
342 [ 'tm', '__tm_gmtoff', '#include <time.h>' ],
345 foreach m : struct_members
346 header_check_prefix = glib_conf_prefix
348 header_check_prefix = header_check_prefix + m[2]
350 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
352 if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
353 define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
354 glib_conf.set(define, 1)
355 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
361 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
363 '-Wduplicated-branches',
364 '-Wimplicit-fallthrough',
365 '-Wmisleading-indentation',
366 '-Wstrict-prototypes',
368 # Due to maintained deprecated code, we do not want to see unused parameters
369 '-Wno-unused-parameter',
370 # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
371 # building with -Wbad-function-cast.
372 '-Wno-bad-function-cast',
373 '-Wno-cast-function-type',
374 # Due to function casts through (void*) we cannot support -Wpedantic:
375 # https://wiki.gnome.org/Projects/GLib/CompilerRequirements#Function_pointer_conversions.
377 # A zero-length format string shouldn't be considered an issue.
378 '-Wno-format-zero-length',
379 '-Werror=declaration-after-statement',
381 '-Werror=implicit-function-declaration',
383 '-Werror=missing-include-dirs',
384 '-Werror=missing-prototypes',
385 '-Werror=pointer-arith',
387 warning_c_link_args = [
390 if get_option('bsymbolic_functions')
391 warning_c_link_args += ['-Wl,-Bsymbolic-functions']
395 warning_c_link_args = []
398 add_project_arguments(cc.get_supported_arguments(warning_c_args), language: 'c')
400 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
401 # means we cannot use that flag in add_project_link_arguments(), and must add
402 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
403 # because that is what the autotools build did.
404 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
406 glib_link_flags = cc.get_supported_link_arguments(warning_c_link_args)
408 # Windows SDK requirements and checks
409 if host_system == 'windows'
410 # Check whether we're building for UWP apps
413 #if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
414 #error "Not building for UWP"
416 if cc.compiles(code, name : 'building for UWP')
417 glib_conf.set('G_WINAPI_ONLY_APP', true)
418 # We require Windows 10+ on WinRT
419 glib_conf.set('_WIN32_WINNT', '0x0A00')
421 # We require Windows 7+ on Win32
422 glib_conf.set('_WIN32_WINNT', '0x0601')
486 if glib_conf.has('HAVE_SYS_STATVFS_H')
487 functions += ['statvfs']
489 have_func_statvfs = false
491 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
492 functions += ['statfs']
494 have_func_statfs = false
497 if host_system == 'windows'
498 iphlpapi_dep = cc.find_library('iphlpapi')
499 iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
500 foreach ifunc : iphlpapi_funcs
501 iphl_prefix = '''#define _WIN32_WINNT @0@
502 #include <winsock2.h>
503 #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
504 if cc.has_function(ifunc,
505 prefix : iphl_prefix,
506 dependencies : iphlpapi_dep)
507 idefine = 'HAVE_' + ifunc.underscorify().to_upper()
508 glib_conf.set(idefine, 1)
509 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
510 set_variable('have_func_' + ifunc, true)
512 set_variable('have_func_' + ifunc, false)
516 functions += ['if_indextoname', 'if_nametoindex']
519 # AIX splice is something else
520 if host_system != 'aix'
521 functions += ['splice']
524 foreach f : functions
525 if cc.has_function(f)
526 define = 'HAVE_' + f.underscorify().to_upper()
527 glib_conf.set(define, 1)
528 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
529 set_variable('have_func_' + f, true)
531 set_variable('have_func_' + f, false)
535 # Check that stpcpy() is usable; must use header.
536 # cc.has_function() in some cases (clang, gcc 10+) assumes that if the
537 # compiler provides a builtin of the same name that the function exists, while
538 # it's in fact not provided by any header or library. This is true for
539 # stpcpy() on Windows using clang and gcc as well as posix_memalign() using
540 # gcc on Windows. Skip these checks on Windows for now to avoid false
541 # positives. See https://github.com/mesonbuild/meson/pull/7116,
542 # https://github.com/mesonbuild/meson/issues/3672 and
543 # https://github.com/mesonbuild/meson/issues/5628.
544 # FIXME: Once meson no longer returns success for stpcpy() and
545 # posix_memalign() on Windows using GCC and clang we can remove this.
546 if host_system != 'windows' and cc.has_function('stpcpy', prefix : '#include <string.h>')
547 glib_conf.set('HAVE_STPCPY', 1)
550 # Check that posix_memalign() is usable; must use header
551 if host_system != 'windows' and cc.has_function('posix_memalign', prefix : '#include <stdlib.h>')
552 glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
555 # Check that posix_spawn() is usable; must use header
556 if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
557 glib_conf.set('HAVE_POSIX_SPAWN', 1)
560 # Check whether strerror_r returns char *
561 if have_func_strerror_r
562 if cc.compiles('''#define _GNU_SOURCE
565 char error_string[256];
566 char *ptr = strerror_r (-2, error_string, 256);
567 char c = *strerror_r (-2, error_string, 256);
568 return c != 0 && ptr != (void*) 0L;
571 name : 'strerror_r() returns char *')
572 glib_conf.set('STRERROR_R_CHAR_P', 1,
573 description: 'Defined if strerror_r returns char *')
577 # Special-case these functions that have alternative names on Windows/MSVC
578 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
579 glib_conf.set('HAVE_SNPRINTF', 1)
580 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
581 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
582 hack_define = '1\n#define snprintf _snprintf'
583 glib_conf.set('HAVE_SNPRINTF', hack_define)
584 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
587 if cc.has_function('strcasecmp')
588 glib_conf.set('HAVE_STRCASECMP', 1)
589 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
590 elif cc.has_function('_stricmp')
591 hack_define = '1\n#define strcasecmp _stricmp'
592 glib_conf.set('HAVE_STRCASECMP', hack_define)
593 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
596 if cc.has_function('strncasecmp')
597 glib_conf.set('HAVE_STRNCASECMP', 1)
598 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
599 elif cc.has_function('_strnicmp')
600 hack_define = '1\n#define strncasecmp _strnicmp'
601 glib_conf.set('HAVE_STRNCASECMP', hack_define)
602 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
605 if cc.has_header_symbol('sys/sysmacros.h', 'major')
606 glib_conf.set('MAJOR_IN_SYSMACROS', 1)
607 elif cc.has_header_symbol('sys/mkdev.h', 'major')
608 glib_conf.set('MAJOR_IN_MKDEV', 1)
609 elif cc.has_header_symbol('sys/types.h', 'major')
610 glib_conf.set('MAJOR_IN_TYPES', 1)
613 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
614 glib_conf.set('HAVE_RTLD_LAZY', 1)
617 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
618 glib_conf.set('HAVE_RTLD_NOW', 1)
621 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
622 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
625 have_rtld_next = false
626 if cc.has_header_symbol('dlfcn.h', 'RTLD_NEXT', args: '-D_GNU_SOURCE')
627 have_rtld_next = true
628 glib_conf.set('HAVE_RTLD_NEXT', 1)
631 # Check whether to use statfs or statvfs
632 # Some systems have both statfs and statvfs, pick the most "native" for these
633 if have_func_statfs and have_func_statvfs
634 # on solaris and irix, statfs doesn't even have the f_bavail field
635 if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
636 have_func_statfs = false
638 # at least on linux, statfs is the actual syscall
639 have_func_statvfs = false
643 glib_conf.set('USE_STATFS', 1)
644 stat_func_to_use = 'statfs'
645 elif have_func_statvfs
646 glib_conf.set('USE_STATVFS', 1)
647 stat_func_to_use = 'statvfs'
649 stat_func_to_use = 'neither'
651 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
653 if host_system == 'linux'
654 if cc.has_function('mkostemp',
655 prefix: '''#define _GNU_SOURCE
656 #include <stdlib.h>''')
657 glib_conf.set('HAVE_MKOSTEMP', 1)
662 glib_have_os_x_9_or_later = false
663 glib_have_carbon = false
664 glib_have_cocoa = false
665 if host_system == 'darwin'
666 add_languages('objc')
667 objcc = meson.get_compiler('objc')
669 osx_ldflags += ['-Wl,-framework,CoreFoundation']
671 # Mac OS X Carbon support
672 glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
673 #include <CoreServices/CoreServices.h>''',
674 name : 'Mac OS X Carbon support')
677 glib_conf.set('HAVE_CARBON', true)
678 osx_ldflags += '-Wl,-framework,Carbon'
679 glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
680 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
681 #error Compiling for minimum OS X version before 10.9
683 name : 'OS X 9 or later')
686 # Mac OS X Cocoa support
687 glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
688 #ifdef GNUSTEP_BASE_VERSION
689 #error "Detected GNUstep, not Cocoa"
691 name : 'Mac OS X Cocoa support')
694 glib_conf.set('HAVE_COCOA', true)
695 osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
698 # FIXME: libgio mix C and objC source files and there is no way to reliably
699 # know which language flags it's going to use to link. Add to both languages
700 # for now. See https://github.com/mesonbuild/meson/issues/3585.
701 add_project_link_arguments(osx_ldflags, language : ['objc', 'c'])
705 if cc.links('''#include <linux/futex.h>
706 #include <sys/syscall.h>
708 int main (int argc, char ** argv) {
709 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
711 }''', name : 'futex(2) system call')
712 glib_conf.set('HAVE_FUTEX', 1)
715 # Check for eventfd(2)
716 if cc.links('''#include <sys/eventfd.h>
718 int main (int argc, char ** argv) {
719 eventfd (0, EFD_CLOEXEC);
721 }''', name : 'eventfd(2) system call')
722 glib_conf.set('HAVE_EVENTFD', 1)
725 clock_gettime_test_code = '''
728 int main (int argc, char ** argv) {
729 return clock_gettime(CLOCK_REALTIME, &t);
732 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
733 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
734 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
735 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
736 librt = cc.find_library('rt')
739 dlopen_dlsym_test_code = '''
741 int glib_underscore_test (void) { return 42; }
742 int main (int argc, char ** argv) {
743 void *f1 = (void*)0, *f2 = (void*)0, *handle;
744 handle = dlopen ((void*)0, 0);
746 f1 = dlsym (handle, "glib_underscore_test");
747 f2 = dlsym (handle, "_glib_underscore_test");
752 if cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
753 have_dlopen_dlsym = true
754 elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
755 have_dlopen_dlsym = true
756 libdl_dep = cc.find_library('dl')
758 have_dlopen_dlsym = false
761 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
763 if cc.compiles(glib_conf_prefix + '''
765 #ifdef HAVE_SYS_PARAM_H
766 #include <sys/param.h>
768 #ifdef HAVE_SYS_VFS_H
771 #ifdef HAVE_SYS_MOUNT_H
772 #include <sys/mount.h>
774 #ifdef HAVE_SYS_STATFS_H
775 #include <sys/statfs.h>
777 void some_func (void) {
780 }''', name : 'number of arguments to statfs() (n=2)')
781 glib_conf.set('STATFS_ARGS', 2)
782 elif cc.compiles(glib_conf_prefix + '''
784 #ifdef HAVE_SYS_PARAM_H
785 #include <sys/param.h>
787 #ifdef HAVE_SYS_VFS_H
790 #ifdef HAVE_SYS_MOUNT_H
791 #include <sys/mount.h>
793 #ifdef HAVE_SYS_STATFS_H
794 #include <sys/statfs.h>
796 void some_func (void) {
798 statfs("/", &st, sizeof (st), 0);
799 }''', name : 'number of arguments to statfs() (n=4)')
800 glib_conf.set('STATFS_ARGS', 4)
802 error('Unable to determine number of arguments to statfs()')
806 # open takes O_DIRECTORY as an option
808 if cc.compiles('''#include <fcntl.h>
809 #include <sys/types.h>
810 #include <sys/stat.h>
811 void some_func (void) {
812 open(0, O_DIRECTORY, 0);
813 }''', name : 'open() option O_DIRECTORY')
814 glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
817 # Check whether there is a vsnprintf() function with C99 semantics installed.
818 # (similar tests to AC_FUNC_VSNPRINTF_C99)
819 # Check whether there is a snprintf() function with C99 semantics installed.
820 # (similar tests to AC_FUNC_SNPRINTF_C99)
821 # Check whether there is a printf() function with Unix98 semantics installed.
822 # (similar tests to AC_FUNC_PRINTF_UNIX98)
823 have_good_vsnprintf = false
824 have_good_snprintf = false
825 have_good_printf = false
827 if host_system == 'windows' and (cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl')
828 # Unfortunately the Visual Studio 2015+ implementations of C99-style
829 # snprintf and vsnprintf don't seem to be quite good enough.
830 # (Sorry, I don't know exactly what is the problem,
831 # but it is related to floating point formatting and decimal point vs. comma.)
832 # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
833 # rigorous enough to notice, though.
834 glib_conf.set('HAVE_C99_SNPRINTF', false)
835 glib_conf.set('HAVE_C99_VSNPRINTF', false)
836 glib_conf.set('HAVE_UNIX98_PRINTF', false)
837 elif not cc_can_run and host_system in ['ios', 'darwin']
838 # All these are true when compiling natively on macOS, so we should use good
839 # defaults when building for iOS and tvOS.
840 glib_conf.set('HAVE_C99_SNPRINTF', true)
841 glib_conf.set('HAVE_C99_VSNPRINTF', true)
842 glib_conf.set('HAVE_UNIX98_PRINTF', true)
843 have_good_vsnprintf = true
844 have_good_snprintf = true
845 have_good_printf = true
847 vsnprintf_c99_test_code = '''
859 r = vsnprintf(buffer, 5, s, args);
865 /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
866 implementation. The above will return 7 but if you replace
867 the size of the buffer with 0, it borks! */
869 r = vsnprintf(buffer, 0, s, args);
886 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
887 if rres.compiled() and rres.returncode() == 0
888 glib_conf.set('HAVE_C99_VSNPRINTF', 1)
889 have_good_vsnprintf = true
892 have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
893 glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
896 snprintf_c99_test_code = '''
907 r = snprintf(buffer, 5, "1234567");
912 r = snprintf(buffer, 0, "1234567");
917 r = snprintf(NULL, 0, "1234567");
933 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
934 if rres.compiled() and rres.returncode() == 0
935 glib_conf.set('HAVE_C99_SNPRINTF', 1)
936 have_good_snprintf = true
939 have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
940 glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
943 printf_unix98_test_code = '''
951 sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
952 if (strcmp ("2 3 1", buffer) == 0)
958 rres = cc.run(printf_unix98_test_code, name : 'Unix98 printf positional parameters')
959 if rres.compiled() and rres.returncode() == 0
960 glib_conf.set('HAVE_UNIX98_PRINTF', 1)
961 have_good_printf = true
964 have_good_printf = meson.get_cross_property('have_unix98_printf', false)
965 glib_conf.set('HAVE_UNIX98_PRINTF', have_good_printf)
969 if host_system == 'windows'
970 glib_conf.set_quoted('EXEEXT', '.exe')
972 glib_conf.set('EXEEXT', '')
975 # Our printf is 'good' only if vsnpintf()/snprintf()/printf() supports C99 well enough
976 use_system_printf = have_good_vsnprintf and have_good_snprintf and have_good_printf
977 glib_conf.set('USE_SYSTEM_PRINTF', use_system_printf)
978 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', use_system_printf)
980 if not use_system_printf
981 # gnulib has vasprintf so override the previous check
982 glib_conf.set('HAVE_VASPRINTF', 1)
985 # Check for nl_langinfo and CODESET
986 if cc.links('''#include <langinfo.h>
987 int main (int argc, char ** argv) {
988 char *codeset = nl_langinfo (CODESET);
990 }''', name : 'nl_langinfo and CODESET')
991 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
992 glib_conf.set('HAVE_CODESET', 1)
995 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
996 if cc.links('''#include <langinfo.h>
997 int main (int argc, char ** argv) {
999 str = nl_langinfo (PM_STR);
1000 str = nl_langinfo (D_T_FMT);
1001 str = nl_langinfo (D_FMT);
1002 str = nl_langinfo (T_FMT);
1003 str = nl_langinfo (T_FMT_AMPM);
1004 str = nl_langinfo (MON_1);
1005 str = nl_langinfo (ABMON_12);
1006 str = nl_langinfo (DAY_1);
1007 str = nl_langinfo (ABDAY_7);
1009 }''', name : 'nl_langinfo (PM_STR)')
1010 glib_conf.set('HAVE_LANGINFO_TIME', 1)
1012 if cc.links('''#include <langinfo.h>
1013 int main (int argc, char ** argv) {
1015 str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
1016 str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
1017 str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
1018 str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
1019 str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
1020 str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
1021 str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
1022 str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
1023 str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
1024 str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
1026 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
1027 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
1030 # Check for nl_langinfo and alternative month names
1031 if cc.links('''#ifndef _GNU_SOURCE
1032 # define _GNU_SOURCE
1034 #include <langinfo.h>
1035 int main (int argc, char ** argv) {
1037 str = nl_langinfo (ALTMON_1);
1038 str = nl_langinfo (ALTMON_2);
1039 str = nl_langinfo (ALTMON_3);
1040 str = nl_langinfo (ALTMON_4);
1041 str = nl_langinfo (ALTMON_5);
1042 str = nl_langinfo (ALTMON_6);
1043 str = nl_langinfo (ALTMON_7);
1044 str = nl_langinfo (ALTMON_8);
1045 str = nl_langinfo (ALTMON_9);
1046 str = nl_langinfo (ALTMON_10);
1047 str = nl_langinfo (ALTMON_11);
1048 str = nl_langinfo (ALTMON_12);
1050 }''', name : 'nl_langinfo (ALTMON_n)')
1051 glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
1054 # Check for nl_langinfo and abbreviated alternative month names
1055 if cc.links('''#ifndef _GNU_SOURCE
1056 # define _GNU_SOURCE
1058 #include <langinfo.h>
1059 int main (int argc, char ** argv) {
1061 str = nl_langinfo (_NL_ABALTMON_1);
1062 str = nl_langinfo (_NL_ABALTMON_2);
1063 str = nl_langinfo (_NL_ABALTMON_3);
1064 str = nl_langinfo (_NL_ABALTMON_4);
1065 str = nl_langinfo (_NL_ABALTMON_5);
1066 str = nl_langinfo (_NL_ABALTMON_6);
1067 str = nl_langinfo (_NL_ABALTMON_7);
1068 str = nl_langinfo (_NL_ABALTMON_8);
1069 str = nl_langinfo (_NL_ABALTMON_9);
1070 str = nl_langinfo (_NL_ABALTMON_10);
1071 str = nl_langinfo (_NL_ABALTMON_11);
1072 str = nl_langinfo (_NL_ABALTMON_12);
1074 }''', name : 'nl_langinfo (_NL_ABALTMON_n)')
1075 glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
1078 # Check if C compiler supports the 'signed' keyword
1079 if not cc.compiles('''signed char x;''', name : 'signed')
1080 glib_conf.set('signed', '/* NOOP */')
1083 # Check if the ptrdiff_t type exists
1084 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
1085 glib_conf.set('HAVE_PTRDIFF_T', 1)
1088 # Check for sig_atomic_t type
1089 if cc.links('''#include <signal.h>
1090 #include <sys/types.h>
1091 sig_atomic_t val = 42;
1092 int main (int argc, char ** argv) {
1093 return val == 42 ? 0 : 1;
1094 }''', name : 'sig_atomic_t')
1095 glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
1098 # Check if 'long long' works
1099 # jm_AC_TYPE_LONG_LONG
1100 if cc.compiles('''long long ll = 1LL;
1102 int some_func (void) {
1103 long long llmax = (long long) -1;
1104 return ll << i | ll >> i | llmax / ll | llmax % ll;
1105 }''', name : 'long long')
1106 glib_conf.set('HAVE_LONG_LONG', 1)
1107 have_long_long = true
1109 have_long_long = false
1112 # Test whether the compiler supports the 'long double' type.
1113 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
1114 long double foo = 0.0;
1115 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
1116 int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
1117 name : 'long double')
1118 glib_conf.set('HAVE_LONG_DOUBLE', 1)
1121 # Test whether <stddef.h> has the 'wchar_t' type.
1122 if cc.has_header_symbol('stddef.h', 'wchar_t')
1123 glib_conf.set('HAVE_WCHAR_T', 1)
1126 # Test whether <wchar.h> has the 'wint_t' type.
1127 if cc.has_header_symbol('wchar.h', 'wint_t')
1128 glib_conf.set('HAVE_WINT_T', 1)
1131 found_uintmax_t = false
1133 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
1134 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1135 # jm_AC_HEADER_INTTYPES_H
1136 if cc.compiles('''#include <sys/types.h>
1137 #include <inttypes.h>
1138 void some_func (void) {
1139 uintmax_t i = (uintmax_t) -1;
1140 }''', name : 'uintmax_t in inttypes.h')
1141 glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1142 found_uintmax_t = true
1145 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1146 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1147 # jm_AC_HEADER_STDINT_H
1148 if cc.compiles('''#include <sys/types.h>
1150 void some_func (void) {
1151 uintmax_t i = (uintmax_t) -1;
1152 }''', name : 'uintmax_t in stdint.h')
1153 glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1154 found_uintmax_t = true
1157 # Define intmax_t to 'long' or 'long long'
1158 # if it is not already defined in <stdint.h> or <inttypes.h>.
1159 # For simplicity, we assume that a header file defines 'intmax_t' if and
1160 # only if it defines 'uintmax_t'.
1162 glib_conf.set('HAVE_INTMAX_T', 1)
1164 glib_conf.set('intmax_t', 'long long')
1166 glib_conf.set('intmax_t', 'long')
1169 char_size = cc.sizeof('char')
1170 short_size = cc.sizeof('short')
1171 int_size = cc.sizeof('int')
1172 voidp_size = cc.sizeof('void*')
1173 long_size = cc.sizeof('long')
1175 long_long_size = cc.sizeof('long long')
1179 sizet_size = cc.sizeof('size_t')
1180 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1181 ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1183 ssizet_size = cc.sizeof('ssize_t')
1186 # Some platforms (Apple) hard-code int64_t to long long instead of
1187 # using long on 64-bit architectures. This can cause type mismatch
1188 # warnings when trying to interface with code using the standard
1189 # library type. Test for the warnings and set gint64 to whichever
1191 if long_long_size == long_size
1192 if cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1193 #pragma options langlvl=stdc99
1195 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1202 }''', name : 'int64_t is long')
1203 int64_t_typedef = 'long'
1204 elif cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1205 #pragma options langlvl=stdc99
1207 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1212 long long *i2 = &i1;
1214 }''', name : 'int64_t is long long')
1215 int64_t_typedef = 'long long'
1220 char_align = cc.alignment('char')
1221 short_align = cc.alignment('short')
1222 int_align = cc.alignment('int')
1223 voidp_align = cc.alignment('void*')
1224 long_align = cc.alignment('long')
1225 long_long_align = cc.alignment('long long')
1226 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1227 # be 64-bit in C99, and it is available on all supported compilers
1228 sizet_align = cc.alignment('size_t')
1230 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1232 glib_conf.set('SIZEOF_CHAR', char_size)
1233 glib_conf.set('SIZEOF_INT', int_size)
1234 glib_conf.set('SIZEOF_SHORT', short_size)
1235 glib_conf.set('SIZEOF_LONG', long_size)
1236 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1237 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1238 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1239 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1240 glib_conf.set('SIZEOF_WCHAR_T', cc.sizeof('wchar_t', prefix: '#include <stddef.h>'))
1253 error('Compiler provides no native 16-bit integer type')
1255 glibconfig_conf.set('gint16', gint16)
1256 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1257 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1258 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1265 guint32_align = short_align
1271 guint32_align = int_align
1277 guint32_align = long_align
1279 error('Compiler provides no native 32-bit integer type')
1281 glibconfig_conf.set('gint32', gint32)
1282 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1283 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1284 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1285 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1293 gint64_constant='(val)'
1294 guint64_constant='(val)'
1295 guint64_align = int_align
1296 elif long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long')
1302 gint64_constant='(val##L)'
1303 guint64_constant='(val##UL)'
1304 guint64_align = long_align
1305 elif long_long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long long')
1306 gint64 = 'long long'
1307 glib_extension='G_GNUC_EXTENSION '
1308 gint64_modifier=int64_m
1309 gint64_format=int64_m + 'i'
1310 guint64_format=int64_m + 'u'
1311 gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1312 guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1313 guint64_align = long_long_align
1315 error('Compiler provides no native 64-bit integer type')
1317 glibconfig_conf.set('glib_extension', glib_extension)
1318 glibconfig_conf.set('gint64', gint64)
1319 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1320 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1321 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1322 glibconfig_conf.set('gint64_constant', gint64_constant)
1323 glibconfig_conf.set('guint64_constant', guint64_constant)
1324 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1326 if host_system == 'windows'
1327 glibconfig_conf.set('g_pid_type', 'void*')
1328 glibconfig_conf.set_quoted('g_pid_format', 'p')
1329 if host_machine.cpu_family() == 'x86_64'
1330 glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1332 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1334 glibconfig_conf.set('g_dir_separator', '\\\\')
1335 glibconfig_conf.set('g_searchpath_separator', ';')
1337 glibconfig_conf.set('g_pid_type', 'int')
1338 glibconfig_conf.set_quoted('g_pid_format', 'i')
1339 glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1340 glibconfig_conf.set('g_dir_separator', '/')
1341 glibconfig_conf.set('g_searchpath_separator', ':')
1344 g_sizet_compatibility = {
1345 'short': sizet_size == short_size,
1346 'int': sizet_size == int_size,
1347 'long': sizet_size == long_size,
1348 'long long': sizet_size == long_long_size,
1351 # Do separate checks for gcc/clang (and ignore other compilers for now), since
1352 # we need to explicitly pass -Werror to the compilers.
1353 # FIXME: https://github.com/mesonbuild/meson/issues/5399
1354 # We can’t simplify these checks using a foreach loop because dictionary keys
1355 # have to be string literals.
1356 # FIXME: https://github.com/mesonbuild/meson/issues/5231
1357 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
1358 g_sizet_compatibility += {
1359 'short': g_sizet_compatibility['short'] and cc.compiles(
1360 '''#include <stddef.h>
1361 size_t f (size_t *i) { return *i + 1; }
1363 unsigned short i = 0;
1368 name : 'GCC size_t typedef is short'),
1369 'int': g_sizet_compatibility['int'] and cc.compiles(
1370 '''#include <stddef.h>
1371 size_t f (size_t *i) { return *i + 1; }
1378 name : 'GCC size_t typedef is int'),
1379 'long': g_sizet_compatibility['long'] and cc.compiles(
1380 '''#include <stddef.h>
1381 size_t f (size_t *i) { return *i + 1; }
1383 unsigned long i = 0;
1388 name : 'GCC size_t typedef is long'),
1389 'long long': g_sizet_compatibility['long long'] and cc.compiles(
1390 '''#include <stddef.h>
1391 size_t f (size_t *i) { return *i + 1; }
1393 unsigned long long i = 0;
1398 name : 'GCC size_t typedef is long long'),
1402 if g_sizet_compatibility['short']
1403 glibconfig_conf.set('glib_size_type_define', 'short')
1404 glibconfig_conf.set_quoted('gsize_modifier', 'h')
1405 glibconfig_conf.set_quoted('gssize_modifier', 'h')
1406 glibconfig_conf.set_quoted('gsize_format', 'hu')
1407 glibconfig_conf.set_quoted('gssize_format', 'hi')
1408 glibconfig_conf.set('glib_msize_type', 'SHRT')
1409 elif g_sizet_compatibility['int']
1410 glibconfig_conf.set('glib_size_type_define', 'int')
1411 glibconfig_conf.set_quoted('gsize_modifier', '')
1412 glibconfig_conf.set_quoted('gssize_modifier', '')
1413 glibconfig_conf.set_quoted('gsize_format', 'u')
1414 glibconfig_conf.set_quoted('gssize_format', 'i')
1415 glibconfig_conf.set('glib_msize_type', 'INT')
1416 elif g_sizet_compatibility['long']
1417 glibconfig_conf.set('glib_size_type_define', 'long')
1418 glibconfig_conf.set_quoted('gsize_modifier', 'l')
1419 glibconfig_conf.set_quoted('gssize_modifier', 'l')
1420 glibconfig_conf.set_quoted('gsize_format', 'lu')
1421 glibconfig_conf.set_quoted('gssize_format', 'li')
1422 glibconfig_conf.set('glib_msize_type', 'LONG')
1423 elif g_sizet_compatibility['long long']
1424 glibconfig_conf.set('glib_size_type_define', 'long long')
1425 glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1426 glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1427 glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1428 glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1429 glibconfig_conf.set('glib_msize_type', 'INT64')
1431 error('Could not determine size of size_t.')
1434 if voidp_size == int_size
1435 glibconfig_conf.set('glib_intptr_type_define', 'int')
1436 glibconfig_conf.set_quoted('gintptr_modifier', '')
1437 glibconfig_conf.set_quoted('gintptr_format', 'i')
1438 glibconfig_conf.set_quoted('guintptr_format', 'u')
1439 glibconfig_conf.set('glib_gpi_cast', '(gint)')
1440 glibconfig_conf.set('glib_gpui_cast', '(guint)')
1441 elif voidp_size == long_size
1442 glibconfig_conf.set('glib_intptr_type_define', 'long')
1443 glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1444 glibconfig_conf.set_quoted('gintptr_format', 'li')
1445 glibconfig_conf.set_quoted('guintptr_format', 'lu')
1446 glibconfig_conf.set('glib_gpi_cast', '(glong)')
1447 glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1448 elif voidp_size == long_long_size
1449 glibconfig_conf.set('glib_intptr_type_define', 'long long')
1450 glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1451 glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1452 glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1453 glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1454 glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1456 error('Could not determine size of void *')
1459 if long_size != 8 and long_long_size != 8 and int_size != 8
1460 error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1463 glibconfig_conf.set('gintbits', int_size * 8)
1464 glibconfig_conf.set('glongbits', long_size * 8)
1465 glibconfig_conf.set('gsizebits', sizet_size * 8)
1466 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1468 # XXX: https://gitlab.gnome.org/GNOME/glib/issues/1413
1469 if host_system == 'windows'
1470 g_module_suffix = 'dll'
1472 g_module_suffix = 'so'
1474 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1476 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1477 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1478 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1479 glibconfig_conf.set('GLIB_VERSION', glib_version)
1481 glibconfig_conf.set('glib_void_p', voidp_size)
1482 glibconfig_conf.set('glib_long', long_size)
1483 glibconfig_conf.set('glib_size_t', sizet_size)
1484 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1485 if host_machine.endian() == 'big'
1486 glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1487 glibconfig_conf.set('g_bs_native', 'BE')
1488 glibconfig_conf.set('g_bs_alien', 'LE')
1490 glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1491 glibconfig_conf.set('g_bs_native', 'LE')
1492 glibconfig_conf.set('g_bs_alien', 'BE')
1495 # === va_copy checks ===
1496 # we currently check for all three va_copy possibilities, so we get
1497 # all results in config.log for bug reports.
1500 foreach try_func : [ '__va_copy', 'va_copy' ]
1501 if cc.compiles('''#include <stdarg.h>
1504 # include "msvc_recommended_pragmas.h"
1506 void f (int i, ...) {
1507 va_list args1, args2;
1508 va_start (args1, i);
1510 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1512 va_end (args1); va_end (args2);
1517 }'''.format(try_func),
1518 name : try_func + ' check')
1519 va_copy_func = try_func
1522 if va_copy_func != ''
1523 glib_conf.set('G_VA_COPY', va_copy_func)
1524 glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1526 glib_vacopy = '/* #undef G_VA_COPY */'
1529 va_list_val_copy_prog = '''
1532 void f (int i, ...) {
1533 va_list args1, args2;
1534 va_start (args1, i);
1536 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1538 va_end (args1); va_end (args2);
1546 rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1547 glib_va_val_copy = rres.returncode() == 0
1549 glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
1551 if not glib_va_val_copy
1552 glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1553 glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1555 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1557 # check for flavours of varargs macros
1558 g_have_iso_c_varargs = cc.compiles('''
1559 void some_func (void) {
1560 int a(int p1, int p2, int p3);
1561 #define call_a(...) a(1,__VA_ARGS__)
1563 }''', name : 'ISO C99 varargs macros in C')
1565 if g_have_iso_c_varargs
1566 glibconfig_conf.set('g_have_iso_c_varargs', '''
1568 # define G_HAVE_ISO_VARARGS 1
1572 g_have_iso_cxx_varargs = cxx.compiles('''
1573 void some_func (void) {
1574 int a(int p1, int p2, int p3);
1575 #define call_a(...) a(1,__VA_ARGS__)
1577 }''', name : 'ISO C99 varargs macros in C++')
1579 if g_have_iso_cxx_varargs
1580 glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1582 # define G_HAVE_ISO_VARARGS 1
1586 g_have_gnuc_varargs = cc.compiles('''
1587 void some_func (void) {
1588 int a(int p1, int p2, int p3);
1589 #define call_a(params...) a(1,params)
1591 }''', name : 'GNUC varargs macros')
1593 if cc.has_header('alloca.h')
1594 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1596 has_syspoll = cc.has_header('sys/poll.h')
1597 has_systypes = cc.has_header('sys/types.h')
1599 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1601 has_winsock2 = cc.has_header('winsock2.h')
1603 if has_syspoll and has_systypes
1605 #include<sys/poll.h>
1606 #include<sys/types.h>'''
1609 #define _WIN32_WINNT @0@
1610 #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1613 error('FIX POLL* defines')
1617 [ 'POLLIN', 'g_pollin', 1 ],
1618 [ 'POLLOUT', 'g_pollout', 4 ],
1619 [ 'POLLPRI', 'g_pollpri', 2 ],
1620 [ 'POLLERR', 'g_pollerr', 8 ],
1621 [ 'POLLHUP', 'g_pollhup', 16 ],
1622 [ 'POLLNVAL', 'g_pollnval', 32 ],
1625 if has_syspoll and has_systypes
1626 foreach d : poll_defines
1627 val = cc.compute_int(d[0], prefix: poll_includes)
1628 glibconfig_conf.set(d[1], val)
1631 # Due to a missed bug in configure.ac the poll test
1632 # never succeeded on Windows and used some pre-defined
1633 # values as a fallback. Keep using them to maintain
1634 # ABI compatibility with autotools builds of glibs
1635 # and with *any* glib-using code compiled against them,
1636 # since these values end up in a public header glibconfig.h.
1637 foreach d : poll_defines
1638 glibconfig_conf.set(d[1], d[2])
1642 # Internet address families
1643 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1644 if host_system == 'windows'
1646 #include <winsock2.h>'''
1649 #include <sys/types.h>
1650 #include <sys/socket.h>'''
1654 [ 'AF_UNIX', 'g_af_unix' ],
1655 [ 'AF_INET', 'g_af_inet' ],
1656 [ 'AF_INET6', 'g_af_inet6' ],
1657 [ 'MSG_OOB', 'g_msg_oob' ],
1658 [ 'MSG_PEEK', 'g_msg_peek' ],
1659 [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1661 foreach d : inet_defines
1662 val = cc.compute_int(d[0], prefix: inet_includes)
1663 glibconfig_conf.set(d[1], val)
1666 # We need a more robust approach here...
1667 host_cpu_family = host_machine.cpu_family()
1668 if host_cpu_family == 'x86' or host_cpu_family == 'x86_64' or host_cpu_family == 's390' or host_cpu_family == 's390x' or host_cpu_family.startswith('arm') or host_cpu_family == 'aarch64' or host_cpu_family.startswith('crisv32') or host_cpu_family.startswith('etrax')
1669 glib_memory_barrier_needed = false
1670 elif host_cpu_family.startswith('sparc') or host_cpu_family.startswith('alpha') or host_cpu_family.startswith('powerpc') or host_cpu_family == 'ia64'
1671 glib_memory_barrier_needed = true
1673 warning('Unknown host cpu: ' + host_cpu_family)
1674 glib_memory_barrier_needed = true
1676 glibconfig_conf.set('G_ATOMIC_OP_MEMORY_BARRIER_NEEDED', glib_memory_barrier_needed)
1678 # We need to decide at configure time if GLib will use real atomic
1679 # operations ("lock free") or emulated ones with a mutex. This is
1680 # because we must put this information in glibconfig.h so we know if
1681 # it is safe or not to inline using compiler intrinsics directly from
1684 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1685 # user is interested in knowing if they can use the atomic ops across
1688 # We can currently support the atomic ops natively when building GLib
1689 # with recent versions of GCC or MSVC.
1691 # Note that the atomic ops are only available with GCC on x86 when
1692 # using -march=i486 or higher. If we detect that the atomic ops are
1693 # not available but would be available given the right flags, we want
1694 # to abort and advise the user to fix their CFLAGS. It's better to do
1695 # that then to silently fall back on emulated atomic ops just because
1696 # the user had the wrong build environment.
1697 atomictest = '''int main() {
1698 volatile int atomic = 2;
1699 __sync_bool_compare_and_swap (&atomic, 2, 3);
1705 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1706 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1710 # We know that we can always use real ("lock free") atomic operations with MSVC
1711 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' or cc.links(atomictest, name : 'atomic ops')
1712 have_atomic_lock_free = true
1713 if cc.get_id() == 'gcc' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1714 # Old gcc release may provide
1715 # __sync_bool_compare_and_swap but doesn't define
1716 # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1717 glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1720 have_atomic_lock_free = false
1721 if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1722 error('GLib must be built with -march=i486 or later.')
1725 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1729 # Determination of thread implementation
1730 if host_system == 'windows' and not get_option('force_posix_threads')
1732 threads_implementation = 'win32'
1733 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1734 glib_conf.set('THREADS_WIN32', 1)
1736 thread_dep = dependency('threads')
1737 threads_implementation = 'posix'
1738 pthread_prefix = '''
1740 # define _GNU_SOURCE
1742 #include <pthread.h>'''
1743 glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1744 glib_conf.set('THREADS_POSIX', 1)
1745 if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1746 glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1748 if cc.has_header_symbol('pthread.h', 'pthread_attr_setinheritsched')
1749 glib_conf.set('HAVE_PTHREAD_ATTR_SETINHERITSCHED', 1)
1751 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1752 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1754 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1755 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1757 if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1758 glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1761 if cc.has_header_symbol('sys/syscall.h', 'SYS_sched_getattr')
1762 glib_conf.set('HAVE_SYS_SCHED_GETATTR', 1)
1765 # Assume that pthread_setname_np is available in some form; same as configure
1766 if cc.links(pthread_prefix + '''
1768 pthread_setname_np("example");
1771 name : 'pthread_setname_np(const char*)',
1772 dependencies : thread_dep)
1774 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1775 elif cc.links(pthread_prefix + '''
1777 pthread_setname_np(pthread_self(), "example");
1780 name : 'pthread_setname_np(pthread_t, const char*)',
1781 dependencies : thread_dep)
1782 # Linux, Solaris, etc.
1783 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1784 elif cc.links(pthread_prefix + '''
1786 pthread_setname_np(pthread_self(), "%s", "example");
1789 name : 'pthread_setname_np(pthread_t, const char*, void*)',
1790 dependencies : thread_dep)
1792 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG', 1)
1793 elif cc.links(pthread_prefix + '''
1794 #include <pthread_np.h>
1796 pthread_set_name_np(pthread_self(), "example");
1799 name : 'pthread_set_name_np(pthread_t, const char*)',
1800 dependencies : thread_dep)
1801 # FreeBSD, DragonFlyBSD, OpenBSD, etc.
1802 glib_conf.set('HAVE_PTHREAD_SET_NAME_NP', 1)
1806 # FIXME: we should make it print the result and always return 0, so that
1807 # the output in meson shows up as green
1808 stack_grows_check_prog = '''
1809 volatile int *a = 0, *b = 0;
1821 return b > a ? 0 : 1;
1825 rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
1826 growing_stack = rres.returncode() == 0
1828 growing_stack = meson.get_cross_property('growing_stack', false)
1831 glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack)
1835 # We should never use the MinGW C library's iconv because it may not be
1836 # available in the actual runtime environment. On Windows, we always use
1837 # the built-in implementation
1838 iconv_opt = get_option('iconv')
1839 if host_system == 'windows'
1841 # We have a #include "win_iconv.c" in gconvert.c on Windows, so we don't need
1842 # any external library for it
1843 if iconv_opt != 'auto'
1844 warning('-Diconv was set to @0@, which was ignored')
1848 if ['auto', 'libc'].contains(iconv_opt) and cc.has_function('iconv_open')
1852 if not found_iconv and ['auto', 'external'].contains(iconv_opt) and cc.has_header_symbol('iconv.h', 'iconv_open')
1853 libiconv = [cc.find_library('iconv')]
1858 error('iconv implementation "@0@" not found'.format(iconv_opt))
1862 if get_option('internal_pcre')
1864 use_system_pcre = false
1866 pcre = dependency('libpcre', version: '>= 8.31', required : false) # Should check for Unicode support, too. FIXME
1868 if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
1869 # MSVC: Search for the PCRE library by the configuration, which corresponds
1870 # to the output of CMake builds of PCRE. Note that debugoptimized
1871 # is really a Release build with .PDB files.
1872 if buildtype == 'debug'
1873 pcre = cc.find_library('pcred', required : false)
1875 pcre = cc.find_library('pcre', required : false)
1879 use_system_pcre = pcre.found()
1881 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1883 use_pcre_static_flag = false
1885 if host_system == 'windows'
1886 if not use_system_pcre
1887 use_pcre_static_flag = true
1889 pcre_static = cc.links('''#define PCRE_STATIC
1897 name : 'Windows system PCRE is a static build')
1899 use_pcre_static_flag = true
1904 libm = cc.find_library('m', required : false)
1905 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
1907 # Don't use the bundled ZLib sources until we are sure that we can't find it on
1909 libz_dep = dependency('zlib', required : false)
1910 if not libz_dep.found()
1911 if cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
1912 libz_dep = cc.find_library('z', required : false)
1914 libz_dep = cc.find_library('zlib1', required : false)
1915 if not libz_dep.found()
1916 libz_dep = cc.find_library('zlib', required : false)
1919 if not libz_dep.found() or not cc.has_header('zlib.h')
1920 libz_dep = subproject('zlib').get_variable('zlib_dep')
1924 # First check in libc, fallback to libintl, and as last chance build
1925 # proxy-libintl subproject.
1926 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
1927 # implementations. This could be extended if issues are found in some platforms.
1928 if cc.has_function('ngettext')
1930 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset')
1932 libintl = cc.find_library('intl', required : false)
1933 if not libintl.found()
1934 libintl = subproject('proxy-libintl').get_variable('intl_dep')
1935 have_bind_textdomain_codeset = true # proxy-libintl supports it
1937 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset',
1938 dependencies : libintl)
1942 glib_conf.set('HAVE_BIND_TEXTDOMAIN_CODESET', have_bind_textdomain_codeset)
1944 # We require gettext to always be present
1945 glib_conf.set('HAVE_DCGETTEXT', 1)
1946 glib_conf.set('HAVE_GETTEXT', 1)
1948 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
1950 # libmount is only used by gio, but we need to fetch the libs to generate the
1951 # pkg-config file below
1953 if host_system == 'linux'
1954 libmount_dep = dependency('mount', version : '>=2.23', required : get_option('libmount'))
1955 glib_conf.set('HAVE_LIBMOUNT', libmount_dep.found())
1958 if host_system == 'windows'
1959 winsock2 = cc.find_library('ws2_32')
1963 if host_system == 'linux'
1964 selinux_dep = dependency('libselinux', required: get_option('selinux'))
1966 glib_conf.set('HAVE_SELINUX', selinux_dep.found())
1970 if host_system != 'windows' and get_option('xattr')
1971 # either glibc or libattr can provide xattr support
1972 # for both of them, we check for getxattr being in
1973 # the library and a valid xattr header.
1976 if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
1977 glib_conf.set('HAVE_SYS_XATTR_H', 1)
1978 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
1979 #failure. try libattr
1980 elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
1981 glib_conf.set('HAVE_ATTR_XATTR_H', 1)
1982 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
1983 xattr_dep = [cc.find_library('xattr')]
1985 error('No getxattr implementation found in C library or libxattr')
1988 glib_conf.set('HAVE_XATTR', 1)
1989 if cc.compiles(glib_conf_prefix + '''
1991 #ifdef HAVE_SYS_TYPES_H
1992 #include <sys/types.h>
1994 #ifdef HAVE_SYS_XATTR_H
1995 #include <sys/xattr.h>
1996 #elif HAVE_ATTR_XATTR_H
1997 #include <attr/xattr.h>
2001 ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
2004 name : 'XATTR_NOFOLLOW')
2005 glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
2009 # If strlcpy is present (BSD and similar), check that it conforms to the BSD
2010 # specification. Specifically Solaris 8's strlcpy() does not, see
2011 # https://bugzilla.gnome.org/show_bug.cgi?id=53933 for further context.
2012 if cc.has_function('strlcpy')
2014 rres = cc.run('''#include <stdlib.h>
2018 (void) strlcpy (p, "hi", 10);
2019 if (strlcat (p, "bye", 0) != 3)
2023 name : 'OpenBSD strlcpy/strlcat')
2024 if rres.compiled() and rres.returncode() == 0
2025 glib_conf.set('HAVE_STRLCPY', 1)
2027 elif meson.get_cross_property('have_strlcpy', false)
2028 glib_conf.set('HAVE_STRLCPY', 1)
2032 cmdline_test_code = '''
2034 #include <sys/stat.h>
2043 /* This code is a dumbed-down version of g_file_get_contents() */
2047 #define BUFSIZE 1024
2048 char result[BUFSIZE];
2049 struct stat stat_buf;
2051 int fd = open ("/proc/self/cmdline", O_RDONLY|O_BINARY);
2053 assert (fstat (fd, &stat_buf) == 0);
2055 if (stat_buf.st_size > 0 && S_ISREG (stat_buf.st_mode))
2056 assert (read (fd, result, BUFSIZE) > 0);
2059 FILE *f = fdopen (fd, "r");
2061 assert (fread (result, 1, BUFSIZE, f) > 0);
2070 exit (__getcmdline ());
2074 rres = cc.run(cmdline_test_code, name : '/proc/self/cmdline')
2075 have_proc_self_cmdline = rres.compiled() and rres.returncode() == 0
2077 have_proc_self_cmdline = meson.get_cross_property('have_proc_self_cmdline', false)
2080 glib_conf.set('HAVE_PROC_SELF_CMDLINE', have_proc_self_cmdline)
2082 python = import('python').find_installation('python3')
2083 # used for '#!/usr/bin/env <name>'
2084 python_name = 'python3'
2086 python_version = python.language_version()
2087 python_version_req = '>=3.5'
2088 if not python_version.version_compare(python_version_req)
2089 error('Requires Python @0@, @1@ found.'.format(python_version_req, python_version))
2092 # Determine which user environment-dependent files that we want to install
2093 have_bash = find_program('bash', required : false).found() # For completion scripts
2094 have_sh = find_program('sh', required : false).found() # For glib-gettextize
2096 # Some installed tests require a custom environment
2097 env_program = find_program('env', required: installed_tests_enabled)
2099 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
2100 if host_system == 'sunos'
2101 glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
2102 glib_conf.set('_XOPEN_SOURCE', 2)
2103 glib_conf.set('__EXTENSIONS__',1)
2106 # Sadly Meson does not expose this value:
2107 # https://github.com/mesonbuild/meson/pull/3460
2108 if host_system == 'windows'
2109 # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
2110 # with no explanation. Do the same here for now but this could be revisited if
2112 export_dynamic_ldflags = []
2113 elif host_system == 'cygwin'
2114 export_dynamic_ldflags = ['-Wl,--export-all-symbols']
2115 elif host_system == 'darwin'
2116 export_dynamic_ldflags = []
2117 elif host_system == 'sunos'
2118 export_dynamic_ldflags = []
2120 export_dynamic_ldflags = ['-Wl,--export-dynamic']
2125 if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
2126 # Ensure MSVC-compatible struct packing convention is used when
2127 # compiling for Win32 with gcc. It is used for the whole project and exposed
2129 win32_cflags = ['-mms-bitfields']
2130 add_project_arguments(win32_cflags, language : 'c')
2132 # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
2133 win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi']
2134 elif host_system == 'cygwin'
2135 win32_ldflags = ['-luser32', '-lkernel32']
2139 want_dtrace = get_option('dtrace')
2140 enable_dtrace = false
2142 # Since dtrace support is opt-in we just error out if it was requested but
2143 # is not available. We don't bother with autodetection yet.
2146 error('GLib dtrace support not yet compatible with macOS dtrace')
2148 dtrace = find_program('dtrace', required : true) # error out if not found
2149 if not cc.has_header('sys/sdt.h')
2150 error('dtrace support needs sys/sdt.h header')
2152 # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
2153 dtrace_obj_gen = generator(dtrace,
2154 output : '@BASENAME@.o',
2155 arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2156 # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
2157 # -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
2158 dtrace_hdr_gen = generator(dtrace,
2159 output : '@BASENAME@.h',
2160 arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
2161 glib_conf.set('HAVE_DTRACE', 1)
2162 enable_dtrace = true
2166 want_systemtap = get_option('systemtap')
2167 enable_systemtap = false
2169 if want_systemtap and enable_dtrace
2170 tapset_install_dir = get_option('tapset_install_dir')
2171 if tapset_install_dir == ''
2172 tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
2174 stp_cdata = configuration_data()
2175 stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
2176 stp_cdata.set('LT_CURRENT', minor_version * 100)
2177 stp_cdata.set('LT_REVISION', micro_version)
2178 enable_systemtap = true
2182 test_timeout_slow = 180
2184 pkg = import('pkgconfig')
2185 windows = import('windows')
2196 # xgettext is optional (on Windows for instance)
2197 if find_program('xgettext', required : get_option('nls')).found()
2201 # Install glib-gettextize executable, if a UNIX-style shell is found
2203 # These should not contain " quotes around the values
2204 gettextize_conf = configuration_data()
2205 gettextize_conf.set('PACKAGE', 'glib')
2206 gettextize_conf.set('VERSION', meson.project_version())
2207 gettextize_conf.set('prefix', glib_prefix)
2208 gettextize_conf.set('datarootdir', glib_datadir)
2209 gettextize_conf.set('datadir', glib_datadir)
2210 configure_file(input : 'glib-gettextize.in',
2211 install_dir : glib_bindir,
2212 output : 'glib-gettextize',
2213 configuration : gettextize_conf)
2216 # Install m4 macros that other projects use
2217 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
2218 install_dir : join_paths(get_option('datadir'), 'aclocal'))
2220 if host_system != 'windows'
2221 # Install Valgrind suppression file (except on Windows,
2222 # as Valgrind is currently not supported on Windows)
2223 install_data('glib.supp',
2224 install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
2227 configure_file(output : 'config.h', configuration : glib_conf)
2229 if host_system == 'windows'
2230 install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
2233 if get_option('man')
2234 xsltproc = find_program('xsltproc', required : true)
2235 xsltproc_command = [
2238 '--stringparam', 'man.output.quietly', '1',
2239 '--stringparam', 'funcsynopsis.style', 'ansi',
2240 '--stringparam', 'man.th.extra1.suppress', '1',
2241 '--stringparam', 'man.authors.section.enabled', '0',
2242 '--stringparam', 'man.copyright.section.enabled', '0',
2244 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
2247 man1_dir = join_paths(glib_prefix, get_option('mandir'), 'man1')
2250 gnome = import('gnome')
2251 subdir('docs/reference')