1 project('glib', 'c', 'cpp',
3 meson_version : '>= 0.44.0',
10 cc = meson.get_compiler('c')
11 cxx = meson.get_compiler('cpp')
13 if cc.get_id() == 'msvc'
14 # Ignore several spurious warnings for things glib does very commonly
15 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
16 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
17 # NOTE: Only add warnings here if you are sure they're spurious
18 add_project_arguments('/wd4035', '/wd4715', '/wd4116',
19 '/wd4046', '/wd4068', '/wo4090', '/FImsvc_recommended_pragmas.h',language : 'c')
20 # Disable SAFESEH with MSVC for plugins and libs that use external deps that
21 # are built with MinGW
22 noseh_link_args = ['/SAFESEH:NO']
25 # -mms-bitfields vs -fnative-struct ?
28 host_system = host_machine.system()
30 glib_version = meson.project_version()
31 glib_api_version = '2.0'
32 version_arr = glib_version.split('.')
33 major_version = version_arr[0].to_int()
34 minor_version = version_arr[1].to_int()
35 micro_version = version_arr[2].to_int()
37 interface_age = minor_version.is_odd() ? 0 : micro_version
38 binary_age = 100 * minor_version + micro_version
41 # Maintain compatibility with previous libtool versioning
42 # current = minor * 100 + micro
43 library_version = '@0@.@1@.@2@'.format(soversion, binary_age - interface_age, interface_age)
45 configinc = include_directories('.')
46 glibinc = include_directories('glib')
47 gobjectinc = include_directories('gobject')
48 gmoduleinc = include_directories('gmodule')
49 gioinc = include_directories('gio')
51 glib_prefix = get_option('prefix')
52 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
53 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
54 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
55 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
56 glib_includedir = join_paths(glib_prefix, get_option('includedir'))
57 glib_giomodulesdir = get_option('gio_module_dir')
58 if glib_giomodulesdir == ''
59 glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
62 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
64 add_project_arguments('-D_GNU_SOURCE', language: 'c')
66 # Disable strict aliasing;
67 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
68 if cc.has_argument('-fno-strict-aliasing')
69 add_project_arguments('-fno-strict-aliasing', language: 'c')
72 ########################
73 # Configuration begins #
74 ########################
75 glib_conf = configuration_data()
76 glibconfig_conf = configuration_data()
78 # accumulated list of defines as we check for them, so we can easily
79 # use them later in test programs (autoconf does this automatically)
82 glib_conf.set('GLIB_VERSION', glib_version)
83 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
84 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
85 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
86 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
87 glib_conf.set('GLIB_BINARY_AGE', binary_age)
88 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
89 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'http://bugzilla.gnome.org/enter_bug.cgi?product=glib')
90 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
91 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
92 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
93 glib_conf.set_quoted('PACKAGE_URL', '')
94 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
95 glib_conf.set('ENABLE_NLS', 1)
97 # Variables used in glib-gettextize and pkg-config files
98 # These should not contain " quotes around the values
99 glib_conf.set('PACKAGE', 'glib')
100 glib_conf.set('VERSION', meson.project_version())
101 glib_conf.set('prefix', glib_prefix)
102 glib_conf.set('exec_prefix', glib_prefix)
103 glib_conf.set('libdir', glib_libdir)
104 glib_conf.set('includedir', glib_includedir)
105 glib_conf.set('datadir', glib_datadir)
106 glib_conf.set('datarootdir', glib_datadir)
108 glib_conf.set('_GNU_SOURCE', 1)
110 if host_system == 'windows'
111 # Poll doesn't work on devices on Windows
112 glib_conf.set('BROKEN_POLL', true)
115 # Detect and set symbol visibility
116 glib_hidden_visibility_args = []
117 if get_option('default_library') != 'static'
118 if host_system == 'windows'
119 glib_conf.set('DLL_EXPORT', true)
120 if cc.get_id() == 'msvc'
121 glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
122 elif cc.has_argument('-fvisibility=hidden')
123 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
124 glib_hidden_visibility_args = ['-fvisibility=hidden']
126 elif cc.has_argument('-fvisibility=hidden')
127 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
128 glib_hidden_visibility_args = ['-fvisibility=hidden']
132 if host_system == 'windows' and get_option('default_library') == 'static'
133 glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
134 glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
137 # FIXME: what about Cygwin (G_WITH_CYGWIN)
138 if host_system == 'windows'
139 glib_os = '''#define G_OS_WIN32
140 #define G_PLATFORM_WIN32'''
142 glib_os = '#define G_OS_UNIX'
144 glibconfig_conf.set('glib_os', glib_os)
146 # We need to know the build type to determine what .lib files we need on Visual Studio
147 # for dependencies that don't normally come with pkg-config files for Visual Studio builds
148 buildtype = get_option('buildtype')
150 # check for header files
186 'dirent.h', # MSC does not come with this by default
187 'sys/time.h', # MSC does not come with this by default
205 define = 'HAVE_' + h.underscorify().to_upper()
206 glib_conf.set(define, 1)
207 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
211 if cc.has_header('linux/netlink.h')
212 glib_conf.set('HAVE_NETLINK', 1)
215 if glib_conf.has('HAVE_LOCALE_H')
216 if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
217 glib_conf.set('HAVE_LC_MESSAGES', 1)
221 struct_stat_blkprefix = '''
222 #include <sys/types.h>
223 #include <sys/stat.h>
227 #ifdef HAVE_SYS_STATFS_H
228 #include <sys/statfs.h>
230 #ifdef HAVE_SYS_PARAM_H
231 #include <sys/param.h>
233 #ifdef HAVE_SYS_MOUNT_H
234 #include <sys/mount.h>
239 [ 'stat', 'st_mtimensec' ],
240 [ 'stat', 'st_mtim.tv_nsec' ],
241 [ 'stat', 'st_atimensec' ],
242 [ 'stat', 'st_atim.tv_nsec' ],
243 [ 'stat', 'st_ctimensec' ],
244 [ 'stat', 'st_ctim.tv_nsec' ],
245 [ 'stat', 'st_birthtime' ],
246 [ 'stat', 'st_birthtimensec' ],
247 [ 'stat', 'st_birthtim' ],
248 [ 'stat', 'st_birthtim.tv_nsec' ],
249 [ 'stat', 'st_blksize', struct_stat_blkprefix ],
250 [ 'stat', 'st_blocks', struct_stat_blkprefix ],
251 [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
252 [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
253 [ 'dirent', 'd_type', '''#include <sys/types.h>
254 #include <dirent.h>''' ],
257 foreach m : struct_members
258 header_check_prefix = glib_conf_prefix
260 header_check_prefix = header_check_prefix + m[2]
262 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
264 if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
265 define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
266 glib_conf.set(define, 1)
267 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
273 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
276 '-Wduplicated-branches',
277 '-Wstrict-prototypes',
278 '-Werror=declaration-after-statement',
280 '-Werror=format-security',
281 '-Werror=implicit-function-declaration',
283 '-Werror=missing-include-dirs',
284 '-Werror=missing-prototypes',
285 '-Werror=pointer-arith',
291 add_project_arguments(cc.get_supported_arguments(test_c_args), language: 'c')
293 # Windows Support (Vista+)
294 if host_system == 'windows'
295 glib_conf.set('_WIN32_WINNT', '0x0601')
359 if glib_conf.has('HAVE_SYS_STATVFS_H')
360 functions += ['statvfs']
362 have_func_statvfs = false
364 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
365 functions += ['statfs']
367 have_func_statfs = false
370 if host_system == 'windows'
371 iphlpapi_dep = cc.find_library('iphlpapi')
372 iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
373 foreach ifunc : iphlpapi_funcs
374 if cc.has_function(ifunc,
375 prefix : '#define _WIN32_WINNT 0x0601\n#include <winsock2.h>\n#include <iphlpapi.h>',
376 dependencies : iphlpapi_dep)
377 idefine = 'HAVE_' + ifunc.underscorify().to_upper()
378 glib_conf.set(idefine, 1)
379 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
380 set_variable('have_func_' + ifunc, true)
382 set_variable('have_func_' + ifunc, false)
386 functions += ['if_indextoname', 'if_nametoindex']
389 # AIX splice is something else
390 if host_system != 'aix'
391 functions += ['splice']
394 foreach f : functions
395 if cc.has_function(f)
396 define = 'HAVE_' + f.underscorify().to_upper()
397 glib_conf.set(define, 1)
398 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
399 set_variable('have_func_' + f, true)
401 set_variable('have_func_' + f, false)
405 # Check whether strerror_r returns char *
406 if have_func_strerror_r
407 if cc.compiles('''#define _GNU_SOURCE
410 char error_string[256];
411 char *ptr = strerror_r (-2, error_string, 256);
412 char c = *strerror_r (-2, error_string, 256);
413 return c != 0 && ptr != (void*) 0L;
416 name : 'strerror_r() returns char *')
417 glib_conf.set('STRERROR_R_CHAR_P', 1,
418 description: 'Defined if strerror_r returns char *')
422 # Special-case these functions that have alternative names on Windows/MSVC
423 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
424 glib_conf.set('HAVE_SNPRINTF', 1)
425 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
426 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
427 hack_define = '1\n#define snprintf _snprintf'
428 glib_conf.set('HAVE_SNPRINTF', hack_define)
429 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
432 if cc.has_function('strcasecmp')
433 glib_conf.set('HAVE_STRCASECMP', 1)
434 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
435 elif cc.has_function('_stricmp')
436 hack_define = '1\n#define strcasecmp _stricmp'
437 glib_conf.set('HAVE_STRCASECMP', hack_define)
438 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
441 if cc.has_function('strncasecmp')
442 glib_conf.set('HAVE_STRNCASECMP', 1)
443 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
444 elif cc.has_function('_strnicmp')
445 hack_define = '1\n#define strncasecmp _strnicmp'
446 glib_conf.set('HAVE_STRNCASECMP', hack_define)
447 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
450 if cc.has_header_symbol('sys/sysmacros.h', 'major')
451 glib_conf.set('MAJOR_IN_SYSMACROS', 1)
452 elif cc.has_header_symbol('sys/mkdev.h', 'major')
453 glib_conf.set('MAJOR_IN_MKDEV', 1)
456 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
457 glib_conf.set('HAVE_RTLD_LAZY', 1)
460 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
461 glib_conf.set('HAVE_RTLD_NOW', 1)
464 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
465 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
468 # Check whether to use statfs or statvfs
469 # Some systems have both statfs and statvfs, pick the most "native" for these
470 if have_func_statfs and have_func_statvfs
471 # on solaris and irix, statfs doesn't even have the f_bavail field
472 if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
473 have_func_statfs = false
475 # at least on linux, statfs is the actual syscall
476 have_func_statvfs = false
480 glib_conf.set('USE_STATFS', 1)
481 stat_func_to_use = 'statfs'
482 elif have_func_statvfs
483 glib_conf.set('USE_STATVFS', 1)
484 stat_func_to_use = 'statvfs'
486 stat_func_to_use = 'neither'
488 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
490 if host_system == 'linux'
491 if cc.has_function('mkostemp',
492 prefix: '''#define _GNU_SOURCE
493 #include <stdlib.h>''')
494 glib_conf.set('HAVE_MKOSTEMP', 1)
500 # Mac OS X Carbon support
501 glib_have_carbon = cc.compiles('''#include <Carbon/Carbon.h>
502 #include <CoreServices/CoreServices.h>''',
503 name : 'Mac OS X Carbon support')
505 glib_have_os_x_9_or_later = false
508 glib_conf.set('HAVE_CARBON', true)
509 CARBON_LIBS='-Wl,-framework,Carbon' # FIXME: propagate to .pc files as well
510 platform_ldflags += [CARBON_LIBS]
511 glib_have_os_x_9_or_later = cc.compiles('''#include <AvailabilityMacros.h>
512 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
513 #error Compiling for minimum OS X version before 10.9
514 #endif''', name : 'OS X 9 or later')
519 # Mac OS X Cocoa support
520 glib_have_cocoa = cc.compiles('''#include <Cocoa/Cocoa.h>
521 #ifdef GNUSTEP_BASE_VERSION
522 #error "Detected GNUstep, not Cocoa"
524 name : 'Mac OS X Cocoa support')
527 glib_conf.set('HAVE_COCOA', true)
528 COCOA_LIBS='-Wl,-framework,Foundation -Wl,-framework,AppKit' # FIXME: propagate to .pc files as well
529 platform_ldflags += [COCOA_LIBS]
535 if cc.links('''#include <linux/futex.h>
536 #include <sys/syscall.h>
538 int main (int argc, char ** argv) {
539 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
541 }''', name : 'futex(2) system call')
542 glib_conf.set('HAVE_FUTEX', 1)
545 # Check for eventfd(2)
546 if cc.links('''#include <sys/eventfd.h>
548 int main (int argc, char ** argv) {
549 eventfd (0, EFD_CLOEXEC);
551 }''', name : 'eventfd(2) system call')
552 glib_conf.set('HAVE_EVENTFD', 1)
555 clock_gettime_test_code = '''
558 int main (int argc, char ** argv) {
559 return clock_gettime(CLOCK_REALTIME, &t);
562 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
563 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
564 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
565 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
566 librt = cc.find_library('rt')
569 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
571 if cc.compiles(glib_conf_prefix + '''
573 #ifdef HAVE_SYS_PARAM_H
574 #include <sys/param.h>
576 #ifdef HAVE_SYS_VFS_H
579 #ifdef HAVE_SYS_MOUNT_H
580 #include <sys/mount.h>
582 #ifdef HAVE_SYS_STATFS_H
583 #include <sys/statfs.h>
585 void some_func (void) {
588 }''', name : 'number of arguments to statfs() (n=2)')
589 glib_conf.set('STATFS_ARGS', 2)
590 elif cc.compiles(glib_conf_prefix + '''
592 #ifdef HAVE_SYS_PARAM_H
593 #include <sys/param.h>
595 #ifdef HAVE_SYS_VFS_H
598 #ifdef HAVE_SYS_MOUNT_H
599 #include <sys/mount.h>
601 #ifdef HAVE_SYS_STATFS_H
602 #include <sys/statfs.h>
604 void some_func (void) {
606 statfs("/", &st, sizeof (st), 0);
607 }''', name : 'number of arguments to statfs() (n=4)')
608 glib_conf.set('STATFS_ARGS', 4)
610 error('Unable to determine number of arguments to statfs()')
614 # open takes O_DIRECTORY as an option
616 if cc.compiles('''#include <fcntl.h>
617 #include <sys/types.h>
618 #include <sys/stat.h>],
619 void some_func (void) {
620 open(0, O_DIRECTORY, 0);
621 }''', name : 'open() option O_DIRECTORY')
622 glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
625 # Check whether there is a vsnprintf() function with C99 semantics installed.
626 # AC_FUNC_VSNPRINTF_C99
627 # Check whether there is a snprintf() function with C99 semantics installed.
628 # AC_FUNC_SNPRINTF_C99
630 have_good_vsnprintf = false
631 have_good_snprintf = false
633 if host_system == 'windows'
634 # Unfortunately the mingw and Visual Studio 2015+ implementations of C99-style
635 # snprintf and vsnprintf don't seem to be quite good enough, at least not in
636 # mingw-runtime-3.14. (Sorry, I don't know exactly what is the problem,
637 # but it is related to floating point formatting and decimal point vs. comma.)
638 # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
639 # rigorous enough to notice, though.
640 glib_conf.set('HAVE_C99_SNPRINTF', false)
641 glib_conf.set('HAVE_C99_VSNPRINTF', false)
643 vsnprintf_c99_test_code = '''
655 r = vsnprintf(buffer, 5, s, args);
661 /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
662 implementation. The above will return 7 but if you replace
663 the size of the buffer with 0, it borks! */
665 r = vsnprintf(buffer, 0, s, args);
681 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
682 if rres.compiled() and rres.returncode() == 0
683 glib_conf.set('HAVE_C99_VSNPRINTF', 1)
684 have_good_vsnprintf = true
687 snprintf_c99_test_code = '''
698 r = snprintf(buffer, 5, "1234567");
703 r = snprintf(buffer, 0, "1234567");
708 r = snprintf(NULL, 0, "1234567");
723 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
724 if rres.compiled() and rres.returncode() == 0
725 glib_conf.set('HAVE_C99_SNPRINTF', 1)
726 have_good_snprintf = true
730 if host_system == 'windows'
731 glib_conf.set_quoted('EXEEXT', '.exe')
733 glib_conf.set('EXEEXT', '')
736 if have_good_vsnprintf and have_good_snprintf
737 # Our printf is 'good' only if vsnpintf()/snprintf() supports C99 well enough
738 glib_conf.set('HAVE_GOOD_PRINTF', 1) # FIXME: Check for HAVE_UNIX98_PRINTF?
740 glib_conf.set('HAVE_VASPRINTF', 1)
743 # Check whether the printf() family supports Unix98 %n$ positional parameters
744 # AC_FUNC_PRINTF_UNIX98
745 # Nothing uses HAVE_UNIX98_PRINTF
748 # Check for nl_langinfo and CODESET
749 # FIXME: Check for HAVE_BIND_TEXTDOMAIN_CODESET
750 if cc.links('''#include <langinfo.h>
751 int main (int argc, char ** argv) {
752 char *codeset = nl_langinfo (CODESET);
754 }''', name : 'nl_langinfo and CODESET')
755 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
756 glib_conf.set('HAVE_CODESET', 1)
759 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
760 if cc.links('''#include <langinfo.h>
761 int main (int argc, char ** argv) {
763 str = nl_langinfo (PM_STR);
764 str = nl_langinfo (D_T_FMT);
765 str = nl_langinfo (D_FMT);
766 str = nl_langinfo (T_FMT);
767 str = nl_langinfo (T_FMT_AMPM);
768 str = nl_langinfo (MON_1);
769 str = nl_langinfo (ABMON_12);
770 str = nl_langinfo (DAY_1);
771 str = nl_langinfo (ABDAY_7);
773 }''', name : 'nl_langinfo (PM_STR)')
774 glib_conf.set('HAVE_LANGINFO_TIME', 1)
776 if cc.links('''#include <langinfo.h>
777 int main (int argc, char ** argv) {
779 str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
780 str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
781 str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
782 str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
783 str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
784 str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
785 str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
786 str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
787 str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
788 str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
790 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
791 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
794 # Check for nl_langinfo and alternative month names
795 if cc.links('''#ifndef _GNU_SOURCE
798 #include <langinfo.h>
799 int main (int argc, char ** argv) {
801 str = nl_langinfo (ALTMON_1);
802 str = nl_langinfo (ALTMON_2);
803 str = nl_langinfo (ALTMON_3);
804 str = nl_langinfo (ALTMON_4);
805 str = nl_langinfo (ALTMON_5);
806 str = nl_langinfo (ALTMON_6);
807 str = nl_langinfo (ALTMON_7);
808 str = nl_langinfo (ALTMON_8);
809 str = nl_langinfo (ALTMON_9);
810 str = nl_langinfo (ALTMON_10);
811 str = nl_langinfo (ALTMON_11);
812 str = nl_langinfo (ALTMON_12);
814 }''', name : 'nl_langinfo (ALTMON_n)')
815 glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
818 # Check for nl_langinfo and abbreviated alternative month names
819 if cc.links('''#ifndef _GNU_SOURCE
822 #include <langinfo.h>
823 int main (int argc, char ** argv) {
825 str = nl_langinfo (_NL_ALTMON_1);
826 str = nl_langinfo (_NL_ALTMON_2);
827 str = nl_langinfo (_NL_ALTMON_3);
828 str = nl_langinfo (_NL_ALTMON_4);
829 str = nl_langinfo (_NL_ALTMON_5);
830 str = nl_langinfo (_NL_ALTMON_6);
831 str = nl_langinfo (_NL_ALTMON_7);
832 str = nl_langinfo (_NL_ALTMON_8);
833 str = nl_langinfo (_NL_ALTMON_9);
834 str = nl_langinfo (_NL_ALTMON_10);
835 str = nl_langinfo (_NL_ALTMON_11);
836 str = nl_langinfo (_NL_ALTMON_12);
838 }''', name : 'nl_langinfo (_NL_ALTMON_n)')
839 glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
842 # Check if C compiler supports the 'signed' keyword
843 if not cc.compiles('''signed char x;''', name : 'signed')
844 glib_conf.set('signed', '/* NOOP */')
847 # Check if the ptrdiff_t type exists
848 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
849 glib_conf.set('HAVE_PTRDIFF_T', 1)
852 # Check for sig_atomic_t type
853 if cc.links('''#include <signal.h>
854 #include <sys/types.h>
855 sig_atomic_t val = 42;
856 int main (int argc, char ** argv) {
857 return val == 42 ? 0 : 1;
858 }''', name : 'sig_atomic_t')
859 glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
862 # Check if 'long long' works and what format can be used to print it
863 # jm_AC_TYPE_LONG_LONG
864 # Nothing uses HAVE_LONG_LONG_FORMAT and HAVE_INT64_AND_I64
865 if cc.compiles('''long long ll = 1LL;
867 int some_func (void) {
868 long long llmax = (long long) -1;
869 return ll << i | ll >> i | llmax / ll | llmax % ll;
870 }''', name : 'long long')
871 glib_conf.set('HAVE_LONG_LONG', 1)
872 have_long_long = true
874 have_long_long = false
877 # Test whether the compiler supports the 'long double' type.
878 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
879 long double foo = 0.0;
880 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
881 int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
882 name : 'long double')
883 glib_conf.set('HAVE_LONG_DOUBLE', 1)
886 #dnl Test whether <stddef.h> has the 'wchar_t' type.
887 if cc.has_header_symbol('stddef.h', 'wchar_t')
888 glib_conf.set('HAVE_WCHAR_T', 1)
891 # Test whether <wchar.h> has the 'wint_t' type.
892 if cc.has_header_symbol('wchar.h', 'wint_t')
893 glib_conf.set('HAVE_WINT_T', 1)
896 found_uintmax_t = false
898 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
899 # doesn't clash with <sys/types.h>, and declares uintmax_t.
900 # jm_AC_HEADER_INTTYPES_H
901 if cc.compiles('''#include <sys/types.h>
902 #include <inttypes.h>
903 void some_func (void) {
904 uintmax_t i = (uintmax_t) -1;
905 }''', name : 'uintmax_t in inttypes.h')
906 glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
907 found_uintmax_t = true
910 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
911 # doesn't clash with <sys/types.h>, and declares uintmax_t.
912 # jm_AC_HEADER_STDINT_H
913 if cc.compiles('''#include <sys/types.h>
915 void some_func (void) {
916 uintmax_t i = (uintmax_t) -1;
917 }''', name : 'uintmax_t in stdint.h')
918 glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
919 found_uintmax_t = true
922 # Define intmax_t to 'long' or 'long long'
923 # if it is not already defined in <stdint.h> or <inttypes.h>.
924 # For simplicity, we assume that a header file defines 'intmax_t' if and
925 # only if it defines 'uintmax_t'.
927 glib_conf.set('HAVE_INTMAX_T', 1)
929 glib_conf.set('intmax_t', 'long long')
931 glib_conf.set('intmax_t', 'long')
934 char_size = cc.sizeof('char')
935 short_size = cc.sizeof('short')
936 int_size = cc.sizeof('int')
937 voidp_size = cc.sizeof('void*')
938 long_size = cc.sizeof('long')
940 long_long_size = cc.sizeof('long long')
944 sizet_size = cc.sizeof('size_t')
945 if cc.get_id() == 'msvc'
946 ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
948 ssizet_size = cc.sizeof('ssize_t')
951 # On Windows, MSVC supports both ll and I64 as format specifiers for 64-bit
952 # integers, but some versions (at least 4.7.x) of MinGW only support I64.
953 if host_system == 'windows'
959 char_align = cc.alignment('char')
960 short_align = cc.alignment('short')
961 int_align = cc.alignment('int')
962 voidp_align = cc.alignment('void*')
963 long_align = cc.alignment('long')
964 long_long_align = cc.alignment('long long')
965 # NOTE: We don't check for size of __int64 because long long is guaranteed to
966 # be 64-bit in C99, and it is available on all supported compilers
967 sizet_align = cc.alignment('size_t')
969 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
971 glib_conf.set('SIZEOF_CHAR', char_size)
972 glib_conf.set('SIZEOF_INT', int_size)
973 glib_conf.set('SIZEOF_SHORT', short_size)
974 glib_conf.set('SIZEOF_LONG', long_size)
975 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
976 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
977 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
978 glib_conf.set('SIZEOF_VOID_P', voidp_size)
991 error('Compiler provides no native 16-bit integer type')
993 glibconfig_conf.set('gint16', gint16)
994 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
995 glibconfig_conf.set_quoted('gint16_format', gint16_format)
996 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1003 guint32_align = short_align
1009 guint32_align = int_align
1015 guint32_align = long_align
1017 error('Compiler provides no native 32-bit integer type')
1019 glibconfig_conf.set('gint32', gint32)
1020 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1021 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1022 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1023 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1031 gint64_constant='(val)'
1032 guint64_constant='(val)'
1033 guint64_align = int_align
1040 gint64_constant='(val##L)'
1041 guint64_constant='(val##UL)'
1042 guint64_align = long_align
1043 elif long_long_size == 8
1044 gint64 = 'long long'
1045 glib_extension='G_GNUC_EXTENSION '
1046 gint64_modifier=int64_m
1047 gint64_format=int64_m + 'i'
1048 guint64_format=int64_m + 'u'
1049 gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1050 guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1051 guint64_align = long_long_align
1053 error('Compiler provides no native 64-bit integer type')
1055 glibconfig_conf.set('glib_extension', glib_extension)
1056 glibconfig_conf.set('gint64', gint64)
1057 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1058 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1059 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1060 glibconfig_conf.set('gint64_constant', gint64_constant)
1061 glibconfig_conf.set('guint64_constant', guint64_constant)
1062 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1064 if host_system == 'windows'
1065 glibconfig_conf.set('g_pid_type', 'void*')
1066 glibconfig_conf.set_quoted('g_pid_format', 'p')
1067 if host_machine.cpu_family() == 'x86_64'
1068 glibconfig_conf.set_quoted('g_pollfd_format', '%#I64x')
1070 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1072 glibconfig_conf.set('g_dir_separator', '\\\\')
1073 glibconfig_conf.set('g_searchpath_separator', ';')
1075 glibconfig_conf.set('g_pid_type', 'int')
1076 glibconfig_conf.set_quoted('g_pid_format', 'i')
1077 glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1078 glibconfig_conf.set('g_dir_separator', '/')
1079 glibconfig_conf.set('g_searchpath_separator', ':')
1082 if sizet_size == short_size
1083 glibconfig_conf.set('glib_size_type_define', 'short')
1084 glibconfig_conf.set_quoted('gsize_modifier', 'h')
1085 glibconfig_conf.set_quoted('gssize_modifier', 'h')
1086 glibconfig_conf.set_quoted('gsize_format', 'hu')
1087 glibconfig_conf.set_quoted('gssize_format', 'hi')
1088 glibconfig_conf.set('glib_msize_type', 'SHRT')
1089 elif sizet_size == int_size
1090 glibconfig_conf.set('glib_size_type_define', 'int')
1091 glibconfig_conf.set_quoted('gsize_modifier', '')
1092 glibconfig_conf.set_quoted('gssize_modifier', '')
1093 glibconfig_conf.set_quoted('gsize_format', 'u')
1094 glibconfig_conf.set_quoted('gssize_format', 'i')
1095 glibconfig_conf.set('glib_msize_type', 'INT')
1096 elif sizet_size == long_size
1097 glibconfig_conf.set('glib_size_type_define', 'long')
1098 glibconfig_conf.set_quoted('gsize_modifier', 'l')
1099 glibconfig_conf.set_quoted('gssize_modifier', 'l')
1100 glibconfig_conf.set_quoted('gsize_format', 'lu')
1101 glibconfig_conf.set_quoted('gssize_format', 'li')
1102 glibconfig_conf.set('glib_msize_type', 'LONG')
1103 elif sizet_size == long_long_size
1104 glibconfig_conf.set('glib_size_type_define', 'long long')
1105 glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1106 glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1107 glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1108 glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1109 glibconfig_conf.set('glib_msize_type', 'INT64')
1111 error('Could not determine size of size_t.')
1114 if voidp_size == int_size
1115 glibconfig_conf.set('glib_intptr_type_define', 'int')
1116 glibconfig_conf.set_quoted('gintptr_modifier', '')
1117 glibconfig_conf.set_quoted('gintptr_format', 'i')
1118 glibconfig_conf.set_quoted('guintptr_format', 'u')
1119 glibconfig_conf.set('glib_gpi_cast', '(gint)')
1120 glibconfig_conf.set('glib_gpui_cast', '(guint)')
1121 elif voidp_size == long_size
1122 glibconfig_conf.set('glib_intptr_type_define', 'long')
1123 glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1124 glibconfig_conf.set_quoted('gintptr_format', 'li')
1125 glibconfig_conf.set_quoted('guintptr_format', 'lu')
1126 glibconfig_conf.set('glib_gpi_cast', '(glong)')
1127 glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1128 elif voidp_size == long_long_size
1129 glibconfig_conf.set('glib_intptr_type_define', 'long long')
1130 glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1131 glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1132 glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1133 glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1134 glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1136 error('Could not determine size of void *')
1139 if long_size != 8 and long_long_size != 8 and int_size != 8
1140 error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1143 glibconfig_conf.set('gintbits', int_size * 8)
1144 glibconfig_conf.set('glongbits', long_size * 8)
1145 glibconfig_conf.set('gsizebits', sizet_size * 8)
1146 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1148 # FIXME: maybe meson should tell us the libsuffix?
1149 if host_system == 'windows'
1150 g_module_suffix = 'dll'
1151 elif host_system == 'darwin'
1152 g_module_suffix = 'dylib'
1154 g_module_suffix = 'so'
1156 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1158 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1159 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1160 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1161 glibconfig_conf.set('GLIB_VERSION', glib_version)
1163 glibconfig_conf.set('glib_void_p', voidp_size)
1164 glibconfig_conf.set('glib_long', long_size)
1165 glibconfig_conf.set('glib_size_t', sizet_size)
1166 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1167 if host_machine.endian() == 'big'
1168 glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1169 glibconfig_conf.set('g_bs_native', 'BE')
1170 glibconfig_conf.set('g_bs_alien', 'LE')
1172 glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1173 glibconfig_conf.set('g_bs_native', 'LE')
1174 glibconfig_conf.set('g_bs_alien', 'BE')
1177 # === va_copy checks ===
1178 # we currently check for all three va_copy possibilities, so we get
1179 # all results in config.log for bug reports.
1182 foreach try_func : [ '__va_copy', 'va_copy' ]
1183 if cc.compiles('''#include <stdarg.h>
1186 # include "msvc_recommended_pragmas.h"
1188 void f (int i, ...) {
1189 va_list args1, args2;
1190 va_start (args1, i);
1192 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1194 va_end (args1); va_end (args2);
1199 }'''.format(try_func),
1200 name : try_func + ' check')
1201 va_copy_func = try_func
1204 if va_copy_func != ''
1205 glib_conf.set('G_VA_COPY', va_copy_func)
1206 glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1208 glib_vacopy = '/* #undef G_VA_COPY */'
1211 va_list_val_copy_prog = '''
1214 void f (int i, ...) {
1215 va_list args1, args2;
1216 va_start (args1, i);
1218 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1220 va_end (args1); va_end (args2);
1227 # We do this in two steps so if compilation fails already it looks less alarming
1228 glib_va_val_copy = false
1229 if cc.compiles(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1230 # FIXME: what to do when cross-compiling?
1231 if cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values').returncode() == 0
1232 glib_va_val_copy = true
1235 if not glib_va_val_copy
1236 glib_va_val_copy = false
1237 glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1238 glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1240 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1242 # check for flavours of varargs macros
1243 g_have_iso_c_varargs = cc.compiles('''
1244 void some_func (void) {
1245 int a(int p1, int p2, int p3);
1246 #define call_a(...) a(1,__VA_ARGS__)
1248 }''', name : 'ISO C99 varargs macros in C')
1250 if g_have_iso_c_varargs
1251 glibconfig_conf.set('g_have_iso_c_varargs', '''
1253 # define G_HAVE_ISO_VARARGS 1
1257 g_have_iso_cxx_varargs = cxx.compiles('''
1258 void some_func (void) {
1259 int a(int p1, int p2, int p3);
1260 #define call_a(...) a(1,__VA_ARGS__)
1262 }''', name : 'ISO C99 varargs macros in C++')
1264 if g_have_iso_cxx_varargs
1265 glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1267 # define G_HAVE_ISO_VARARGS 1
1271 g_have_gnuc_varargs = cc.compiles('''
1272 void some_func (void) {
1273 int a(int p1, int p2, int p3);
1274 #define call_a(params...) a(1,params)
1276 }''', name : 'GNUC varargs macros')
1278 if cc.has_header('alloca.h')
1279 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1281 has_syspoll = cc.has_header('sys/poll.h')
1282 has_systypes = cc.has_header('sys/types.h')
1284 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1286 has_winsock2 = cc.has_header('winsock2.h')
1288 if has_syspoll and has_systypes
1289 templ = '''#include<sys/poll.h>
1290 #include<sys/types.h>
1292 int main(int argc, char **argv) {
1293 printf("%d\n", (int)@0@);
1297 templ = '''#define _WIN32_WINNT 0x0600
1299 #include <winsock2.h>
1300 int main(int argc, char **argv) {
1301 printf("%d\n", (int)@0@);
1306 error('FIX POLL* defines')
1309 value_POLLIN = cc.run(templ.format('POLLIN'), name : 'POLLIN value').stdout().strip()
1310 value_POLLOUT = cc.run(templ.format('POLLOUT'), name : 'POLLOUT value').stdout().strip()
1311 value_POLLPRI = cc.run(templ.format('POLLPRI'), name : 'POLLPRI value').stdout().strip()
1312 value_POLLERR = cc.run(templ.format('POLLERR'), name : 'POLLERR value').stdout().strip()
1313 value_POLLHUP = cc.run(templ.format('POLLHUP'), name : 'POLLHUP value').stdout().strip()
1314 value_POLLNVAL = cc.run(templ.format('POLLNVAL'), name : 'POLLNVAL value').stdout().strip()
1316 glibconfig_conf.set('g_pollin', value_POLLIN)
1317 glibconfig_conf.set('g_pollout', value_POLLOUT)
1318 glibconfig_conf.set('g_pollpri', value_POLLPRI)
1319 glibconfig_conf.set('g_pollerr', value_POLLERR)
1320 glibconfig_conf.set('g_pollhup', value_POLLHUP)
1321 glibconfig_conf.set('g_pollnval', value_POLLNVAL)
1323 # Internet address families
1324 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1325 if host_system == 'windows'
1326 glib_inet_includes= '''
1327 #include <winsock2.h>
1330 glib_inet_includes='''
1331 #include <sys/types.h>
1332 #include <sys/socket.h>
1337 [ 'AF_UNIX', 'g_af_unix' ],
1338 [ 'AF_INET', 'g_af_inet' ],
1339 [ 'AF_INET6', 'g_af_inet6' ],
1340 [ 'MSG_OOB', 'g_msg_oob' ],
1341 [ 'MSG_PEEK', 'g_msg_peek' ],
1342 [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1344 foreach d : net_defines
1347 int main(int argc, char **argv) {
1348 printf("%d\n", (int)@1@);
1351 # FIXME: fix for cross-compilation
1352 if not meson.has_exe_wrapper()
1353 error('Fix sys define detection for cross build')
1355 val = cc.run(templ.format(glib_inet_includes, d[0]), name : d[0] + ' value').stdout().strip()
1356 glibconfig_conf.set(d[1], val)
1359 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', true) # FIXME!
1361 # We need a more robust approach here...
1362 host_cpu_family = host_machine.cpu_family()
1363 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')
1364 glib_memory_barrier_needed = false
1365 elif host_cpu_family.startswith('sparc') or host_cpu_family.startswith('alpha') or host_cpu_family.startswith('powerpc') or host_cpu_family == 'ia64'
1366 glib_memory_barrier_needed = true
1368 warning('Unknown host cpu: ' + host_cpu_family)
1369 glib_memory_barrier_needed = true
1371 glibconfig_conf.set('G_ATOMIC_OP_MEMORY_BARRIER_NEEDED', glib_memory_barrier_needed)
1373 # Note that the atomic ops are only available with GCC on x86 when
1374 # using -march=i486 or higher. If we detect that the atomic ops are
1375 # not available but would be available given the right flags, we want
1376 # to abort and advise the user to fix their CFLAGS. It's better to do
1377 # that then to silently fall back on emulated atomic ops just because
1378 # the user had the wrong build environment.
1379 atomictest = '''void func() {
1380 volatile int atomic = 2;
1381 __sync_bool_compare_and_swap (&atomic, 2, 3);
1384 if cc.compiles(atomictest)
1385 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', true)
1387 if host_machine.cpu_family() == 'x86' and cc.compiles(atomictest, args : '-march=i486')
1388 error('GLib must be built with -march=i486 or later.')
1390 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', false)
1395 # Let meson figure out all this business and whether -pthread or whatnot is needed
1396 # FIXME: probably needs more tweaking in meson for things like -D_REENTRANT etc.
1397 thread_dep = dependency('threads')
1399 # Determination of thread implementation
1400 if host_system == 'windows'
1401 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1402 glib_conf.set('THREADS_WIN32', 1)
1404 pthread_prefix = '''
1406 # define _GNU_SOURCE
1408 #include <pthread.h>'''
1409 glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1410 glib_conf.set('THREADS_POSIX', 1)
1411 if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1412 glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1414 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1415 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1417 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1418 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1420 if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1421 glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1423 # Assume that pthread_setname_np is available in some form; same as configure
1424 if cc.links(pthread_prefix + '''
1426 pthread_setname_np("example");
1428 name : 'pthread_setname_np(const char*)',
1429 dependencies : thread_dep)
1431 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1432 elif cc.links(pthread_prefix + '''
1434 pthread_setname_np(pthread_self(), "example");
1436 name : 'pthread_setname_np(pthread_t, const char*)',
1437 dependencies : thread_dep)
1438 # Linux, Solaris, etc.
1439 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1443 # FIXME: how to do this when cross-compiling?
1444 # FIXME: we should make it print the result and always return 0, so that
1445 # the output in meson shows up as green
1446 stack_grows_check_prog = '''
1447 volatile int *a = 0, *b = 0;
1459 return b > a ? 0 : 1;
1461 stack_grows_run_result = cc.run(stack_grows_check_prog, name : 'stack grows check')
1462 if stack_grows_run_result.compiled() and stack_grows_run_result.returncode() == 0
1463 glibconfig_conf.set('G_HAVE_GROWING_STACK', 1)
1465 glibconfig_conf.set('G_HAVE_GROWING_STACK', 0)
1470 # USE_LIBICONV_GNU: Using GNU libiconv
1471 # USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library
1473 # We should never use the MinGW C library's iconv. On Windows we use the
1474 # GNU implementation that ships with MinGW.
1476 # On Windows, just always use the built-in implementation
1477 if host_system == 'windows'
1479 glib_conf.set('USE_LIBICONV_NATIVE', true)
1482 iconv_opt = get_option('iconv')
1483 if iconv_opt == 'libc'
1484 if cc.has_function('iconv_open')
1488 elif iconv_opt == 'gnu'
1489 if cc.has_header_symbol('iconv.h', 'libiconv_open')
1490 glib_conf.set('USE_LIBICONV_GNU', true)
1491 libiconv = [cc.find_library('iconv')]
1494 elif iconv_opt == 'native'
1495 if cc.has_header_symbol('iconv.h', 'iconv_open')
1496 glib_conf.set('USE_LIBICONV_NATIVE', true)
1497 libiconv = [cc.find_library('iconv')]
1503 error('No iconv() implementation found in C library or libiconv')
1508 if get_option('internal_pcre')
1510 use_system_pcre = false
1512 pcre = dependency('libpcre', required : false) # Should check for Unicode support, too. FIXME
1514 if cc.get_id() == 'msvc'
1515 # MSVC: Search for the PCRE library by the configuration, which corresponds
1516 # to the output of CMake builds of PCRE. Note that debugoptimized
1517 # is really a Release build with .PDB files.
1518 if buildtype == 'debug'
1519 pcre = cc.find_library('pcred', required : false)
1521 pcre = cc.find_library('pcre', required : false)
1525 use_system_pcre = pcre.found()
1527 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1529 use_pcre_static_flag = false
1531 if host_system == 'windows'
1532 if not use_system_pcre
1533 use_pcre_static_flag = true
1535 pcre_static = cc.links('''#define PCRE_STATIC
1543 name : 'Windows system PCRE is a static build')
1545 use_pcre_static_flag = true
1550 libm = cc.find_library('m', required : false)
1551 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
1552 zlib_libname = '-lz'
1553 if cc.get_id() != 'msvc'
1554 libz_dep = dependency('zlib', fallback : ['zlib', 'zlib_dep'])
1556 # MSVC: Don't use the bundled ZLib sources until we are sure that we can't
1557 # find the ZLib .lib
1558 libz_dep = dependency('zlib', required : false)
1560 # MSVC: Search for the ZLib .lib, which corresponds to the results of
1561 # of using ZLib's win32/makefile.msc.
1562 if not libz_dep.found()
1563 libz_dep = cc.find_library('zlib1', required : false)
1565 zlib_libname = '-lzlib1'
1567 libz_dep = cc.find_library('zlib', required : false)
1569 zlib_libname = '-lzlib'
1571 libz_dep = subproject('zlib').get_variable('zlib_dep')
1577 # Only used on non-glibc targets
1578 libintl = cc.find_library('intl', required : false)
1579 if host_system == 'windows' and not libintl.found()
1580 # Used only when the gettext library is not available (MSVC, not MinGW)
1581 libintl = subproject('proxy-libintl').get_variable('intl_dep')
1582 glib_conf.set('HAVE_DCGETTEXT', 1)
1584 glib_conf.set('HAVE_DCGETTEXT', cc.has_header_symbol('libintl.h', 'dcgettext'))
1586 # We require gettext to always be present
1587 glib_conf.set('HAVE_GETTEXT', 1)
1588 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
1589 # xgettext is optional (on Windows for instance)
1590 xgettext = find_program('xgettext', required : false)
1592 # libmount is only used by gio, but we need to fetch the libs to generate the
1593 # pkg-config file below
1595 if host_system == 'linux' and get_option('libmount')
1596 libmount_dep = [dependency('mount', version : '>=2.23', required : true)]
1599 if host_system == 'windows'
1600 winsock2 = cc.find_library('ws2_32')
1604 if host_system == 'linux' and get_option('selinux')
1605 selinux_dep = [dependency('libselinux')]
1606 glib_conf.set('SELINUX_LIBS', '-lselinux')
1607 glib_conf.set('HAVE_SELINUX', 1)
1611 if host_system != 'windows' and get_option('xattr')
1612 # either glibc or libattr can provide xattr support
1613 # for both of them, we check for getxattr being in
1614 # the library and a valid xattr header.
1617 if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
1618 glib_conf.set('HAVE_SYS_XATTR_H', 1)
1619 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
1620 #failure. try libattr
1621 elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
1622 glib_conf.set('HAVE_ATTR_XATTR_H', 1)
1623 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
1624 xattr_dep = [cc.find_library('xattr')]
1626 error('No getxattr implementation found in C library or libxattr')
1629 glib_conf.set('HAVE_XATTR', 1)
1630 if cc.compiles(glib_conf_prefix + '''
1632 #ifdef HAVE_SYS_TYPES_H
1633 #include <sys/types.h>
1635 #ifdef HAVE_SYS_XATTR_H
1636 #include <sys/xattr.h>
1637 #elif HAVE_ATTR_XATTR_H
1638 #include <attr/xattr.h>
1642 ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
1644 name : 'XATTR_NOFOLLOW')
1645 glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
1649 python = import('python3').find_python()
1651 # Determine which user environment-dependent files that we want to install
1652 have_bash = find_program('bash', required : false).found() # For completion scripts
1653 have_m4 = find_program('m4', required : false).found() # For m4 macros
1654 have_sh = find_program('sh', required : false).found() # For glib-gettextize
1656 # FIXME: defines in config.h that are not actually used anywhere
1657 # (we add them for now to minimise the diff)
1658 glib_conf.set('HAVE_DLFCN_H', 1)
1659 glib_conf.set('__EXTENSIONS__', 1)
1660 glib_conf.set('STDC_HEADERS', 1)
1662 glib_conf.set('SIZEOF___INT64', 8)
1664 # Various substs needed for our pkg-config files
1665 # FIXME: Derive these from the dependency() objects (Meson support needed)
1666 glib_conf.set('ZLIB_LIBS', zlib_libname)
1667 glib_conf.set('LIBFFI_LIBS', '-lffi')
1669 glib_conf.set('INTLLIBS', '-lintl')
1671 if libiconv.length() != 0
1672 glib_conf.set('ICONV_LIBS', '-liconv')
1675 glib_conf.set('PCRE_LIBS', '-lpcre')
1677 if libmount_dep.length() != 0
1678 glib_conf.set('LIBMOUNT_LIBS', '-lmount')
1679 glib_conf.set('HAVE_LIBMOUNT', 1)
1681 glib_conf.set('GIO_MODULE_DIR', glib_giomodulesdir)
1683 # @G_MODULE_LIBS@ @COCOA_LIBS@ @CARBON_LIBS@ @G_LIBS_EXTRA@
1684 # @PCRE_REQUIRES@ @GLIB_EXTRA_CFLAGS@ @G_THREAD_CFLAGS@
1687 want_dtrace = get_option('dtrace')
1688 enable_dtrace = false
1690 # Since dtrace support is opt-in we just error out if it was requested but
1691 # is not available. We don't bother with autodetection yet.
1694 error('GLib dtrace support not yet compatible with macOS dtrace')
1696 dtrace = find_program('dtrace', required : true) # error out if not found
1697 if not cc.has_header('sys/sdt.h')
1698 error('dtrace support needs sys/sdt.h header')
1700 # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
1701 dtrace_obj_gen = generator(dtrace,
1702 output : '@BASENAME@.o',
1703 arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1704 # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
1705 # -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
1706 dtrace_hdr_gen = generator(dtrace,
1707 output : '@BASENAME@.h',
1708 arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1709 glib_conf.set('HAVE_DTRACE', 1)
1710 enable_dtrace = true
1714 want_systemtap = get_option('systemtap')
1715 enable_systemtap = false
1717 if want_systemtap and enable_dtrace
1718 tapset_install_dir = get_option('tapset_install_dir')
1719 if tapset_install_dir == ''
1720 tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
1722 stp_cdata = configuration_data()
1723 stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
1724 stp_cdata.set('LT_CURRENT', minor_version * 100)
1725 stp_cdata.set('LT_REVISION', micro_version)
1726 enable_systemtap = true
1730 windows = import('windows')
1741 # Configure and install pkg-config files
1747 'gmodule-export-2.0.pc',
1748 'gmodule-no-export-2.0.pc',
1751 if host_system == 'windows'
1752 pc_files += ['gio-windows-2.0.pc']
1754 pc_files += ['gio-unix-2.0.pc']
1757 foreach pc : pc_files
1758 configure_file(input : pc + '.in',
1760 install_dir : glib_pkgconfigreldir,
1762 configuration : glib_conf)
1765 # NOTE: We skip glib-zip.in because the filenames it assumes don't match ours
1767 # Install glib-gettextize executable, if a UNIX-style shell is found
1769 configure_file(input : 'glib-gettextize.in',
1771 install_dir : 'bin',
1772 output : 'glib-gettextize',
1773 configuration : glib_conf)
1777 # Install m4 macros that other projects use
1778 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
1779 install_dir : join_paths(get_option('datadir'), 'aclocal'))
1782 if host_system != 'windows'
1783 # Install Valgrind suppression file (except on Windows,
1784 # as Valgrind is currently not supported on Windows)
1785 install_data('glib.supp',
1786 install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
1789 configure_file(input : 'config.h.meson',
1790 output : 'config.h',
1791 configuration : glib_conf)
1793 if host_system == 'windows'
1794 install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
1797 if get_option('man')
1798 xsltproc = find_program('xsltproc', required : true)
1799 xsltproc_command = [
1802 '--stringparam', 'man.output.quietly', '1',
1803 '--stringparam', 'funcsynopsis.style', 'ansi',
1804 '--stringparam', 'man.th.extra1.suppress', '1',
1805 '--stringparam', 'man.authors.section.enabled', '0',
1806 '--stringparam', 'man.copyright.section.enabled', '0',
1808 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
1811 man1_dir = get_option('mandir') + '/man1'
1814 gnome = import('gnome')
1815 subdir('docs/reference/glib')
1816 subdir('docs/reference/gobject')
1817 subdir('docs/reference/gio')