1 project('glib', 'c', 'cpp',
3 meson_version : '>= 0.48.0',
5 'buildtype=debugoptimized',
11 cc = meson.get_compiler('c')
12 cxx = meson.get_compiler('cpp')
14 cc_can_run = not meson.is_cross_build() or meson.has_exe_wrapper()
16 if cc.get_id() == 'msvc'
17 # Ignore several spurious warnings for things glib does very commonly
18 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
19 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
20 # NOTE: Only add warnings here if you are sure they're spurious
21 add_project_arguments('/wd4035', '/wd4715', '/wd4116',
22 '/wd4046', '/wd4068', '/wo4090', '/FImsvc_recommended_pragmas.h',language : 'c')
23 # Disable SAFESEH with MSVC for plugins and libs that use external deps that
24 # are built with MinGW
25 noseh_link_args = ['/SAFESEH:NO']
26 # Set the input and exec encoding to utf-8, like is the default with GCC
27 add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c')
30 # -mms-bitfields vs -fnative-struct ?
33 host_system = host_machine.system()
35 glib_version = meson.project_version()
36 glib_api_version = '2.0'
37 version_arr = glib_version.split('.')
38 major_version = version_arr[0].to_int()
39 minor_version = version_arr[1].to_int()
40 micro_version = version_arr[2].to_int()
42 interface_age = minor_version.is_odd() ? 0 : micro_version
43 binary_age = 100 * minor_version + micro_version
46 # Maintain compatibility with previous libtool versioning
47 # current = minor * 100 + micro
48 current = binary_age - interface_age
49 library_version = '@0@.@1@.@2@'.format(soversion, current, interface_age)
50 darwin_versions = [current + 1, '@0@.@1@'.format(current + 1, interface_age)]
52 configinc = include_directories('.')
53 glibinc = include_directories('glib')
54 gobjectinc = include_directories('gobject')
55 gmoduleinc = include_directories('gmodule')
56 gioinc = include_directories('gio')
58 glib_prefix = get_option('prefix')
59 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
60 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
61 glib_libexecdir = join_paths(glib_prefix, get_option('libexecdir'))
62 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
63 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
64 glib_includedir = join_paths(glib_prefix, get_option('includedir'))
65 glib_giomodulesdir = get_option('gio_module_dir')
66 if glib_giomodulesdir == ''
67 glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
70 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
72 installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
73 installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
74 installed_tests_enabled = get_option('installed_tests')
75 installed_tests_template = files('template.test.in')
76 installed_tests_template_tap = files('template-tap.test.in')
78 add_project_arguments('-D_GNU_SOURCE', language: 'c')
80 # Disable strict aliasing;
81 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
82 if cc.has_argument('-fno-strict-aliasing')
83 add_project_arguments('-fno-strict-aliasing', language: 'c')
86 ########################
87 # Configuration begins #
88 ########################
89 glib_conf = configuration_data()
90 glibconfig_conf = configuration_data()
92 # accumulated list of defines as we check for them, so we can easily
93 # use them later in test programs (autoconf does this automatically)
96 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
97 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
98 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
99 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
100 glib_conf.set('GLIB_BINARY_AGE', binary_age)
101 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
102 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
103 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
104 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
105 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
106 glib_conf.set_quoted('PACKAGE_URL', '')
107 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
108 glib_conf.set('ENABLE_NLS', 1)
110 # used by the .rc.in files
111 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
113 glib_conf.set('_GNU_SOURCE', 1)
115 if host_system == 'windows'
116 # Poll doesn't work on devices on Windows
117 glib_conf.set('BROKEN_POLL', true)
120 if host_system == 'windows' and cc.get_id() != 'msvc'
121 # FIXME: Ideally we shouldn't depend on this on Windows and should use
122 # 64 bit capable Windows API that also works with MSVC.
123 # The autotools build did set this for mingw and while meson sets it
124 # for gcc/clang by default, it doesn't do so on Windows.
125 glib_conf.set('_FILE_OFFSET_BITS', 64)
128 # Check for GNU visibility attributes
129 g_have_gnuc_visibility = cc.compiles('''
131 __attribute__ ((visibility ("hidden")))
136 __attribute__ ((visibility ("internal")))
141 __attribute__ ((visibility ("protected")))
146 __attribute__ ((visibility ("default")))
159 # Not supported by MSVC, but MSVC also won't support visibility,
160 # so it's OK to pass -Werror explicitly. Replace with
161 # override_options : 'werror=true' once that is supported
163 name : 'GNU C visibility attributes test')
165 if g_have_gnuc_visibility
166 glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
169 # Detect and set symbol visibility
170 glib_hidden_visibility_args = []
171 if get_option('default_library') != 'static'
172 if host_system == 'windows'
173 glib_conf.set('DLL_EXPORT', true)
174 if cc.get_id() == 'msvc'
175 glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
176 elif cc.has_argument('-fvisibility=hidden')
177 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
178 glib_hidden_visibility_args = ['-fvisibility=hidden']
180 elif cc.has_argument('-fvisibility=hidden')
181 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
182 glib_hidden_visibility_args = ['-fvisibility=hidden']
186 if host_system == 'windows' and get_option('default_library') == 'static'
187 glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
188 glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
191 # FIXME: what about Cygwin (G_WITH_CYGWIN)
192 if host_system == 'windows'
193 glib_os = '''#define G_OS_WIN32
194 #define G_PLATFORM_WIN32'''
196 glib_os = '#define G_OS_UNIX'
198 glibconfig_conf.set('glib_os', glib_os)
200 # We need to know the build type to determine what .lib files we need on Visual Studio
201 # for dependencies that don't normally come with pkg-config files for Visual Studio builds
202 buildtype = get_option('buildtype')
204 glib_debug_cflags = []
205 if buildtype.startswith('debug')
206 glib_debug_cflags += ['-DG_ENABLE_DEBUG']
207 elif buildtype == 'release'
208 glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
211 add_project_arguments(glib_debug_cflags, language: 'c')
213 # check for header files
218 'dirent.h', # MSC does not come with this by default
252 'sys/time.h', # MSC does not come with this by default
268 define = 'HAVE_' + h.underscorify().to_upper()
269 glib_conf.set(define, 1)
270 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
274 # FIXME: Use cc.check_header from Meson 0.47.
275 # FreeBSD includes a malloc.h which always throw compilation error.
276 if cc.compiles('#include <malloc.h>', name : 'malloc.h')
277 glib_conf.set('HAVE_MALLOC_H', 1)
278 glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
281 if cc.has_header('linux/netlink.h')
282 glib_conf.set('HAVE_NETLINK', 1)
285 if glib_conf.has('HAVE_LOCALE_H')
286 if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
287 glib_conf.set('HAVE_LC_MESSAGES', 1)
291 struct_stat_blkprefix = '''
292 #include <sys/types.h>
293 #include <sys/stat.h>
297 #ifdef HAVE_SYS_STATFS_H
298 #include <sys/statfs.h>
300 #ifdef HAVE_SYS_PARAM_H
301 #include <sys/param.h>
303 #ifdef HAVE_SYS_MOUNT_H
304 #include <sys/mount.h>
309 [ 'stat', 'st_mtimensec' ],
310 [ 'stat', 'st_mtim.tv_nsec' ],
311 [ 'stat', 'st_atimensec' ],
312 [ 'stat', 'st_atim.tv_nsec' ],
313 [ 'stat', 'st_ctimensec' ],
314 [ 'stat', 'st_ctim.tv_nsec' ],
315 [ 'stat', 'st_birthtime' ],
316 [ 'stat', 'st_birthtimensec' ],
317 [ 'stat', 'st_birthtim' ],
318 [ 'stat', 'st_birthtim.tv_nsec' ],
319 [ 'stat', 'st_blksize', struct_stat_blkprefix ],
320 [ 'stat', 'st_blocks', struct_stat_blkprefix ],
321 [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
322 [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
323 [ 'dirent', 'd_type', '''#include <sys/types.h>
324 #include <dirent.h>''' ],
325 [ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
326 [ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
327 [ 'tm', 'tm_gmtoff', '#include <time.h>' ],
328 [ 'tm', '__tm_gmtoff', '#include <time.h>' ],
331 foreach m : struct_members
332 header_check_prefix = glib_conf_prefix
334 header_check_prefix = header_check_prefix + m[2]
336 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
338 if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
339 define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
340 glib_conf.set(define, 1)
341 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
347 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
350 '-Wduplicated-branches',
351 '-Wimplicit-fallthrough',
352 '-Wmisleading-indentation',
353 '-Wstrict-prototypes',
355 # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
356 # building with -Wbad-function-cast.
357 '-Wno-bad-function-cast',
358 '-Werror=declaration-after-statement',
360 '-Werror=implicit-function-declaration',
362 '-Werror=missing-include-dirs',
363 '-Werror=missing-prototypes',
364 '-Werror=pointer-arith',
366 warning_c_link_args = [
369 if get_option('bsymbolic_functions')
370 warning_c_link_args += ['-Wl,-Bsymbolic-functions']
374 warning_c_link_args = []
377 add_project_arguments(cc.get_supported_arguments(warning_c_args), language: 'c')
379 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
380 # means we cannot use that flag in add_project_link_arguments(), and must add
381 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
382 # because that is what the autotools build did.
383 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
385 glib_link_flags = cc.get_supported_link_arguments(warning_c_link_args)
387 # Windows Support (7+)
388 if host_system == 'windows'
389 glib_conf.set('_WIN32_WINNT', '0x0601')
452 if glib_conf.has('HAVE_SYS_STATVFS_H')
453 functions += ['statvfs']
455 have_func_statvfs = false
457 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
458 functions += ['statfs']
460 have_func_statfs = false
463 if host_system == 'windows'
464 iphlpapi_dep = cc.find_library('iphlpapi')
465 iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
466 foreach ifunc : iphlpapi_funcs
467 iphl_prefix = '''#define _WIN32_WINNT @0@
468 #include <winsock2.h>
469 #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
470 if cc.has_function(ifunc,
471 prefix : iphl_prefix,
472 dependencies : iphlpapi_dep)
473 idefine = 'HAVE_' + ifunc.underscorify().to_upper()
474 glib_conf.set(idefine, 1)
475 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
476 set_variable('have_func_' + ifunc, true)
478 set_variable('have_func_' + ifunc, false)
482 functions += ['if_indextoname', 'if_nametoindex']
485 # AIX splice is something else
486 if host_system != 'aix'
487 functions += ['splice']
490 foreach f : functions
491 if cc.has_function(f)
492 define = 'HAVE_' + f.underscorify().to_upper()
493 glib_conf.set(define, 1)
494 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
495 set_variable('have_func_' + f, true)
497 set_variable('have_func_' + f, false)
501 # Check that stpcpy() is usable; must use header
502 if cc.has_function('stpcpy', prefix : '#include <string.h>')
503 glib_conf.set('HAVE_STPCPY', 1)
506 # Check that posix_memalign() is usable; must use header
507 if cc.has_function('posix_memalign', prefix : '#include <stdlib.h>')
508 glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
511 # Check that posix_spawn() is usable; must use header
512 if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
513 glib_conf.set('HAVE_POSIX_SPAWN', 1)
516 # Check whether strerror_r returns char *
517 if have_func_strerror_r
518 if cc.compiles('''#define _GNU_SOURCE
521 char error_string[256];
522 char *ptr = strerror_r (-2, error_string, 256);
523 char c = *strerror_r (-2, error_string, 256);
524 return c != 0 && ptr != (void*) 0L;
527 name : 'strerror_r() returns char *')
528 glib_conf.set('STRERROR_R_CHAR_P', 1,
529 description: 'Defined if strerror_r returns char *')
533 # Special-case these functions that have alternative names on Windows/MSVC
534 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
535 glib_conf.set('HAVE_SNPRINTF', 1)
536 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
537 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
538 hack_define = '1\n#define snprintf _snprintf'
539 glib_conf.set('HAVE_SNPRINTF', hack_define)
540 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
543 if cc.has_function('strcasecmp')
544 glib_conf.set('HAVE_STRCASECMP', 1)
545 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
546 elif cc.has_function('_stricmp')
547 hack_define = '1\n#define strcasecmp _stricmp'
548 glib_conf.set('HAVE_STRCASECMP', hack_define)
549 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
552 if cc.has_function('strncasecmp')
553 glib_conf.set('HAVE_STRNCASECMP', 1)
554 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
555 elif cc.has_function('_strnicmp')
556 hack_define = '1\n#define strncasecmp _strnicmp'
557 glib_conf.set('HAVE_STRNCASECMP', hack_define)
558 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
561 if cc.has_header_symbol('sys/sysmacros.h', 'major')
562 glib_conf.set('MAJOR_IN_SYSMACROS', 1)
563 elif cc.has_header_symbol('sys/mkdev.h', 'major')
564 glib_conf.set('MAJOR_IN_MKDEV', 1)
565 elif cc.has_header_symbol('sys/types.h', 'major')
566 glib_conf.set('MAJOR_IN_TYPES', 1)
569 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
570 glib_conf.set('HAVE_RTLD_LAZY', 1)
573 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
574 glib_conf.set('HAVE_RTLD_NOW', 1)
577 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
578 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
581 # Check whether to use statfs or statvfs
582 # Some systems have both statfs and statvfs, pick the most "native" for these
583 if have_func_statfs and have_func_statvfs
584 # on solaris and irix, statfs doesn't even have the f_bavail field
585 if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
586 have_func_statfs = false
588 # at least on linux, statfs is the actual syscall
589 have_func_statvfs = false
593 glib_conf.set('USE_STATFS', 1)
594 stat_func_to_use = 'statfs'
595 elif have_func_statvfs
596 glib_conf.set('USE_STATVFS', 1)
597 stat_func_to_use = 'statvfs'
599 stat_func_to_use = 'neither'
601 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
603 if host_system == 'linux'
604 if cc.has_function('mkostemp',
605 prefix: '''#define _GNU_SOURCE
606 #include <stdlib.h>''')
607 glib_conf.set('HAVE_MKOSTEMP', 1)
612 glib_have_os_x_9_or_later = false
613 glib_have_carbon = false
614 glib_have_cocoa = false
615 if host_system == 'darwin'
616 add_languages('objc')
617 objcc = meson.get_compiler('objc')
619 osx_ldflags += ['-Wl,-framework,CoreFoundation']
621 # Mac OS X Carbon support
622 glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
623 #include <CoreServices/CoreServices.h>''',
624 name : 'Mac OS X Carbon support')
627 glib_conf.set('HAVE_CARBON', true)
628 osx_ldflags += '-Wl,-framework,Carbon'
629 glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
630 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
631 #error Compiling for minimum OS X version before 10.9
633 name : 'OS X 9 or later')
636 # Mac OS X Cocoa support
637 glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
638 #ifdef GNUSTEP_BASE_VERSION
639 #error "Detected GNUstep, not Cocoa"
641 name : 'Mac OS X Cocoa support')
644 glib_conf.set('HAVE_COCOA', true)
645 osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
648 # FIXME: libgio mix C and objC source files and there is no way to reliably
649 # know which language flags it's going to use to link. Add to both languages
650 # for now. See https://github.com/mesonbuild/meson/issues/3585.
651 add_project_link_arguments(osx_ldflags, language : ['objc', 'c'])
655 if cc.links('''#include <linux/futex.h>
656 #include <sys/syscall.h>
658 int main (int argc, char ** argv) {
659 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
661 }''', name : 'futex(2) system call')
662 glib_conf.set('HAVE_FUTEX', 1)
665 # Check for eventfd(2)
666 if cc.links('''#include <sys/eventfd.h>
668 int main (int argc, char ** argv) {
669 eventfd (0, EFD_CLOEXEC);
671 }''', name : 'eventfd(2) system call')
672 glib_conf.set('HAVE_EVENTFD', 1)
675 clock_gettime_test_code = '''
678 int main (int argc, char ** argv) {
679 return clock_gettime(CLOCK_REALTIME, &t);
682 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
683 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
684 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
685 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
686 librt = cc.find_library('rt')
689 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
691 if cc.compiles(glib_conf_prefix + '''
693 #ifdef HAVE_SYS_PARAM_H
694 #include <sys/param.h>
696 #ifdef HAVE_SYS_VFS_H
699 #ifdef HAVE_SYS_MOUNT_H
700 #include <sys/mount.h>
702 #ifdef HAVE_SYS_STATFS_H
703 #include <sys/statfs.h>
705 void some_func (void) {
708 }''', name : 'number of arguments to statfs() (n=2)')
709 glib_conf.set('STATFS_ARGS', 2)
710 elif cc.compiles(glib_conf_prefix + '''
712 #ifdef HAVE_SYS_PARAM_H
713 #include <sys/param.h>
715 #ifdef HAVE_SYS_VFS_H
718 #ifdef HAVE_SYS_MOUNT_H
719 #include <sys/mount.h>
721 #ifdef HAVE_SYS_STATFS_H
722 #include <sys/statfs.h>
724 void some_func (void) {
726 statfs("/", &st, sizeof (st), 0);
727 }''', name : 'number of arguments to statfs() (n=4)')
728 glib_conf.set('STATFS_ARGS', 4)
730 error('Unable to determine number of arguments to statfs()')
734 # open takes O_DIRECTORY as an option
736 if cc.compiles('''#include <fcntl.h>
737 #include <sys/types.h>
738 #include <sys/stat.h>],
739 void some_func (void) {
740 open(0, O_DIRECTORY, 0);
741 }''', name : 'open() option O_DIRECTORY')
742 glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
745 # Check whether there is a vsnprintf() function with C99 semantics installed.
746 # (similar tests to AC_FUNC_VSNPRINTF_C99)
747 # Check whether there is a snprintf() function with C99 semantics installed.
748 # (similar tests to AC_FUNC_SNPRINTF_C99)
749 # Check whether there is a printf() function with Unix98 semantics installed.
750 # (similar tests to AC_FUNC_PRINTF_UNIX98)
751 have_good_vsnprintf = false
752 have_good_snprintf = false
753 have_good_printf = false
755 if host_system == 'windows' and cc.get_id() == 'msvc'
756 # Unfortunately the Visual Studio 2015+ implementations of C99-style
757 # snprintf and vsnprintf don't seem to be quite good enough.
758 # (Sorry, I don't know exactly what is the problem,
759 # but it is related to floating point formatting and decimal point vs. comma.)
760 # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
761 # rigorous enough to notice, though.
762 glib_conf.set('HAVE_C99_SNPRINTF', false)
763 glib_conf.set('HAVE_C99_VSNPRINTF', false)
764 glib_conf.set('HAVE_UNIX98_PRINTF', false)
766 vsnprintf_c99_test_code = '''
778 r = vsnprintf(buffer, 5, s, args);
784 /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
785 implementation. The above will return 7 but if you replace
786 the size of the buffer with 0, it borks! */
788 r = vsnprintf(buffer, 0, s, args);
805 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
806 if rres.compiled() and rres.returncode() == 0
807 glib_conf.set('HAVE_C99_VSNPRINTF', 1)
808 have_good_vsnprintf = true
811 have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
812 glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
815 snprintf_c99_test_code = '''
826 r = snprintf(buffer, 5, "1234567");
831 r = snprintf(buffer, 0, "1234567");
836 r = snprintf(NULL, 0, "1234567");
852 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
853 if rres.compiled() and rres.returncode() == 0
854 glib_conf.set('HAVE_C99_SNPRINTF', 1)
855 have_good_snprintf = true
858 have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
859 glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
862 printf_unix98_test_code = '''
870 sprintf (buffer, "%2\$d %3\$d %1\$d", 1, 2, 3);
871 if (strcmp ("2 3 1", buffer) == 0)
877 rres = cc.run(printf_unix98_test_code, name : 'Unix98 printf positional parameters')
878 if rres.compiled() and rres.returncode() == 0
879 glib_conf.set('HAVE_UNIX98_PRINTF', 1)
880 have_good_printf = true
883 have_good_printf = meson.get_cross_property('have_unix98_printf', false)
884 glib_conf.set('HAVE_UNIX98_PRINTF', have_good_printf)
888 if host_system == 'windows'
889 glib_conf.set_quoted('EXEEXT', '.exe')
891 glib_conf.set('EXEEXT', '')
894 if have_good_vsnprintf and have_good_snprintf and have_good_printf
895 # Our printf is 'good' only if vsnpintf()/snprintf()/printf() supports C99 well enough
896 glib_conf.set('HAVE_GOOD_PRINTF', 1)
898 glib_conf.set('HAVE_VASPRINTF', 1)
901 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF',
902 have_good_vsnprintf and have_good_snprintf and have_good_printf)
904 # Check whether the printf() family supports Unix98 %n$ positional parameters
905 # AC_FUNC_PRINTF_UNIX98
906 # Nothing uses HAVE_UNIX98_PRINTF
909 # Check for nl_langinfo and CODESET
910 if cc.links('''#include <langinfo.h>
911 int main (int argc, char ** argv) {
912 char *codeset = nl_langinfo (CODESET);
914 }''', name : 'nl_langinfo and CODESET')
915 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
916 glib_conf.set('HAVE_CODESET', 1)
919 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
920 if cc.links('''#include <langinfo.h>
921 int main (int argc, char ** argv) {
923 str = nl_langinfo (PM_STR);
924 str = nl_langinfo (D_T_FMT);
925 str = nl_langinfo (D_FMT);
926 str = nl_langinfo (T_FMT);
927 str = nl_langinfo (T_FMT_AMPM);
928 str = nl_langinfo (MON_1);
929 str = nl_langinfo (ABMON_12);
930 str = nl_langinfo (DAY_1);
931 str = nl_langinfo (ABDAY_7);
933 }''', name : 'nl_langinfo (PM_STR)')
934 glib_conf.set('HAVE_LANGINFO_TIME', 1)
936 if cc.links('''#include <langinfo.h>
937 int main (int argc, char ** argv) {
939 str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
940 str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
941 str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
942 str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
943 str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
944 str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
945 str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
946 str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
947 str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
948 str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
950 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
951 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
954 # Check for nl_langinfo and alternative month names
955 if cc.links('''#ifndef _GNU_SOURCE
958 #include <langinfo.h>
959 int main (int argc, char ** argv) {
961 str = nl_langinfo (ALTMON_1);
962 str = nl_langinfo (ALTMON_2);
963 str = nl_langinfo (ALTMON_3);
964 str = nl_langinfo (ALTMON_4);
965 str = nl_langinfo (ALTMON_5);
966 str = nl_langinfo (ALTMON_6);
967 str = nl_langinfo (ALTMON_7);
968 str = nl_langinfo (ALTMON_8);
969 str = nl_langinfo (ALTMON_9);
970 str = nl_langinfo (ALTMON_10);
971 str = nl_langinfo (ALTMON_11);
972 str = nl_langinfo (ALTMON_12);
974 }''', name : 'nl_langinfo (ALTMON_n)')
975 glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
978 # Check for nl_langinfo and abbreviated alternative month names
979 if cc.links('''#ifndef _GNU_SOURCE
982 #include <langinfo.h>
983 int main (int argc, char ** argv) {
985 str = nl_langinfo (_NL_ALTMON_1);
986 str = nl_langinfo (_NL_ALTMON_2);
987 str = nl_langinfo (_NL_ALTMON_3);
988 str = nl_langinfo (_NL_ALTMON_4);
989 str = nl_langinfo (_NL_ALTMON_5);
990 str = nl_langinfo (_NL_ALTMON_6);
991 str = nl_langinfo (_NL_ALTMON_7);
992 str = nl_langinfo (_NL_ALTMON_8);
993 str = nl_langinfo (_NL_ALTMON_9);
994 str = nl_langinfo (_NL_ALTMON_10);
995 str = nl_langinfo (_NL_ALTMON_11);
996 str = nl_langinfo (_NL_ALTMON_12);
998 }''', name : 'nl_langinfo (_NL_ALTMON_n)')
999 glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
1002 # Check if C compiler supports the 'signed' keyword
1003 if not cc.compiles('''signed char x;''', name : 'signed')
1004 glib_conf.set('signed', '/* NOOP */')
1007 # Check if the ptrdiff_t type exists
1008 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
1009 glib_conf.set('HAVE_PTRDIFF_T', 1)
1012 # Check for sig_atomic_t type
1013 if cc.links('''#include <signal.h>
1014 #include <sys/types.h>
1015 sig_atomic_t val = 42;
1016 int main (int argc, char ** argv) {
1017 return val == 42 ? 0 : 1;
1018 }''', name : 'sig_atomic_t')
1019 glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
1022 # Check if 'long long' works
1023 # jm_AC_TYPE_LONG_LONG
1024 if cc.compiles('''long long ll = 1LL;
1026 int some_func (void) {
1027 long long llmax = (long long) -1;
1028 return ll << i | ll >> i | llmax / ll | llmax % ll;
1029 }''', name : 'long long')
1030 glib_conf.set('HAVE_LONG_LONG', 1)
1031 have_long_long = true
1033 have_long_long = false
1036 # Test whether the compiler supports the 'long double' type.
1037 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
1038 long double foo = 0.0;
1039 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
1040 int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
1041 name : 'long double')
1042 glib_conf.set('HAVE_LONG_DOUBLE', 1)
1045 # Test whether <stddef.h> has the 'wchar_t' type.
1046 if cc.has_header_symbol('stddef.h', 'wchar_t')
1047 glib_conf.set('HAVE_WCHAR_T', 1)
1050 # Test whether <wchar.h> has the 'wint_t' type.
1051 if cc.has_header_symbol('wchar.h', 'wint_t')
1052 glib_conf.set('HAVE_WINT_T', 1)
1055 found_uintmax_t = false
1057 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
1058 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1059 # jm_AC_HEADER_INTTYPES_H
1060 if cc.compiles('''#include <sys/types.h>
1061 #include <inttypes.h>
1062 void some_func (void) {
1063 uintmax_t i = (uintmax_t) -1;
1064 }''', name : 'uintmax_t in inttypes.h')
1065 glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1066 found_uintmax_t = true
1069 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1070 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1071 # jm_AC_HEADER_STDINT_H
1072 if cc.compiles('''#include <sys/types.h>
1074 void some_func (void) {
1075 uintmax_t i = (uintmax_t) -1;
1076 }''', name : 'uintmax_t in stdint.h')
1077 glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1078 found_uintmax_t = true
1081 # Define intmax_t to 'long' or 'long long'
1082 # if it is not already defined in <stdint.h> or <inttypes.h>.
1083 # For simplicity, we assume that a header file defines 'intmax_t' if and
1084 # only if it defines 'uintmax_t'.
1086 glib_conf.set('HAVE_INTMAX_T', 1)
1088 glib_conf.set('intmax_t', 'long long')
1090 glib_conf.set('intmax_t', 'long')
1093 char_size = cc.sizeof('char')
1094 short_size = cc.sizeof('short')
1095 int_size = cc.sizeof('int')
1096 voidp_size = cc.sizeof('void*')
1097 long_size = cc.sizeof('long')
1099 long_long_size = cc.sizeof('long long')
1103 sizet_size = cc.sizeof('size_t')
1104 if cc.get_id() == 'msvc'
1105 ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1107 ssizet_size = cc.sizeof('ssize_t')
1110 # Some platforms (Apple) hard-code int64_t to long long instead of
1111 # using long on 64-bit architectures. This can cause type mismatch
1112 # warnings when trying to interface with code using the standard
1113 # library type. Test for the warnings and set gint64 to whichever
1115 if long_long_size == long_size
1116 if cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1117 #pragma options langlvl=stdc99
1119 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1126 }''', name : 'int64_t is long')
1127 int64_t_typedef = 'long'
1128 elif cc.compiles('''#if defined(_AIX) && !defined(__GNUC__)
1129 #pragma options langlvl=stdc99
1131 #pragma GCC diagnostic error "-Wincompatible-pointer-types"
1136 long long *i2 = &i1;
1138 }''', name : 'int64_t is long long')
1139 int64_t_typedef = 'long long'
1144 char_align = cc.alignment('char')
1145 short_align = cc.alignment('short')
1146 int_align = cc.alignment('int')
1147 voidp_align = cc.alignment('void*')
1148 long_align = cc.alignment('long')
1149 long_long_align = cc.alignment('long long')
1150 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1151 # be 64-bit in C99, and it is available on all supported compilers
1152 sizet_align = cc.alignment('size_t')
1154 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1156 glib_conf.set('SIZEOF_CHAR', char_size)
1157 glib_conf.set('SIZEOF_INT', int_size)
1158 glib_conf.set('SIZEOF_SHORT', short_size)
1159 glib_conf.set('SIZEOF_LONG', long_size)
1160 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1161 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1162 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1163 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1176 error('Compiler provides no native 16-bit integer type')
1178 glibconfig_conf.set('gint16', gint16)
1179 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1180 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1181 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1188 guint32_align = short_align
1194 guint32_align = int_align
1200 guint32_align = long_align
1202 error('Compiler provides no native 32-bit integer type')
1204 glibconfig_conf.set('gint32', gint32)
1205 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1206 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1207 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1208 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1216 gint64_constant='(val)'
1217 guint64_constant='(val)'
1218 guint64_align = int_align
1219 elif long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long')
1225 gint64_constant='(val##L)'
1226 guint64_constant='(val##UL)'
1227 guint64_align = long_align
1228 elif long_long_size == 8 and (long_long_size != long_size or int64_t_typedef == 'long long')
1229 gint64 = 'long long'
1230 glib_extension='G_GNUC_EXTENSION '
1231 gint64_modifier=int64_m
1232 gint64_format=int64_m + 'i'
1233 guint64_format=int64_m + 'u'
1234 gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1235 guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1236 guint64_align = long_long_align
1238 error('Compiler provides no native 64-bit integer type')
1240 glibconfig_conf.set('glib_extension', glib_extension)
1241 glibconfig_conf.set('gint64', gint64)
1242 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1243 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1244 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1245 glibconfig_conf.set('gint64_constant', gint64_constant)
1246 glibconfig_conf.set('guint64_constant', guint64_constant)
1247 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1249 if host_system == 'windows'
1250 glibconfig_conf.set('g_pid_type', 'void*')
1251 glibconfig_conf.set_quoted('g_pid_format', 'p')
1252 if host_machine.cpu_family() == 'x86_64'
1253 glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1255 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1257 glibconfig_conf.set('g_dir_separator', '\\\\')
1258 glibconfig_conf.set('g_searchpath_separator', ';')
1260 glibconfig_conf.set('g_pid_type', 'int')
1261 glibconfig_conf.set_quoted('g_pid_format', 'i')
1262 glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1263 glibconfig_conf.set('g_dir_separator', '/')
1264 glibconfig_conf.set('g_searchpath_separator', ':')
1267 if sizet_size == short_size
1268 glibconfig_conf.set('glib_size_type_define', 'short')
1269 glibconfig_conf.set_quoted('gsize_modifier', 'h')
1270 glibconfig_conf.set_quoted('gssize_modifier', 'h')
1271 glibconfig_conf.set_quoted('gsize_format', 'hu')
1272 glibconfig_conf.set_quoted('gssize_format', 'hi')
1273 glibconfig_conf.set('glib_msize_type', 'SHRT')
1274 elif sizet_size == int_size
1275 glibconfig_conf.set('glib_size_type_define', 'int')
1276 glibconfig_conf.set_quoted('gsize_modifier', '')
1277 glibconfig_conf.set_quoted('gssize_modifier', '')
1278 glibconfig_conf.set_quoted('gsize_format', 'u')
1279 glibconfig_conf.set_quoted('gssize_format', 'i')
1280 glibconfig_conf.set('glib_msize_type', 'INT')
1281 elif sizet_size == long_size
1282 glibconfig_conf.set('glib_size_type_define', 'long')
1283 glibconfig_conf.set_quoted('gsize_modifier', 'l')
1284 glibconfig_conf.set_quoted('gssize_modifier', 'l')
1285 glibconfig_conf.set_quoted('gsize_format', 'lu')
1286 glibconfig_conf.set_quoted('gssize_format', 'li')
1287 glibconfig_conf.set('glib_msize_type', 'LONG')
1288 elif sizet_size == long_long_size
1289 glibconfig_conf.set('glib_size_type_define', 'long long')
1290 glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1291 glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1292 glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1293 glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1294 glibconfig_conf.set('glib_msize_type', 'INT64')
1296 error('Could not determine size of size_t.')
1299 if voidp_size == int_size
1300 glibconfig_conf.set('glib_intptr_type_define', 'int')
1301 glibconfig_conf.set_quoted('gintptr_modifier', '')
1302 glibconfig_conf.set_quoted('gintptr_format', 'i')
1303 glibconfig_conf.set_quoted('guintptr_format', 'u')
1304 glibconfig_conf.set('glib_gpi_cast', '(gint)')
1305 glibconfig_conf.set('glib_gpui_cast', '(guint)')
1306 elif voidp_size == long_size
1307 glibconfig_conf.set('glib_intptr_type_define', 'long')
1308 glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1309 glibconfig_conf.set_quoted('gintptr_format', 'li')
1310 glibconfig_conf.set_quoted('guintptr_format', 'lu')
1311 glibconfig_conf.set('glib_gpi_cast', '(glong)')
1312 glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1313 elif voidp_size == long_long_size
1314 glibconfig_conf.set('glib_intptr_type_define', 'long long')
1315 glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1316 glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1317 glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1318 glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1319 glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1321 error('Could not determine size of void *')
1324 if long_size != 8 and long_long_size != 8 and int_size != 8
1325 error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1328 glibconfig_conf.set('gintbits', int_size * 8)
1329 glibconfig_conf.set('glongbits', long_size * 8)
1330 glibconfig_conf.set('gsizebits', sizet_size * 8)
1331 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1333 # XXX: https://gitlab.gnome.org/GNOME/glib/issues/1413
1334 if host_system == 'windows'
1335 g_module_suffix = 'dll'
1337 g_module_suffix = 'so'
1339 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1341 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1342 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1343 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1344 glibconfig_conf.set('GLIB_VERSION', glib_version)
1346 glibconfig_conf.set('glib_void_p', voidp_size)
1347 glibconfig_conf.set('glib_long', long_size)
1348 glibconfig_conf.set('glib_size_t', sizet_size)
1349 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1350 if host_machine.endian() == 'big'
1351 glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1352 glibconfig_conf.set('g_bs_native', 'BE')
1353 glibconfig_conf.set('g_bs_alien', 'LE')
1355 glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1356 glibconfig_conf.set('g_bs_native', 'LE')
1357 glibconfig_conf.set('g_bs_alien', 'BE')
1360 # === va_copy checks ===
1361 # we currently check for all three va_copy possibilities, so we get
1362 # all results in config.log for bug reports.
1365 foreach try_func : [ '__va_copy', 'va_copy' ]
1366 if cc.compiles('''#include <stdarg.h>
1369 # include "msvc_recommended_pragmas.h"
1371 void f (int i, ...) {
1372 va_list args1, args2;
1373 va_start (args1, i);
1375 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1377 va_end (args1); va_end (args2);
1382 }'''.format(try_func),
1383 name : try_func + ' check')
1384 va_copy_func = try_func
1387 if va_copy_func != ''
1388 glib_conf.set('G_VA_COPY', va_copy_func)
1389 glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1391 glib_vacopy = '/* #undef G_VA_COPY */'
1394 va_list_val_copy_prog = '''
1397 void f (int i, ...) {
1398 va_list args1, args2;
1399 va_start (args1, i);
1401 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1403 va_end (args1); va_end (args2);
1411 rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1412 glib_va_val_copy = rres.returncode() == 0
1414 glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
1416 if not glib_va_val_copy
1417 glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1418 glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1420 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1422 # check for flavours of varargs macros
1423 g_have_iso_c_varargs = cc.compiles('''
1424 void some_func (void) {
1425 int a(int p1, int p2, int p3);
1426 #define call_a(...) a(1,__VA_ARGS__)
1428 }''', name : 'ISO C99 varargs macros in C')
1430 if g_have_iso_c_varargs
1431 glibconfig_conf.set('g_have_iso_c_varargs', '''
1433 # define G_HAVE_ISO_VARARGS 1
1437 g_have_iso_cxx_varargs = cxx.compiles('''
1438 void some_func (void) {
1439 int a(int p1, int p2, int p3);
1440 #define call_a(...) a(1,__VA_ARGS__)
1442 }''', name : 'ISO C99 varargs macros in C++')
1444 if g_have_iso_cxx_varargs
1445 glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1447 # define G_HAVE_ISO_VARARGS 1
1451 g_have_gnuc_varargs = cc.compiles('''
1452 void some_func (void) {
1453 int a(int p1, int p2, int p3);
1454 #define call_a(params...) a(1,params)
1456 }''', name : 'GNUC varargs macros')
1458 if cc.has_header('alloca.h')
1459 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1461 has_syspoll = cc.has_header('sys/poll.h')
1462 has_systypes = cc.has_header('sys/types.h')
1464 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1466 has_winsock2 = cc.has_header('winsock2.h')
1468 if has_syspoll and has_systypes
1470 #include<sys/poll.h>
1471 #include<sys/types.h>'''
1474 #define _WIN32_WINNT @0@
1475 #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1478 error('FIX POLL* defines')
1482 [ 'POLLIN', 'g_pollin', 1 ],
1483 [ 'POLLOUT', 'g_pollout', 4 ],
1484 [ 'POLLPRI', 'g_pollpri', 2 ],
1485 [ 'POLLERR', 'g_pollerr', 8 ],
1486 [ 'POLLHUP', 'g_pollhup', 16 ],
1487 [ 'POLLNVAL', 'g_pollnval', 32 ],
1490 if has_syspoll and has_systypes
1491 foreach d : poll_defines
1492 val = cc.compute_int(d[0], prefix: poll_includes)
1493 glibconfig_conf.set(d[1], val)
1496 # Due to a missed bug in configure.ac the poll test
1497 # never succeeded on Windows and used some pre-defined
1498 # values as a fallback. Keep using them to maintain
1499 # ABI compatibility with autotools builds of glibs
1500 # and with *any* glib-using code compiled against them,
1501 # since these values end up in a public header glibconfig.h.
1502 foreach d : poll_defines
1503 glibconfig_conf.set(d[1], d[2])
1507 # Internet address families
1508 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1509 if host_system == 'windows'
1511 #include <winsock2.h>'''
1514 #include <sys/types.h>
1515 #include <sys/socket.h>'''
1519 [ 'AF_UNIX', 'g_af_unix' ],
1520 [ 'AF_INET', 'g_af_inet' ],
1521 [ 'AF_INET6', 'g_af_inet6' ],
1522 [ 'MSG_OOB', 'g_msg_oob' ],
1523 [ 'MSG_PEEK', 'g_msg_peek' ],
1524 [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1526 foreach d : inet_defines
1527 val = cc.compute_int(d[0], prefix: inet_includes)
1528 glibconfig_conf.set(d[1], val)
1531 # We need a more robust approach here...
1532 host_cpu_family = host_machine.cpu_family()
1533 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')
1534 glib_memory_barrier_needed = false
1535 elif host_cpu_family.startswith('sparc') or host_cpu_family.startswith('alpha') or host_cpu_family.startswith('powerpc') or host_cpu_family == 'ia64'
1536 glib_memory_barrier_needed = true
1538 warning('Unknown host cpu: ' + host_cpu_family)
1539 glib_memory_barrier_needed = true
1541 glibconfig_conf.set('G_ATOMIC_OP_MEMORY_BARRIER_NEEDED', glib_memory_barrier_needed)
1543 # We need to decide at configure time if GLib will use real atomic
1544 # operations ("lock free") or emulated ones with a mutex. This is
1545 # because we must put this information in glibconfig.h so we know if
1546 # it is safe or not to inline using compiler intrinsics directly from
1549 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1550 # user is interested in knowing if they can use the atomic ops across
1553 # We can currently support the atomic ops natively when building GLib
1554 # with recent versions of GCC or MSVC.
1556 # Note that the atomic ops are only available with GCC on x86 when
1557 # using -march=i486 or higher. If we detect that the atomic ops are
1558 # not available but would be available given the right flags, we want
1559 # to abort and advise the user to fix their CFLAGS. It's better to do
1560 # that then to silently fall back on emulated atomic ops just because
1561 # the user had the wrong build environment.
1562 atomictest = '''int main() {
1563 volatile int atomic = 2;
1564 __sync_bool_compare_and_swap (&atomic, 2, 3);
1570 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1571 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1575 # We know that we can always use real ("lock free") atomic operations with MSVC
1576 if cc.get_id() == 'msvc' or cc.links(atomictest, name : 'atomic ops')
1577 have_atomic_lock_free = true
1578 if (host_system == 'android' or host_system == 'linux') and not cc.compiles(atomicdefine, name : 'atomic ops define')
1579 # When building for armv5 on Linux, gcc provides
1580 # __sync_bool_compare_and_swap but doesn't define
1581 # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1582 glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1585 have_atomic_lock_free = false
1586 if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1587 error('GLib must be built with -march=i486 or later.')
1590 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1594 # Determination of thread implementation
1595 if host_system == 'windows' and not get_option('force_posix_threads')
1597 threads_implementation = 'win32'
1598 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1599 glib_conf.set('THREADS_WIN32', 1)
1601 thread_dep = dependency('threads')
1602 threads_implementation = 'posix'
1603 pthread_prefix = '''
1605 # define _GNU_SOURCE
1607 #include <pthread.h>'''
1608 glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1609 glib_conf.set('THREADS_POSIX', 1)
1610 if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1611 glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1613 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1614 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1616 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1617 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1619 if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1620 glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1622 # Assume that pthread_setname_np is available in some form; same as configure
1623 if cc.links(pthread_prefix + '''
1625 pthread_setname_np("example");
1628 name : 'pthread_setname_np(const char*)',
1629 dependencies : thread_dep)
1631 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1632 elif cc.links(pthread_prefix + '''
1634 pthread_setname_np(pthread_self(), "example");
1637 name : 'pthread_setname_np(pthread_t, const char*)',
1638 dependencies : thread_dep)
1639 # Linux, Solaris, etc.
1640 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1644 # FIXME: we should make it print the result and always return 0, so that
1645 # the output in meson shows up as green
1646 stack_grows_check_prog = '''
1647 volatile int *a = 0, *b = 0;
1659 return b > a ? 0 : 1;
1663 rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
1664 growing_stack = rres.returncode() == 0
1666 growing_stack = meson.get_cross_property('growing_stack', false)
1669 glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack)
1673 # USE_LIBICONV_GNU: Using GNU libiconv
1674 # USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library
1676 # We should never use the MinGW C library's iconv. On Windows we use the
1677 # GNU implementation that ships with MinGW.
1679 # On Windows, just always use the built-in implementation
1680 if host_system == 'windows'
1682 glib_conf.set('USE_LIBICONV_NATIVE', true)
1685 iconv_opt = get_option('iconv')
1686 if iconv_opt == 'libc'
1687 if cc.has_function('iconv_open')
1691 elif iconv_opt == 'gnu'
1692 if cc.has_header_symbol('iconv.h', 'libiconv_open')
1693 glib_conf.set('USE_LIBICONV_GNU', true)
1694 libiconv = [cc.find_library('iconv')]
1697 elif iconv_opt == 'native'
1698 if cc.has_header_symbol('iconv.h', 'iconv_open')
1699 glib_conf.set('USE_LIBICONV_NATIVE', true)
1700 libiconv = [cc.find_library('iconv')]
1706 error('iconv implementation "@0@" not found'.format(iconv_opt))
1711 if get_option('internal_pcre')
1713 use_system_pcre = false
1715 pcre = dependency('libpcre', version: '>= 8.31', required : false) # Should check for Unicode support, too. FIXME
1717 if cc.get_id() == 'msvc'
1718 # MSVC: Search for the PCRE library by the configuration, which corresponds
1719 # to the output of CMake builds of PCRE. Note that debugoptimized
1720 # is really a Release build with .PDB files.
1721 if buildtype == 'debug'
1722 pcre = cc.find_library('pcred', required : false)
1724 pcre = cc.find_library('pcre', required : false)
1728 use_system_pcre = pcre.found()
1730 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1732 use_pcre_static_flag = false
1734 if host_system == 'windows'
1735 if not use_system_pcre
1736 use_pcre_static_flag = true
1738 pcre_static = cc.links('''#define PCRE_STATIC
1746 name : 'Windows system PCRE is a static build')
1748 use_pcre_static_flag = true
1753 libm = cc.find_library('m', required : false)
1754 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
1756 # Don't use the bundled ZLib sources until we are sure that we can't find it on
1758 libz_dep = dependency('zlib', required : false)
1759 if not libz_dep.found()
1760 if cc.get_id() != 'msvc'
1761 libz_dep = cc.find_library('z', required : false)
1763 libz_dep = cc.find_library('zlib1', required : false)
1764 if not libz_dep.found()
1765 libz_dep = cc.find_library('zlib', required : false)
1768 if not libz_dep.found() or not cc.has_header('zlib.h')
1769 libz_dep = subproject('zlib').get_variable('zlib_dep')
1773 # First check in libc, fallback to libintl, and as last chance build
1774 # proxy-libintl subproject.
1775 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
1776 # implementations. This could be extended if issues are found in some platforms.
1777 if cc.has_function('ngettext')
1779 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset')
1781 libintl = cc.find_library('intl', required : false)
1782 if not libintl.found()
1783 libintl = subproject('proxy-libintl').get_variable('intl_dep')
1784 have_bind_textdomain_codeset = true # proxy-libintl supports it
1786 have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset',
1787 dependencies : libintl)
1791 glib_conf.set('HAVE_BIND_TEXTDOMAIN_CODESET', have_bind_textdomain_codeset)
1793 # We require gettext to always be present
1794 glib_conf.set('HAVE_DCGETTEXT', 1)
1795 glib_conf.set('HAVE_GETTEXT', 1)
1797 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
1799 # libmount is only used by gio, but we need to fetch the libs to generate the
1800 # pkg-config file below
1802 if host_system == 'linux' and get_option('libmount')
1803 libmount_dep = [dependency('mount', version : '>=2.23', required : true)]
1804 glib_conf.set('HAVE_LIBMOUNT', 1)
1807 if host_system == 'windows'
1808 winsock2 = cc.find_library('ws2_32')
1812 if host_system == 'linux'
1813 selinux_dep = dependency('libselinux', required: get_option('selinux'))
1815 glib_conf.set('HAVE_SELINUX', selinux_dep.found())
1819 if host_system != 'windows' and get_option('xattr')
1820 # either glibc or libattr can provide xattr support
1821 # for both of them, we check for getxattr being in
1822 # the library and a valid xattr header.
1825 if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
1826 glib_conf.set('HAVE_SYS_XATTR_H', 1)
1827 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
1828 #failure. try libattr
1829 elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
1830 glib_conf.set('HAVE_ATTR_XATTR_H', 1)
1831 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
1832 xattr_dep = [cc.find_library('xattr')]
1834 error('No getxattr implementation found in C library or libxattr')
1837 glib_conf.set('HAVE_XATTR', 1)
1838 if cc.compiles(glib_conf_prefix + '''
1840 #ifdef HAVE_SYS_TYPES_H
1841 #include <sys/types.h>
1843 #ifdef HAVE_SYS_XATTR_H
1844 #include <sys/xattr.h>
1845 #elif HAVE_ATTR_XATTR_H
1846 #include <attr/xattr.h>
1850 ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
1853 name : 'XATTR_NOFOLLOW')
1854 glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
1858 # Test if we have strlcpy/strlcat with a compatible implementation:
1859 # https://bugzilla.gnome.org/show_bug.cgi?id=53933
1861 rres = cc.run('''#include <stdlib.h>
1865 (void) strlcpy (p, "hi", 10);
1866 if (strlcat (p, "bye", 0) != 3)
1870 name : 'OpenBSD strlcpy/strlcat')
1871 if rres.compiled() and rres.returncode() == 0
1872 glib_conf.set('HAVE_STRLCPY', 1)
1874 elif meson.get_cross_property('have_strlcpy', false)
1875 glib_conf.set('HAVE_STRLCPY', 1)
1878 python = import('python').find_installation('python3')
1879 # used for '#!/usr/bin/env <name>'
1880 python_name = 'python3'
1882 python_version = python.language_version()
1883 python_version_req = '>=3.4'
1884 if not python_version.version_compare(python_version_req)
1885 error('Requires Python @0@, @1@ found.'.format(python_version_req, python_version))
1888 # Determine which user environment-dependent files that we want to install
1889 have_bash = find_program('bash', required : false).found() # For completion scripts
1890 have_sh = find_program('sh', required : false).found() # For glib-gettextize
1892 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
1893 if host_system == 'sunos'
1894 glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
1895 glib_conf.set('_XOPEN_SOURCE', 2)
1896 glib_conf.set('__EXTENSIONS__',1)
1899 # Sadly Meson does not expose this value:
1900 # https://github.com/mesonbuild/meson/pull/3460
1901 if host_system == 'windows'
1902 # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
1903 # with no explanation. Do the same here for now but this could be revisited if
1905 export_dynamic_ldflags = []
1906 elif host_system == 'cygwin'
1907 export_dynamic_ldflags = ['-Wl,--export-all-symbols']
1908 elif host_system == 'darwin'
1909 export_dynamic_ldflags = []
1911 export_dynamic_ldflags = ['-Wl,--export-dynamic']
1916 if host_system == 'windows' and cc.get_id() != 'msvc'
1917 # Ensure MSVC-compatible struct packing convention is used when
1918 # compiling for Win32 with gcc. It is used for the whole project and exposed
1920 win32_cflags = ['-mms-bitfields']
1921 add_project_arguments(win32_cflags, language : 'c')
1923 # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
1924 win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi']
1925 elif host_system == 'cygwin'
1926 win32_ldflags = ['-luser32', '-lkernel32']
1930 want_dtrace = get_option('dtrace')
1931 enable_dtrace = false
1933 # Since dtrace support is opt-in we just error out if it was requested but
1934 # is not available. We don't bother with autodetection yet.
1937 error('GLib dtrace support not yet compatible with macOS dtrace')
1939 dtrace = find_program('dtrace', required : true) # error out if not found
1940 if not cc.has_header('sys/sdt.h')
1941 error('dtrace support needs sys/sdt.h header')
1943 # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
1944 dtrace_obj_gen = generator(dtrace,
1945 output : '@BASENAME@.o',
1946 arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1947 # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
1948 # -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
1949 dtrace_hdr_gen = generator(dtrace,
1950 output : '@BASENAME@.h',
1951 arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1952 glib_conf.set('HAVE_DTRACE', 1)
1953 enable_dtrace = true
1957 want_systemtap = get_option('systemtap')
1958 enable_systemtap = false
1960 if want_systemtap and enable_dtrace
1961 tapset_install_dir = get_option('tapset_install_dir')
1962 if tapset_install_dir == ''
1963 tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
1965 stp_cdata = configuration_data()
1966 stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
1967 stp_cdata.set('LT_CURRENT', minor_version * 100)
1968 stp_cdata.set('LT_REVISION', micro_version)
1969 enable_systemtap = true
1973 test_timeout_slow = 120
1975 pkg = import('pkgconfig')
1976 windows = import('windows')
1985 # xgettext is optional (on Windows for instance)
1986 if find_program('xgettext', required : get_option('nls')).found()
1990 # Install glib-gettextize executable, if a UNIX-style shell is found
1992 # These should not contain " quotes around the values
1993 gettextize_conf = configuration_data()
1994 gettextize_conf.set('PACKAGE', 'glib')
1995 gettextize_conf.set('VERSION', meson.project_version())
1996 gettextize_conf.set('prefix', glib_prefix)
1997 gettextize_conf.set('datarootdir', glib_datadir)
1998 gettextize_conf.set('datadir', glib_datadir)
1999 configure_file(input : 'glib-gettextize.in',
2001 install_dir : glib_bindir,
2002 output : 'glib-gettextize',
2003 configuration : gettextize_conf)
2006 # Install m4 macros that other projects use
2007 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
2008 install_dir : join_paths(get_option('datadir'), 'aclocal'))
2010 if host_system != 'windows'
2011 # Install Valgrind suppression file (except on Windows,
2012 # as Valgrind is currently not supported on Windows)
2013 install_data('glib.supp',
2014 install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
2017 configure_file(output : 'config.h', configuration : glib_conf)
2019 if host_system == 'windows'
2020 install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
2023 if get_option('man')
2024 xsltproc = find_program('xsltproc', required : true)
2025 xsltproc_command = [
2028 '--stringparam', 'man.output.quietly', '1',
2029 '--stringparam', 'funcsynopsis.style', 'ansi',
2030 '--stringparam', 'man.th.extra1.suppress', '1',
2031 '--stringparam', 'man.authors.section.enabled', '0',
2032 '--stringparam', 'man.copyright.section.enabled', '0',
2034 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
2037 man1_dir = get_option('mandir') + '/man1'
2040 gnome = import('gnome')
2041 subdir('docs/reference/glib')
2042 subdir('docs/reference/gobject')
2043 subdir('docs/reference/gio')