1 project('glib', 'c', 'cpp',
3 meson_version : '>= 0.46.1',
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 library_version = '@0@.@1@.@2@'.format(soversion, binary_age - interface_age, interface_age)
50 configinc = include_directories('.')
51 glibinc = include_directories('glib')
52 gobjectinc = include_directories('gobject')
53 gmoduleinc = include_directories('gmodule')
54 gioinc = include_directories('gio')
56 glib_prefix = get_option('prefix')
57 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
58 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
59 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
60 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
61 glib_includedir = join_paths(glib_prefix, get_option('includedir'))
62 glib_giomodulesdir = get_option('gio_module_dir')
63 if glib_giomodulesdir == ''
64 glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
67 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
69 add_project_arguments('-D_GNU_SOURCE', language: 'c')
71 # Disable strict aliasing;
72 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
73 if cc.has_argument('-fno-strict-aliasing')
74 add_project_arguments('-fno-strict-aliasing', language: 'c')
77 ########################
78 # Configuration begins #
79 ########################
80 glib_conf = configuration_data()
81 glibconfig_conf = configuration_data()
83 # accumulated list of defines as we check for them, so we can easily
84 # use them later in test programs (autoconf does this automatically)
87 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
88 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
89 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
90 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
91 glib_conf.set('GLIB_BINARY_AGE', binary_age)
92 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
93 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
94 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
95 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
96 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
97 glib_conf.set_quoted('PACKAGE_URL', '')
98 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
99 glib_conf.set('ENABLE_NLS', 1)
101 # used by the .rc.in files
102 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
104 glib_conf.set('_GNU_SOURCE', 1)
106 if host_system == 'windows'
107 # Poll doesn't work on devices on Windows
108 glib_conf.set('BROKEN_POLL', true)
111 # Check for GNU visibility attributes
112 g_have_gnuc_visibility = cc.compiles('''
114 __attribute__ ((visibility ("hidden")))
119 __attribute__ ((visibility ("internal")))
124 __attribute__ ((visibility ("protected")))
129 __attribute__ ((visibility ("default")))
142 # Not supported by MSVC, but MSVC also won't support visibility,
143 # so it's OK to pass -Werror explicitly. Replace with
144 # override_options : 'werror=true' once that is supported
146 name : 'GNU C visibility attributes test')
148 if g_have_gnuc_visibility
149 glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
152 # Detect and set symbol visibility
153 glib_hidden_visibility_args = []
154 if get_option('default_library') != 'static'
155 if host_system == 'windows'
156 glib_conf.set('DLL_EXPORT', true)
157 if cc.get_id() == 'msvc'
158 glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
159 elif cc.has_argument('-fvisibility=hidden')
160 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
161 glib_hidden_visibility_args = ['-fvisibility=hidden']
163 elif cc.has_argument('-fvisibility=hidden')
164 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
165 glib_hidden_visibility_args = ['-fvisibility=hidden']
169 if host_system == 'windows' and get_option('default_library') == 'static'
170 glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
171 glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
174 # FIXME: what about Cygwin (G_WITH_CYGWIN)
175 if host_system == 'windows'
176 glib_os = '''#define G_OS_WIN32
177 #define G_PLATFORM_WIN32'''
179 glib_os = '#define G_OS_UNIX'
181 glibconfig_conf.set('glib_os', glib_os)
183 # We need to know the build type to determine what .lib files we need on Visual Studio
184 # for dependencies that don't normally come with pkg-config files for Visual Studio builds
185 buildtype = get_option('buildtype')
187 glib_debug_cflags = []
188 if buildtype.startswith('debug')
189 glib_debug_cflags += ['-DG_ENABLE_DEBUG']
190 elif buildtype == 'release'
191 glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
194 add_project_arguments(glib_debug_cflags, language: 'c')
196 # check for header files
201 'dirent.h', # MSC does not come with this by default
234 'sys/time.h', # MSC does not come with this by default
250 define = 'HAVE_' + h.underscorify().to_upper()
251 glib_conf.set(define, 1)
252 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
256 # FIXME: Use cc.check_header from Meson 0.47.
257 # FreeBSD includes a malloc.h which always throw compilation error.
258 if cc.compiles('#include <malloc.h>', name : 'malloc.h')
259 glib_conf.set('HAVE_MALLOC_H', 1)
260 glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
263 if cc.has_header('linux/netlink.h')
264 glib_conf.set('HAVE_NETLINK', 1)
267 if glib_conf.has('HAVE_LOCALE_H')
268 if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
269 glib_conf.set('HAVE_LC_MESSAGES', 1)
273 struct_stat_blkprefix = '''
274 #include <sys/types.h>
275 #include <sys/stat.h>
279 #ifdef HAVE_SYS_STATFS_H
280 #include <sys/statfs.h>
282 #ifdef HAVE_SYS_PARAM_H
283 #include <sys/param.h>
285 #ifdef HAVE_SYS_MOUNT_H
286 #include <sys/mount.h>
291 [ 'stat', 'st_mtimensec' ],
292 [ 'stat', 'st_mtim.tv_nsec' ],
293 [ 'stat', 'st_atimensec' ],
294 [ 'stat', 'st_atim.tv_nsec' ],
295 [ 'stat', 'st_ctimensec' ],
296 [ 'stat', 'st_ctim.tv_nsec' ],
297 [ 'stat', 'st_birthtime' ],
298 [ 'stat', 'st_birthtimensec' ],
299 [ 'stat', 'st_birthtim' ],
300 [ 'stat', 'st_birthtim.tv_nsec' ],
301 [ 'stat', 'st_blksize', struct_stat_blkprefix ],
302 [ 'stat', 'st_blocks', struct_stat_blkprefix ],
303 [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
304 [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
305 [ 'dirent', 'd_type', '''#include <sys/types.h>
306 #include <dirent.h>''' ],
307 [ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
308 [ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
309 [ 'tm', 'tm_gmtoff', '#include <time.h>' ],
310 [ 'tm', '__tm_gmtoff', '#include <time.h>' ],
313 foreach m : struct_members
314 header_check_prefix = glib_conf_prefix
316 header_check_prefix = header_check_prefix + m[2]
318 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
320 if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
321 define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
322 glib_conf.set(define, 1)
323 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
329 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
332 '-Wduplicated-branches',
333 '-Wmisleading-indentation',
334 '-Wstrict-prototypes',
336 '-Werror=declaration-after-statement',
338 '-Werror=format-security',
339 '-Werror=implicit-function-declaration',
341 '-Werror=missing-include-dirs',
342 '-Werror=missing-prototypes',
343 '-Werror=pointer-arith',
348 if get_option('bsymbolic_functions')
349 test_c_link_args += ['-Wl,-Bsymbolic-functions']
353 test_c_link_args = []
356 add_project_arguments(cc.get_supported_arguments(test_c_args), language: 'c')
358 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
359 # means we cannot use that flag in add_project_link_arguments(), and must add
360 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
361 # because that is what the autotools build did.
362 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
364 glib_link_flags = cc.get_supported_link_arguments(test_c_link_args)
366 # Windows Support (7+)
367 if host_system == 'windows'
368 glib_conf.set('_WIN32_WINNT', '0x0601')
431 if glib_conf.has('HAVE_SYS_STATVFS_H')
432 functions += ['statvfs']
434 have_func_statvfs = false
436 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
437 functions += ['statfs']
439 have_func_statfs = false
442 if host_system == 'windows'
443 iphlpapi_dep = cc.find_library('iphlpapi')
444 iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
445 foreach ifunc : iphlpapi_funcs
446 iphl_prefix = '''#define _WIN32_WINNT @0@
447 #include <winsock2.h>
448 #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
449 if cc.has_function(ifunc,
450 prefix : iphl_prefix,
451 dependencies : iphlpapi_dep)
452 idefine = 'HAVE_' + ifunc.underscorify().to_upper()
453 glib_conf.set(idefine, 1)
454 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
455 set_variable('have_func_' + ifunc, true)
457 set_variable('have_func_' + ifunc, false)
461 functions += ['if_indextoname', 'if_nametoindex']
464 # AIX splice is something else
465 if host_system != 'aix'
466 functions += ['splice']
469 foreach f : functions
470 if cc.has_function(f)
471 define = 'HAVE_' + f.underscorify().to_upper()
472 glib_conf.set(define, 1)
473 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
474 set_variable('have_func_' + f, true)
476 set_variable('have_func_' + f, false)
480 # Check that stpcpy() is usable; must use header
481 if cc.has_function('stpcpy', prefix : '#include <string.h>')
482 glib_conf.set('HAVE_STPCPY', 1)
485 # Check that posix_memalign() is usable; must use header
486 if cc.has_function('posix_memalign', prefix : '#include <stdlib.h>')
487 glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
490 # Check that posix_spawn() is usable; must use header
491 if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
492 glib_conf.set('HAVE_POSIX_SPAWN', 1)
495 # Check whether strerror_r returns char *
496 if have_func_strerror_r
497 if cc.compiles('''#define _GNU_SOURCE
500 char error_string[256];
501 char *ptr = strerror_r (-2, error_string, 256);
502 char c = *strerror_r (-2, error_string, 256);
503 return c != 0 && ptr != (void*) 0L;
506 name : 'strerror_r() returns char *')
507 glib_conf.set('STRERROR_R_CHAR_P', 1,
508 description: 'Defined if strerror_r returns char *')
512 # Special-case these functions that have alternative names on Windows/MSVC
513 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
514 glib_conf.set('HAVE_SNPRINTF', 1)
515 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
516 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
517 hack_define = '1\n#define snprintf _snprintf'
518 glib_conf.set('HAVE_SNPRINTF', hack_define)
519 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
522 if cc.has_function('strcasecmp')
523 glib_conf.set('HAVE_STRCASECMP', 1)
524 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
525 elif cc.has_function('_stricmp')
526 hack_define = '1\n#define strcasecmp _stricmp'
527 glib_conf.set('HAVE_STRCASECMP', hack_define)
528 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
531 if cc.has_function('strncasecmp')
532 glib_conf.set('HAVE_STRNCASECMP', 1)
533 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
534 elif cc.has_function('_strnicmp')
535 hack_define = '1\n#define strncasecmp _strnicmp'
536 glib_conf.set('HAVE_STRNCASECMP', hack_define)
537 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
540 if cc.has_header_symbol('sys/sysmacros.h', 'major')
541 glib_conf.set('MAJOR_IN_SYSMACROS', 1)
542 elif cc.has_header_symbol('sys/mkdev.h', 'major')
543 glib_conf.set('MAJOR_IN_MKDEV', 1)
544 elif cc.has_header_symbol('sys/types.h', 'major')
545 glib_conf.set('MAJOR_IN_TYPES', 1)
548 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
549 glib_conf.set('HAVE_RTLD_LAZY', 1)
552 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
553 glib_conf.set('HAVE_RTLD_NOW', 1)
556 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
557 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
560 # Check whether to use statfs or statvfs
561 # Some systems have both statfs and statvfs, pick the most "native" for these
562 if have_func_statfs and have_func_statvfs
563 # on solaris and irix, statfs doesn't even have the f_bavail field
564 if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
565 have_func_statfs = false
567 # at least on linux, statfs is the actual syscall
568 have_func_statvfs = false
572 glib_conf.set('USE_STATFS', 1)
573 stat_func_to_use = 'statfs'
574 elif have_func_statvfs
575 glib_conf.set('USE_STATVFS', 1)
576 stat_func_to_use = 'statvfs'
578 stat_func_to_use = 'neither'
580 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
582 if host_system == 'linux'
583 if cc.has_function('mkostemp',
584 prefix: '''#define _GNU_SOURCE
585 #include <stdlib.h>''')
586 glib_conf.set('HAVE_MKOSTEMP', 1)
591 glib_have_os_x_9_or_later = false
592 glib_have_carbon = false
593 glib_have_cocoa = false
594 if host_system == 'darwin'
595 add_languages('objc')
596 objcc = meson.get_compiler('objc')
598 osx_ldflags += ['-Wl,-framework,CoreFoundation']
600 # Mac OS X Carbon support
601 glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
602 #include <CoreServices/CoreServices.h>''',
603 name : 'Mac OS X Carbon support')
606 glib_conf.set('HAVE_CARBON', true)
607 osx_ldflags += '-Wl,-framework,Carbon'
608 glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
609 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
610 #error Compiling for minimum OS X version before 10.9
612 name : 'OS X 9 or later')
615 # Mac OS X Cocoa support
616 glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
617 #ifdef GNUSTEP_BASE_VERSION
618 #error "Detected GNUstep, not Cocoa"
620 name : 'Mac OS X Cocoa support')
623 glib_conf.set('HAVE_COCOA', true)
624 osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
627 # FIXME: libgio mix C and objC source files and there is no way to reliably
628 # know which language flags it's going to use to link. Add to both languages
629 # for now. See https://github.com/mesonbuild/meson/issues/3585.
630 add_project_link_arguments(osx_ldflags, language : ['objc', 'c'])
634 if cc.links('''#include <linux/futex.h>
635 #include <sys/syscall.h>
637 int main (int argc, char ** argv) {
638 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
640 }''', name : 'futex(2) system call')
641 glib_conf.set('HAVE_FUTEX', 1)
644 # Check for eventfd(2)
645 if cc.links('''#include <sys/eventfd.h>
647 int main (int argc, char ** argv) {
648 eventfd (0, EFD_CLOEXEC);
650 }''', name : 'eventfd(2) system call')
651 glib_conf.set('HAVE_EVENTFD', 1)
654 clock_gettime_test_code = '''
657 int main (int argc, char ** argv) {
658 return clock_gettime(CLOCK_REALTIME, &t);
661 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
662 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
663 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
664 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
665 librt = cc.find_library('rt')
668 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
670 if cc.compiles(glib_conf_prefix + '''
672 #ifdef HAVE_SYS_PARAM_H
673 #include <sys/param.h>
675 #ifdef HAVE_SYS_VFS_H
678 #ifdef HAVE_SYS_MOUNT_H
679 #include <sys/mount.h>
681 #ifdef HAVE_SYS_STATFS_H
682 #include <sys/statfs.h>
684 void some_func (void) {
687 }''', name : 'number of arguments to statfs() (n=2)')
688 glib_conf.set('STATFS_ARGS', 2)
689 elif cc.compiles(glib_conf_prefix + '''
691 #ifdef HAVE_SYS_PARAM_H
692 #include <sys/param.h>
694 #ifdef HAVE_SYS_VFS_H
697 #ifdef HAVE_SYS_MOUNT_H
698 #include <sys/mount.h>
700 #ifdef HAVE_SYS_STATFS_H
701 #include <sys/statfs.h>
703 void some_func (void) {
705 statfs("/", &st, sizeof (st), 0);
706 }''', name : 'number of arguments to statfs() (n=4)')
707 glib_conf.set('STATFS_ARGS', 4)
709 error('Unable to determine number of arguments to statfs()')
713 # open takes O_DIRECTORY as an option
715 if cc.compiles('''#include <fcntl.h>
716 #include <sys/types.h>
717 #include <sys/stat.h>],
718 void some_func (void) {
719 open(0, O_DIRECTORY, 0);
720 }''', name : 'open() option O_DIRECTORY')
721 glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
724 # Check whether there is a vsnprintf() function with C99 semantics installed.
725 # AC_FUNC_VSNPRINTF_C99
726 # Check whether there is a snprintf() function with C99 semantics installed.
727 # AC_FUNC_SNPRINTF_C99
729 have_good_vsnprintf = false
730 have_good_snprintf = false
732 if host_system == 'windows' and cc.get_id() == 'msvc'
733 # Unfortunately the Visual Studio 2015+ implementations of C99-style
734 # snprintf and vsnprintf don't seem to be quite good enough.
735 # (Sorry, I don't know exactly what is the problem,
736 # but it is related to floating point formatting and decimal point vs. comma.)
737 # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
738 # rigorous enough to notice, though.
739 glib_conf.set('HAVE_C99_SNPRINTF', false)
740 glib_conf.set('HAVE_C99_VSNPRINTF', false)
742 vsnprintf_c99_test_code = '''
754 r = vsnprintf(buffer, 5, s, args);
760 /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
761 implementation. The above will return 7 but if you replace
762 the size of the buffer with 0, it borks! */
764 r = vsnprintf(buffer, 0, s, args);
781 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
782 if rres.compiled() and rres.returncode() == 0
783 glib_conf.set('HAVE_C99_VSNPRINTF', 1)
784 have_good_vsnprintf = true
787 have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
788 glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
791 snprintf_c99_test_code = '''
802 r = snprintf(buffer, 5, "1234567");
807 r = snprintf(buffer, 0, "1234567");
812 r = snprintf(NULL, 0, "1234567");
828 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
829 if rres.compiled() and rres.returncode() == 0
830 glib_conf.set('HAVE_C99_SNPRINTF', 1)
831 have_good_snprintf = true
834 have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
835 glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
839 if host_system == 'windows'
840 glib_conf.set_quoted('EXEEXT', '.exe')
842 glib_conf.set('EXEEXT', '')
845 if have_good_vsnprintf and have_good_snprintf
846 # Our printf is 'good' only if vsnpintf()/snprintf() supports C99 well enough
847 glib_conf.set('HAVE_GOOD_PRINTF', 1) # FIXME: Check for HAVE_UNIX98_PRINTF?
849 glib_conf.set('HAVE_VASPRINTF', 1)
852 # Check whether the printf() family supports Unix98 %n$ positional parameters
853 # AC_FUNC_PRINTF_UNIX98
854 # Nothing uses HAVE_UNIX98_PRINTF
857 # Check for nl_langinfo and CODESET
858 # FIXME: Check for HAVE_BIND_TEXTDOMAIN_CODESET
859 if cc.links('''#include <langinfo.h>
860 int main (int argc, char ** argv) {
861 char *codeset = nl_langinfo (CODESET);
863 }''', name : 'nl_langinfo and CODESET')
864 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
865 glib_conf.set('HAVE_CODESET', 1)
868 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
869 if cc.links('''#include <langinfo.h>
870 int main (int argc, char ** argv) {
872 str = nl_langinfo (PM_STR);
873 str = nl_langinfo (D_T_FMT);
874 str = nl_langinfo (D_FMT);
875 str = nl_langinfo (T_FMT);
876 str = nl_langinfo (T_FMT_AMPM);
877 str = nl_langinfo (MON_1);
878 str = nl_langinfo (ABMON_12);
879 str = nl_langinfo (DAY_1);
880 str = nl_langinfo (ABDAY_7);
882 }''', name : 'nl_langinfo (PM_STR)')
883 glib_conf.set('HAVE_LANGINFO_TIME', 1)
885 if cc.links('''#include <langinfo.h>
886 int main (int argc, char ** argv) {
888 str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
889 str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
890 str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
891 str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
892 str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
893 str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
894 str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
895 str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
896 str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
897 str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
899 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
900 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
903 # Check for nl_langinfo and alternative month names
904 if cc.links('''#ifndef _GNU_SOURCE
907 #include <langinfo.h>
908 int main (int argc, char ** argv) {
910 str = nl_langinfo (ALTMON_1);
911 str = nl_langinfo (ALTMON_2);
912 str = nl_langinfo (ALTMON_3);
913 str = nl_langinfo (ALTMON_4);
914 str = nl_langinfo (ALTMON_5);
915 str = nl_langinfo (ALTMON_6);
916 str = nl_langinfo (ALTMON_7);
917 str = nl_langinfo (ALTMON_8);
918 str = nl_langinfo (ALTMON_9);
919 str = nl_langinfo (ALTMON_10);
920 str = nl_langinfo (ALTMON_11);
921 str = nl_langinfo (ALTMON_12);
923 }''', name : 'nl_langinfo (ALTMON_n)')
924 glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
927 # Check for nl_langinfo and abbreviated alternative month names
928 if cc.links('''#ifndef _GNU_SOURCE
931 #include <langinfo.h>
932 int main (int argc, char ** argv) {
934 str = nl_langinfo (_NL_ALTMON_1);
935 str = nl_langinfo (_NL_ALTMON_2);
936 str = nl_langinfo (_NL_ALTMON_3);
937 str = nl_langinfo (_NL_ALTMON_4);
938 str = nl_langinfo (_NL_ALTMON_5);
939 str = nl_langinfo (_NL_ALTMON_6);
940 str = nl_langinfo (_NL_ALTMON_7);
941 str = nl_langinfo (_NL_ALTMON_8);
942 str = nl_langinfo (_NL_ALTMON_9);
943 str = nl_langinfo (_NL_ALTMON_10);
944 str = nl_langinfo (_NL_ALTMON_11);
945 str = nl_langinfo (_NL_ALTMON_12);
947 }''', name : 'nl_langinfo (_NL_ALTMON_n)')
948 glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
951 # Check if C compiler supports the 'signed' keyword
952 if not cc.compiles('''signed char x;''', name : 'signed')
953 glib_conf.set('signed', '/* NOOP */')
956 # Check if the ptrdiff_t type exists
957 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
958 glib_conf.set('HAVE_PTRDIFF_T', 1)
961 # Check for sig_atomic_t type
962 if cc.links('''#include <signal.h>
963 #include <sys/types.h>
964 sig_atomic_t val = 42;
965 int main (int argc, char ** argv) {
966 return val == 42 ? 0 : 1;
967 }''', name : 'sig_atomic_t')
968 glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
971 # Check if 'long long' works
972 # jm_AC_TYPE_LONG_LONG
973 if cc.compiles('''long long ll = 1LL;
975 int some_func (void) {
976 long long llmax = (long long) -1;
977 return ll << i | ll >> i | llmax / ll | llmax % ll;
978 }''', name : 'long long')
979 glib_conf.set('HAVE_LONG_LONG', 1)
980 have_long_long = true
982 have_long_long = false
985 # Test whether the compiler supports the 'long double' type.
986 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
987 long double foo = 0.0;
988 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
989 int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
990 name : 'long double')
991 glib_conf.set('HAVE_LONG_DOUBLE', 1)
994 # Test whether <stddef.h> has the 'wchar_t' type.
995 if cc.has_header_symbol('stddef.h', 'wchar_t')
996 glib_conf.set('HAVE_WCHAR_T', 1)
999 # Test whether <wchar.h> has the 'wint_t' type.
1000 if cc.has_header_symbol('wchar.h', 'wint_t')
1001 glib_conf.set('HAVE_WINT_T', 1)
1004 found_uintmax_t = false
1006 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
1007 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1008 # jm_AC_HEADER_INTTYPES_H
1009 if cc.compiles('''#include <sys/types.h>
1010 #include <inttypes.h>
1011 void some_func (void) {
1012 uintmax_t i = (uintmax_t) -1;
1013 }''', name : 'uintmax_t in inttypes.h')
1014 glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
1015 found_uintmax_t = true
1018 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1019 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1020 # jm_AC_HEADER_STDINT_H
1021 if cc.compiles('''#include <sys/types.h>
1023 void some_func (void) {
1024 uintmax_t i = (uintmax_t) -1;
1025 }''', name : 'uintmax_t in stdint.h')
1026 glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1027 found_uintmax_t = true
1030 # Define intmax_t to 'long' or 'long long'
1031 # if it is not already defined in <stdint.h> or <inttypes.h>.
1032 # For simplicity, we assume that a header file defines 'intmax_t' if and
1033 # only if it defines 'uintmax_t'.
1035 glib_conf.set('HAVE_INTMAX_T', 1)
1037 glib_conf.set('intmax_t', 'long long')
1039 glib_conf.set('intmax_t', 'long')
1042 char_size = cc.sizeof('char')
1043 short_size = cc.sizeof('short')
1044 int_size = cc.sizeof('int')
1045 voidp_size = cc.sizeof('void*')
1046 long_size = cc.sizeof('long')
1048 long_long_size = cc.sizeof('long long')
1052 sizet_size = cc.sizeof('size_t')
1053 if cc.get_id() == 'msvc'
1054 ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1056 ssizet_size = cc.sizeof('ssize_t')
1060 char_align = cc.alignment('char')
1061 short_align = cc.alignment('short')
1062 int_align = cc.alignment('int')
1063 voidp_align = cc.alignment('void*')
1064 long_align = cc.alignment('long')
1065 long_long_align = cc.alignment('long long')
1066 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1067 # be 64-bit in C99, and it is available on all supported compilers
1068 sizet_align = cc.alignment('size_t')
1070 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1072 glib_conf.set('SIZEOF_CHAR', char_size)
1073 glib_conf.set('SIZEOF_INT', int_size)
1074 glib_conf.set('SIZEOF_SHORT', short_size)
1075 glib_conf.set('SIZEOF_LONG', long_size)
1076 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1077 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1078 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1079 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1092 error('Compiler provides no native 16-bit integer type')
1094 glibconfig_conf.set('gint16', gint16)
1095 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1096 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1097 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1104 guint32_align = short_align
1110 guint32_align = int_align
1116 guint32_align = long_align
1118 error('Compiler provides no native 32-bit integer type')
1120 glibconfig_conf.set('gint32', gint32)
1121 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1122 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1123 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1124 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1132 gint64_constant='(val)'
1133 guint64_constant='(val)'
1134 guint64_align = int_align
1141 gint64_constant='(val##L)'
1142 guint64_constant='(val##UL)'
1143 guint64_align = long_align
1144 elif long_long_size == 8
1145 gint64 = 'long long'
1146 glib_extension='G_GNUC_EXTENSION '
1147 gint64_modifier=int64_m
1148 gint64_format=int64_m + 'i'
1149 guint64_format=int64_m + 'u'
1150 gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1151 guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1152 guint64_align = long_long_align
1154 error('Compiler provides no native 64-bit integer type')
1156 glibconfig_conf.set('glib_extension', glib_extension)
1157 glibconfig_conf.set('gint64', gint64)
1158 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1159 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1160 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1161 glibconfig_conf.set('gint64_constant', gint64_constant)
1162 glibconfig_conf.set('guint64_constant', guint64_constant)
1163 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1165 if host_system == 'windows'
1166 glibconfig_conf.set('g_pid_type', 'void*')
1167 glibconfig_conf.set_quoted('g_pid_format', 'p')
1168 if host_machine.cpu_family() == 'x86_64'
1169 glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1171 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1173 glibconfig_conf.set('g_dir_separator', '\\\\')
1174 glibconfig_conf.set('g_searchpath_separator', ';')
1176 glibconfig_conf.set('g_pid_type', 'int')
1177 glibconfig_conf.set_quoted('g_pid_format', 'i')
1178 glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1179 glibconfig_conf.set('g_dir_separator', '/')
1180 glibconfig_conf.set('g_searchpath_separator', ':')
1183 if sizet_size == short_size
1184 glibconfig_conf.set('glib_size_type_define', 'short')
1185 glibconfig_conf.set_quoted('gsize_modifier', 'h')
1186 glibconfig_conf.set_quoted('gssize_modifier', 'h')
1187 glibconfig_conf.set_quoted('gsize_format', 'hu')
1188 glibconfig_conf.set_quoted('gssize_format', 'hi')
1189 glibconfig_conf.set('glib_msize_type', 'SHRT')
1190 elif sizet_size == int_size
1191 glibconfig_conf.set('glib_size_type_define', 'int')
1192 glibconfig_conf.set_quoted('gsize_modifier', '')
1193 glibconfig_conf.set_quoted('gssize_modifier', '')
1194 glibconfig_conf.set_quoted('gsize_format', 'u')
1195 glibconfig_conf.set_quoted('gssize_format', 'i')
1196 glibconfig_conf.set('glib_msize_type', 'INT')
1197 elif sizet_size == long_size
1198 glibconfig_conf.set('glib_size_type_define', 'long')
1199 glibconfig_conf.set_quoted('gsize_modifier', 'l')
1200 glibconfig_conf.set_quoted('gssize_modifier', 'l')
1201 glibconfig_conf.set_quoted('gsize_format', 'lu')
1202 glibconfig_conf.set_quoted('gssize_format', 'li')
1203 glibconfig_conf.set('glib_msize_type', 'LONG')
1204 elif sizet_size == long_long_size
1205 glibconfig_conf.set('glib_size_type_define', 'long long')
1206 glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1207 glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1208 glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1209 glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1210 glibconfig_conf.set('glib_msize_type', 'INT64')
1212 error('Could not determine size of size_t.')
1215 if voidp_size == int_size
1216 glibconfig_conf.set('glib_intptr_type_define', 'int')
1217 glibconfig_conf.set_quoted('gintptr_modifier', '')
1218 glibconfig_conf.set_quoted('gintptr_format', 'i')
1219 glibconfig_conf.set_quoted('guintptr_format', 'u')
1220 glibconfig_conf.set('glib_gpi_cast', '(gint)')
1221 glibconfig_conf.set('glib_gpui_cast', '(guint)')
1222 elif voidp_size == long_size
1223 glibconfig_conf.set('glib_intptr_type_define', 'long')
1224 glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1225 glibconfig_conf.set_quoted('gintptr_format', 'li')
1226 glibconfig_conf.set_quoted('guintptr_format', 'lu')
1227 glibconfig_conf.set('glib_gpi_cast', '(glong)')
1228 glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1229 elif voidp_size == long_long_size
1230 glibconfig_conf.set('glib_intptr_type_define', 'long long')
1231 glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1232 glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1233 glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1234 glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1235 glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1237 error('Could not determine size of void *')
1240 if long_size != 8 and long_long_size != 8 and int_size != 8
1241 error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1244 glibconfig_conf.set('gintbits', int_size * 8)
1245 glibconfig_conf.set('glongbits', long_size * 8)
1246 glibconfig_conf.set('gsizebits', sizet_size * 8)
1247 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1249 # FIXME: maybe meson should tell us the libsuffix?
1250 if host_system == 'windows'
1251 g_module_suffix = 'dll'
1252 elif host_system == 'darwin'
1253 g_module_suffix = 'dylib'
1255 g_module_suffix = 'so'
1257 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1259 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1260 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1261 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1262 glibconfig_conf.set('GLIB_VERSION', glib_version)
1264 glibconfig_conf.set('glib_void_p', voidp_size)
1265 glibconfig_conf.set('glib_long', long_size)
1266 glibconfig_conf.set('glib_size_t', sizet_size)
1267 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1268 if host_machine.endian() == 'big'
1269 glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1270 glibconfig_conf.set('g_bs_native', 'BE')
1271 glibconfig_conf.set('g_bs_alien', 'LE')
1273 glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1274 glibconfig_conf.set('g_bs_native', 'LE')
1275 glibconfig_conf.set('g_bs_alien', 'BE')
1278 # === va_copy checks ===
1279 # we currently check for all three va_copy possibilities, so we get
1280 # all results in config.log for bug reports.
1283 foreach try_func : [ '__va_copy', 'va_copy' ]
1284 if cc.compiles('''#include <stdarg.h>
1287 # include "msvc_recommended_pragmas.h"
1289 void f (int i, ...) {
1290 va_list args1, args2;
1291 va_start (args1, i);
1293 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1295 va_end (args1); va_end (args2);
1300 }'''.format(try_func),
1301 name : try_func + ' check')
1302 va_copy_func = try_func
1305 if va_copy_func != ''
1306 glib_conf.set('G_VA_COPY', va_copy_func)
1307 glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1309 glib_vacopy = '/* #undef G_VA_COPY */'
1312 va_list_val_copy_prog = '''
1315 void f (int i, ...) {
1316 va_list args1, args2;
1317 va_start (args1, i);
1319 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1321 va_end (args1); va_end (args2);
1329 rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1330 glib_va_val_copy = rres.returncode() == 0
1332 glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
1334 if not glib_va_val_copy
1335 glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1336 glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1338 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1340 # check for flavours of varargs macros
1341 g_have_iso_c_varargs = cc.compiles('''
1342 void some_func (void) {
1343 int a(int p1, int p2, int p3);
1344 #define call_a(...) a(1,__VA_ARGS__)
1346 }''', name : 'ISO C99 varargs macros in C')
1348 if g_have_iso_c_varargs
1349 glibconfig_conf.set('g_have_iso_c_varargs', '''
1351 # define G_HAVE_ISO_VARARGS 1
1355 g_have_iso_cxx_varargs = cxx.compiles('''
1356 void some_func (void) {
1357 int a(int p1, int p2, int p3);
1358 #define call_a(...) a(1,__VA_ARGS__)
1360 }''', name : 'ISO C99 varargs macros in C++')
1362 if g_have_iso_cxx_varargs
1363 glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1365 # define G_HAVE_ISO_VARARGS 1
1369 g_have_gnuc_varargs = cc.compiles('''
1370 void some_func (void) {
1371 int a(int p1, int p2, int p3);
1372 #define call_a(params...) a(1,params)
1374 }''', name : 'GNUC varargs macros')
1376 if cc.has_header('alloca.h')
1377 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1379 has_syspoll = cc.has_header('sys/poll.h')
1380 has_systypes = cc.has_header('sys/types.h')
1382 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1384 has_winsock2 = cc.has_header('winsock2.h')
1386 if has_syspoll and has_systypes
1388 #include<sys/poll.h>
1389 #include<sys/types.h>'''
1392 #define _WIN32_WINNT @0@
1393 #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1396 error('FIX POLL* defines')
1400 [ 'POLLIN', 'g_pollin', 1 ],
1401 [ 'POLLOUT', 'g_pollout', 4 ],
1402 [ 'POLLPRI', 'g_pollpri', 2 ],
1403 [ 'POLLERR', 'g_pollerr', 8 ],
1404 [ 'POLLHUP', 'g_pollhup', 16 ],
1405 [ 'POLLNVAL', 'g_pollnval', 32 ],
1408 if has_syspoll and has_systypes
1409 foreach d : poll_defines
1410 val = cc.compute_int(d[0], prefix: poll_includes)
1411 glibconfig_conf.set(d[1], val)
1414 # Due to a missed bug in configure.ac the poll test
1415 # never succeeded on Windows and used some pre-defined
1416 # values as a fallback. Keep using them to maintain
1417 # ABI compatibility with autotools builds of glibs
1418 # and with *any* glib-using code compiled against them,
1419 # since these values end up in a public header glibconfig.h.
1420 foreach d : poll_defines
1421 glibconfig_conf.set(d[1], d[2])
1425 # Internet address families
1426 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1427 if host_system == 'windows'
1429 #include <winsock2.h>'''
1432 #include <sys/types.h>
1433 #include <sys/socket.h>'''
1437 [ 'AF_UNIX', 'g_af_unix' ],
1438 [ 'AF_INET', 'g_af_inet' ],
1439 [ 'AF_INET6', 'g_af_inet6' ],
1440 [ 'MSG_OOB', 'g_msg_oob' ],
1441 [ 'MSG_PEEK', 'g_msg_peek' ],
1442 [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1444 foreach d : inet_defines
1445 val = cc.compute_int(d[0], prefix: inet_includes)
1446 glibconfig_conf.set(d[1], val)
1449 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', true) # FIXME!
1451 # We need a more robust approach here...
1452 host_cpu_family = host_machine.cpu_family()
1453 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.startswith('crisv32') or host_cpu_family.startswith('etrax')
1454 glib_memory_barrier_needed = false
1455 elif host_cpu_family.startswith('sparc') or host_cpu_family.startswith('alpha') or host_cpu_family.startswith('powerpc') or host_cpu_family == 'ia64'
1456 glib_memory_barrier_needed = true
1458 warning('Unknown host cpu: ' + host_cpu_family)
1459 glib_memory_barrier_needed = true
1461 glibconfig_conf.set('G_ATOMIC_OP_MEMORY_BARRIER_NEEDED', glib_memory_barrier_needed)
1463 # We need to decide at configure time if GLib will use real atomic
1464 # operations ("lock free") or emulated ones with a mutex. This is
1465 # because we must put this information in glibconfig.h so we know if
1466 # it is safe or not to inline using compiler intrinsics directly from
1469 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1470 # user is interested in knowing if they can use the atomic ops across
1473 # We can currently support the atomic ops natively when building GLib
1474 # with recent versions of GCC or MSVC.
1476 # Note that the atomic ops are only available with GCC on x86 when
1477 # using -march=i486 or higher. If we detect that the atomic ops are
1478 # not available but would be available given the right flags, we want
1479 # to abort and advise the user to fix their CFLAGS. It's better to do
1480 # that then to silently fall back on emulated atomic ops just because
1481 # the user had the wrong build environment.
1482 atomictest = '''int main() {
1483 volatile int atomic = 2;
1484 __sync_bool_compare_and_swap (&atomic, 2, 3);
1490 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1491 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1495 # We know that we can always use real ("lock free") atomic operations with MSVC
1496 if cc.get_id() == 'msvc' or cc.links(atomictest, name : 'atomic ops')
1497 have_atomic_lock_free = true
1498 if host_system == 'android' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1499 # When building for armv5 on Android, gcc 4.9 provides
1500 # __sync_bool_compare_and_swap but doesn't define
1501 # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1502 glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1505 have_atomic_lock_free = false
1506 if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1507 error('GLib must be built with -march=i486 or later.')
1510 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1514 # Determination of thread implementation
1515 if host_system == 'windows' and not get_option('force_posix_threads')
1517 threads_implementation = 'win32'
1518 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1519 glib_conf.set('THREADS_WIN32', 1)
1521 # FIXME: probably needs more tweaking in meson for things like -D_REENTRANT etc.
1522 thread_dep = dependency('threads')
1523 threads_implementation = 'posix'
1524 pthread_prefix = '''
1526 # define _GNU_SOURCE
1528 #include <pthread.h>'''
1529 glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1530 glib_conf.set('THREADS_POSIX', 1)
1531 if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1532 glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1534 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1535 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1537 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1538 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1540 if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1541 glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1543 # Assume that pthread_setname_np is available in some form; same as configure
1544 if cc.links(pthread_prefix + '''
1546 pthread_setname_np("example");
1549 name : 'pthread_setname_np(const char*)',
1550 dependencies : thread_dep)
1552 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1553 elif cc.links(pthread_prefix + '''
1555 pthread_setname_np(pthread_self(), "example");
1558 name : 'pthread_setname_np(pthread_t, const char*)',
1559 dependencies : thread_dep)
1560 # Linux, Solaris, etc.
1561 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1565 # FIXME: we should make it print the result and always return 0, so that
1566 # the output in meson shows up as green
1567 stack_grows_check_prog = '''
1568 volatile int *a = 0, *b = 0;
1580 return b > a ? 0 : 1;
1584 rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
1585 growing_stack = rres.returncode() == 0
1587 growing_stack = meson.get_cross_property('growing_stack', false)
1590 glibconfig_conf.set('G_HAVE_GROWING_STACK', growing_stack)
1594 # USE_LIBICONV_GNU: Using GNU libiconv
1595 # USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library
1597 # We should never use the MinGW C library's iconv. On Windows we use the
1598 # GNU implementation that ships with MinGW.
1600 # On Windows, just always use the built-in implementation
1601 if host_system == 'windows'
1603 glib_conf.set('USE_LIBICONV_NATIVE', true)
1606 iconv_opt = get_option('iconv')
1607 if iconv_opt == 'libc'
1608 if cc.has_function('iconv_open')
1612 elif iconv_opt == 'gnu'
1613 if cc.has_header_symbol('iconv.h', 'libiconv_open')
1614 glib_conf.set('USE_LIBICONV_GNU', true)
1615 libiconv = [cc.find_library('iconv')]
1618 elif iconv_opt == 'native'
1619 if cc.has_header_symbol('iconv.h', 'iconv_open')
1620 glib_conf.set('USE_LIBICONV_NATIVE', true)
1621 libiconv = [cc.find_library('iconv')]
1627 error('iconv implementation "@0@" not found'.format(iconv_opt))
1632 if get_option('internal_pcre')
1634 use_system_pcre = false
1636 pcre = dependency('libpcre', required : false) # Should check for Unicode support, too. FIXME
1638 if cc.get_id() == 'msvc'
1639 # MSVC: Search for the PCRE library by the configuration, which corresponds
1640 # to the output of CMake builds of PCRE. Note that debugoptimized
1641 # is really a Release build with .PDB files.
1642 if buildtype == 'debug'
1643 pcre = cc.find_library('pcred', required : false)
1645 pcre = cc.find_library('pcre', required : false)
1649 use_system_pcre = pcre.found()
1651 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1653 use_pcre_static_flag = false
1655 if host_system == 'windows'
1656 if not use_system_pcre
1657 use_pcre_static_flag = true
1659 pcre_static = cc.links('''#define PCRE_STATIC
1667 name : 'Windows system PCRE is a static build')
1669 use_pcre_static_flag = true
1674 libm = cc.find_library('m', required : false)
1675 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
1676 if cc.get_id() != 'msvc'
1677 libz_dep = dependency('zlib', fallback : ['zlib', 'zlib_dep'])
1679 # MSVC: Don't use the bundled ZLib sources until we are sure that we can't
1680 # find the ZLib .lib
1681 libz_dep = dependency('zlib', required : false)
1683 # MSVC: Search for the ZLib .lib, which corresponds to the results of
1684 # of using ZLib's win32/makefile.msc.
1685 if not libz_dep.found()
1686 libz_dep = cc.find_library('zlib1', required : false)
1687 if not libz_dep.found()
1688 libz_dep = cc.find_library('zlib', required : false)
1689 if not libz_dep.found()
1690 libz_dep = subproject('zlib').get_variable('zlib_dep')
1696 # First check in libc, fallback to libintl, and as last chance build
1697 # proxy-libintl subproject.
1698 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
1699 # implementations. This could be extended if issues are found in some platforms.
1700 if cc.has_function('ngettext')
1703 libintl = cc.find_library('intl', required : false)
1704 if not libintl.found()
1705 libintl = subproject('proxy-libintl').get_variable('intl_dep')
1709 # We require gettext to always be present
1710 glib_conf.set('HAVE_DCGETTEXT', 1)
1711 glib_conf.set('HAVE_GETTEXT', 1)
1713 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
1714 # xgettext is optional (on Windows for instance)
1715 xgettext = find_program('xgettext', required : false)
1717 # libmount is only used by gio, but we need to fetch the libs to generate the
1718 # pkg-config file below
1720 if host_system == 'linux' and get_option('libmount')
1721 libmount_dep = [dependency('mount', version : '>=2.23', required : true)]
1722 glib_conf.set('HAVE_LIBMOUNT', 1)
1725 if host_system == 'windows'
1726 winsock2 = cc.find_library('ws2_32')
1730 if host_system == 'linux' and get_option('selinux')
1731 selinux_dep = [dependency('libselinux')]
1732 glib_conf.set('HAVE_SELINUX', 1)
1736 if host_system != 'windows' and get_option('xattr')
1737 # either glibc or libattr can provide xattr support
1738 # for both of them, we check for getxattr being in
1739 # the library and a valid xattr header.
1742 if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
1743 glib_conf.set('HAVE_SYS_XATTR_H', 1)
1744 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
1745 #failure. try libattr
1746 elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
1747 glib_conf.set('HAVE_ATTR_XATTR_H', 1)
1748 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
1749 xattr_dep = [cc.find_library('xattr')]
1751 error('No getxattr implementation found in C library or libxattr')
1754 glib_conf.set('HAVE_XATTR', 1)
1755 if cc.compiles(glib_conf_prefix + '''
1757 #ifdef HAVE_SYS_TYPES_H
1758 #include <sys/types.h>
1760 #ifdef HAVE_SYS_XATTR_H
1761 #include <sys/xattr.h>
1762 #elif HAVE_ATTR_XATTR_H
1763 #include <attr/xattr.h>
1767 ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
1770 name : 'XATTR_NOFOLLOW')
1771 glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
1775 # Test if we have strlcpy/strlcat with a compatible implementation:
1776 # https://bugzilla.gnome.org/show_bug.cgi?id=53933
1778 rres = cc.run('''#include <stdlib.h>
1782 (void) strlcpy (p, "hi", 10);
1783 if (strlcat (p, "bye", 0) != 3)
1787 name : 'OpenBSD strlcpy/strlcat')
1788 if rres.compiled() and rres.returncode() == 0
1789 glib_conf.set('HAVE_STRLCPY', 1)
1791 elif meson.get_cross_property('have_strlcpy', false)
1792 glib_conf.set('HAVE_STRLCPY', 1)
1795 python = import('python3').find_python()
1797 # Determine which user environment-dependent files that we want to install
1798 have_bash = find_program('bash', required : false).found() # For completion scripts
1799 have_m4 = find_program('m4', required : false).found() # For m4 macros
1800 have_sh = find_program('sh', required : false).found() # For glib-gettextize
1802 # FIXME: defines in config.h that are not actually used anywhere
1803 # (we add them for now to minimise the diff)
1804 glib_conf.set('HAVE_DLFCN_H', 1)
1805 glib_conf.set('STDC_HEADERS', 1)
1806 glib_conf.set('SIZEOF___INT64', 8)
1808 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
1809 if host_system == 'sunos'
1810 glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
1811 glib_conf.set('_XOPEN_SOURCE', 2)
1812 glib_conf.set('__EXTENSIONS__',1)
1815 # Sadly Meson does not expose this value:
1816 # https://github.com/mesonbuild/meson/pull/3460
1817 if host_system == 'windows'
1818 # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
1819 # with no explanation. Do the same here for now but this could be revisited if
1821 export_dynamic_ldflags = []
1822 elif host_system == 'cygwin'
1823 export_dynamic_ldflags = ['-Wl,--export-all-symbols']
1824 elif host_system == 'darwin'
1825 export_dynamic_ldflags = []
1827 export_dynamic_ldflags = ['-Wl,--export-dynamic']
1832 if host_system == 'windows' and cc.get_id() != 'msvc'
1833 # Ensure MSVC-compatible struct packing convention is used when
1834 # compiling for Win32 with gcc. It is used for the whole project and exposed
1836 win32_cflags = ['-mms-bitfields']
1837 add_project_arguments(win32_cflags, language : 'c')
1839 # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
1840 win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi']
1841 elif host_system == 'cygwin'
1842 win32_ldflags = ['-luser32', '-lkernel32']
1846 want_dtrace = get_option('dtrace')
1847 enable_dtrace = false
1849 # Since dtrace support is opt-in we just error out if it was requested but
1850 # is not available. We don't bother with autodetection yet.
1853 error('GLib dtrace support not yet compatible with macOS dtrace')
1855 dtrace = find_program('dtrace', required : true) # error out if not found
1856 if not cc.has_header('sys/sdt.h')
1857 error('dtrace support needs sys/sdt.h header')
1859 # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
1860 dtrace_obj_gen = generator(dtrace,
1861 output : '@BASENAME@.o',
1862 arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1863 # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
1864 # -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
1865 dtrace_hdr_gen = generator(dtrace,
1866 output : '@BASENAME@.h',
1867 arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1868 glib_conf.set('HAVE_DTRACE', 1)
1869 enable_dtrace = true
1873 want_systemtap = get_option('systemtap')
1874 enable_systemtap = false
1876 if want_systemtap and enable_dtrace
1877 tapset_install_dir = get_option('tapset_install_dir')
1878 if tapset_install_dir == ''
1879 tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
1881 stp_cdata = configuration_data()
1882 stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
1883 stp_cdata.set('LT_CURRENT', minor_version * 100)
1884 stp_cdata.set('LT_REVISION', micro_version)
1885 enable_systemtap = true
1889 pkg = import('pkgconfig')
1890 windows = import('windows')
1901 # Install glib-gettextize executable, if a UNIX-style shell is found
1903 # These should not contain " quotes around the values
1904 gettexize_conf = configuration_data()
1905 gettexize_conf.set('PACKAGE', 'glib')
1906 gettexize_conf.set('VERSION', meson.project_version())
1907 gettexize_conf.set('prefix', glib_prefix)
1908 gettexize_conf.set('datarootdir', glib_datadir)
1909 gettexize_conf.set('datadir', glib_datadir)
1910 configure_file(input : 'glib-gettextize.in',
1912 install_dir : 'bin',
1913 output : 'glib-gettextize',
1914 configuration : gettexize_conf)
1918 # Install m4 macros that other projects use
1919 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
1920 install_dir : join_paths(get_option('datadir'), 'aclocal'))
1923 if host_system != 'windows'
1924 # Install Valgrind suppression file (except on Windows,
1925 # as Valgrind is currently not supported on Windows)
1926 install_data('glib.supp',
1927 install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
1930 configure_file(output : 'config.h', configuration : glib_conf)
1932 if host_system == 'windows'
1933 install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
1936 if get_option('man')
1937 xsltproc = find_program('xsltproc', required : true)
1938 xsltproc_command = [
1941 '--stringparam', 'man.output.quietly', '1',
1942 '--stringparam', 'funcsynopsis.style', 'ansi',
1943 '--stringparam', 'man.th.extra1.suppress', '1',
1944 '--stringparam', 'man.authors.section.enabled', '0',
1945 '--stringparam', 'man.copyright.section.enabled', '0',
1947 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
1950 man1_dir = get_option('mandir') + '/man1'
1953 gnome = import('gnome')
1954 subdir('docs/reference/glib')
1955 subdir('docs/reference/gobject')
1956 subdir('docs/reference/gio')