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 ########################
67 # Configuration begins #
68 ########################
69 glib_conf = configuration_data()
70 glibconfig_conf = configuration_data()
72 # accumulated list of defines as we check for them, so we can easily
73 # use them later in test programs (autoconf does this automatically)
76 glib_conf.set('GLIB_VERSION', glib_version)
77 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
78 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
79 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
80 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
81 glib_conf.set('GLIB_BINARY_AGE', binary_age)
82 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
83 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'http://bugzilla.gnome.org/enter_bug.cgi?product=glib')
84 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
85 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
86 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
87 glib_conf.set_quoted('PACKAGE_URL', '')
88 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
89 glib_conf.set('ENABLE_NLS', 1)
91 # Variables used in glib-gettextize and pkg-config files
92 # These should not contain " quotes around the values
93 glib_conf.set('PACKAGE', 'glib')
94 glib_conf.set('VERSION', meson.project_version())
95 glib_conf.set('prefix', glib_prefix)
96 glib_conf.set('exec_prefix', glib_prefix)
97 glib_conf.set('libdir', glib_libdir)
98 glib_conf.set('includedir', glib_includedir)
99 glib_conf.set('datadir', glib_datadir)
100 glib_conf.set('datarootdir', glib_datadir)
102 glib_conf.set('_GNU_SOURCE', 1)
104 if host_system == 'windows'
105 # Poll doesn't work on devices on Windows
106 glib_conf.set('BROKEN_POLL', true)
109 # Detect and set symbol visibility
110 glib_hidden_visibility_args = []
111 if get_option('default_library') != 'static'
112 if host_system == 'windows'
113 glib_conf.set('DLL_EXPORT', true)
114 if cc.get_id() == 'msvc'
115 glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
116 elif cc.has_argument('-fvisibility=hidden')
117 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
118 glib_hidden_visibility_args = ['-fvisibility=hidden']
120 elif cc.has_argument('-fvisibility=hidden')
121 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
122 glib_hidden_visibility_args = ['-fvisibility=hidden']
126 if host_system == 'windows' and get_option('default_library') == 'static'
127 glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
128 glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
131 # FIXME: what about Cygwin (G_WITH_CYGWIN)
132 if host_system == 'windows'
133 glib_os = '''#define G_OS_WIN32
134 #define G_PLATFORM_WIN32'''
136 glib_os = '#define G_OS_UNIX'
138 glibconfig_conf.set('glib_os', glib_os)
140 # We need to know the build type to determine what .lib files we need on Visual Studio
141 # for dependencies that don't normally come with pkg-config files for Visual Studio builds
142 buildtype = get_option('buildtype')
144 # check for header files
180 'dirent.h', # MSC does not come with this by default
181 'sys/time.h', # MSC does not come with this by default
199 define = 'HAVE_' + h.underscorify().to_upper()
200 glib_conf.set(define, 1)
201 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
205 if cc.has_header('linux/netlink.h')
206 glib_conf.set('HAVE_NETLINK', 1)
209 if glib_conf.has('HAVE_LOCALE_H')
210 if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
211 glib_conf.set('HAVE_LC_MESSAGES', 1)
215 struct_stat_blkprefix = '''
216 #include <sys/types.h>
217 #include <sys/stat.h>
221 #ifdef HAVE_SYS_STATFS_H
222 #include <sys/statfs.h>
224 #ifdef HAVE_SYS_PARAM_H
225 #include <sys/param.h>
227 #ifdef HAVE_SYS_MOUNT_H
228 #include <sys/mount.h>
233 [ 'stat', 'st_mtimensec' ],
234 [ 'stat', 'st_mtim.tv_nsec' ],
235 [ 'stat', 'st_atimensec' ],
236 [ 'stat', 'st_atim.tv_nsec' ],
237 [ 'stat', 'st_ctimensec' ],
238 [ 'stat', 'st_ctim.tv_nsec' ],
239 [ 'stat', 'st_birthtime' ],
240 [ 'stat', 'st_birthtimensec' ],
241 [ 'stat', 'st_birthtim' ],
242 [ 'stat', 'st_birthtim.tv_nsec' ],
243 [ 'stat', 'st_blksize', struct_stat_blkprefix ],
244 [ 'stat', 'st_blocks', struct_stat_blkprefix ],
245 [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
246 [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
247 [ 'dirent', 'd_type', '''#include <sys/types.h>
248 #include <dirent.h>''' ],
251 foreach m : struct_members
252 header_check_prefix = glib_conf_prefix
254 header_check_prefix = header_check_prefix + m[2]
256 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
258 if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
259 define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
260 glib_conf.set(define, 1)
261 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
266 # Windows Support (Vista+)
267 if host_system == 'windows'
268 glib_conf.set('_WIN32_WINNT', '0x0601')
331 if glib_conf.has('HAVE_SYS_STATVFS_H')
332 functions += ['statvfs']
334 have_func_statvfs = false
336 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
337 functions += ['statfs']
339 have_func_statfs = false
342 if host_system == 'windows'
343 iphlpapi_dep = cc.find_library('iphlpapi')
344 iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
345 foreach ifunc : iphlpapi_funcs
346 if cc.has_function(ifunc,
347 prefix : '#define _WIN32_WINNT 0x0601\n#include <winsock2.h>\n#include <iphlpapi.h>',
348 dependencies : iphlpapi_dep)
349 idefine = 'HAVE_' + ifunc.underscorify().to_upper()
350 glib_conf.set(idefine, 1)
351 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
352 set_variable('have_func_' + ifunc, true)
354 set_variable('have_func_' + ifunc, false)
358 functions += ['if_indextoname', 'if_nametoindex']
361 # AIX splice is something else
362 if host_system != 'aix'
363 functions += ['splice']
366 foreach f : functions
367 if cc.has_function(f)
368 define = 'HAVE_' + f.underscorify().to_upper()
369 glib_conf.set(define, 1)
370 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
371 set_variable('have_func_' + f, true)
373 set_variable('have_func_' + f, false)
377 # Check whether strerror_r returns char *
378 if have_func_strerror_r
379 if cc.compiles('''#define _GNU_SOURCE
382 char error_string[256];
383 char *ptr = strerror_r (-2, error_string, 256);
384 char c = *strerror_r (-2, error_string, 256);
385 return c != 0 && ptr != (void*) 0L;
388 name : 'strerror_r() returns char *')
389 glib_conf.set('STRERROR_R_CHAR_P', 1,
390 description: 'Defined if strerror_r returns char *')
394 # Special-case these functions that have alternative names on Windows/MSVC
395 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
396 glib_conf.set('HAVE_SNPRINTF', 1)
397 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
398 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
399 hack_define = '1\n#define snprintf _snprintf'
400 glib_conf.set('HAVE_SNPRINTF', hack_define)
401 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
404 if cc.has_function('strcasecmp')
405 glib_conf.set('HAVE_STRCASECMP', 1)
406 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
407 elif cc.has_function('_stricmp')
408 hack_define = '1\n#define strcasecmp _stricmp'
409 glib_conf.set('HAVE_STRCASECMP', hack_define)
410 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
413 if cc.has_function('strncasecmp')
414 glib_conf.set('HAVE_STRNCASECMP', 1)
415 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
416 elif cc.has_function('_strnicmp')
417 hack_define = '1\n#define strncasecmp _strnicmp'
418 glib_conf.set('HAVE_STRNCASECMP', hack_define)
419 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
422 if cc.has_header_symbol('sys/sysmacros.h', 'major')
423 glib_conf.set('MAJOR_IN_SYSMACROS', 1)
424 elif cc.has_header_symbol('sys/mkdev.h', 'major')
425 glib_conf.set('MAJOR_IN_MKDEV', 1)
428 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
429 glib_conf.set('HAVE_RTLD_LAZY', 1)
432 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
433 glib_conf.set('HAVE_RTLD_NOW', 1)
436 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
437 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
440 # Check whether to use statfs or statvfs
441 # Some systems have both statfs and statvfs, pick the most "native" for these
442 if have_func_statfs and have_func_statvfs
443 # on solaris and irix, statfs doesn't even have the f_bavail field
444 if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
445 have_func_statfs = false
447 # at least on linux, statfs is the actual syscall
448 have_func_statvfs = false
452 glib_conf.set('USE_STATFS', 1)
453 stat_func_to_use = 'statfs'
454 elif have_func_statvfs
455 glib_conf.set('USE_STATVFS', 1)
456 stat_func_to_use = 'statvfs'
458 stat_func_to_use = 'neither'
460 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
462 if host_system == 'linux'
463 if cc.has_function('mkostemp',
464 prefix: '''#define _GNU_SOURCE
465 #include <stdlib.h>''')
466 glib_conf.set('HAVE_MKOSTEMP', 1)
472 # Mac OS X Carbon support
473 glib_have_carbon = cc.compiles('''#include <Carbon/Carbon.h>
474 #include <CoreServices/CoreServices.h>''',
475 name : 'Mac OS X Carbon support')
477 glib_have_os_x_9_or_later = false
480 glib_conf.set('HAVE_CARBON', true)
481 CARBON_LIBS='-Wl,-framework,Carbon' # FIXME: propagate to .pc files as well
482 platform_ldflags += [CARBON_LIBS]
483 glib_have_os_x_9_or_later = cc.compiles('''#include <AvailabilityMacros.h>
484 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
485 #error Compiling for minimum OS X version before 10.9
486 #endif''', name : 'OS X 9 or later')
491 # Mac OS X Cocoa support
492 glib_have_cocoa = cc.compiles('''#include <Cocoa/Cocoa.h>
493 #ifdef GNUSTEP_BASE_VERSION
494 #error "Detected GNUstep, not Cocoa"
496 name : 'Mac OS X Cocoa support')
499 glib_conf.set('HAVE_COCOA', true)
500 COCOA_LIBS='-Wl,-framework,Foundation' # FIXME: propagate to .pc files as well
501 platform_ldflags += [COCOA_LIBS]
507 if cc.links('''#include <linux/futex.h>
508 #include <sys/syscall.h>
510 int main (int argc, char ** argv) {
511 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
513 }''', name : 'futex(2) system call')
514 glib_conf.set('HAVE_FUTEX', 1)
517 # Check for eventfd(2)
518 if cc.links('''#include <sys/eventfd.h>
520 int main (int argc, char ** argv) {
521 eventfd (0, EFD_CLOEXEC);
523 }''', name : 'eventfd(2) system call')
524 glib_conf.set('HAVE_EVENTFD', 1)
527 clock_gettime_test_code = '''
530 int main (int argc, char ** argv) {
531 return clock_gettime(CLOCK_REALTIME, &t);
534 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
535 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
536 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
537 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
538 librt = cc.find_library('rt')
541 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
543 if cc.compiles(glib_conf_prefix + '''
545 #ifdef HAVE_SYS_PARAM_H
546 #include <sys/param.h>
548 #ifdef HAVE_SYS_VFS_H
551 #ifdef HAVE_SYS_MOUNT_H
552 #include <sys/mount.h>
554 #ifdef HAVE_SYS_STATFS_H
555 #include <sys/statfs.h>
557 void some_func (void) {
560 }''', name : 'number of arguments to statfs() (n=2)')
561 glib_conf.set('STATFS_ARGS', 2)
562 elif cc.compiles(glib_conf_prefix + '''
564 #ifdef HAVE_SYS_PARAM_H
565 #include <sys/param.h>
567 #ifdef HAVE_SYS_VFS_H
570 #ifdef HAVE_SYS_MOUNT_H
571 #include <sys/mount.h>
573 #ifdef HAVE_SYS_STATFS_H
574 #include <sys/statfs.h>
576 void some_func (void) {
578 statfs("/", &st, sizeof (st), 0);
579 }''', name : 'number of arguments to statfs() (n=4)')
580 glib_conf.set('STATFS_ARGS', 4)
582 error('Unable to determine number of arguments to statfs()')
586 # open takes O_DIRECTORY as an option
588 if cc.compiles('''#include <fcntl.h>
589 #include <sys/types.h>
590 #include <sys/stat.h>],
591 void some_func (void) {
592 open(0, O_DIRECTORY, 0);
593 }''', name : 'open() option O_DIRECTORY')
594 glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
597 # Check whether there is a vsnprintf() function with C99 semantics installed.
598 # AC_FUNC_VSNPRINTF_C99
599 # Check whether there is a snprintf() function with C99 semantics installed.
600 # AC_FUNC_SNPRINTF_C99
602 have_good_vsnprintf = false
603 have_good_snprintf = false
605 if host_system == 'windows'
606 # Unfortunately the mingw and Visual Studio 2015+ implementations of C99-style
607 # snprintf and vsnprintf don't seem to be quite good enough, at least not in
608 # mingw-runtime-3.14. (Sorry, I don't know exactly what is the problem,
609 # but it is related to floating point formatting and decimal point vs. comma.)
610 # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
611 # rigorous enough to notice, though.
612 glib_conf.set('HAVE_C99_SNPRINTF', false)
613 glib_conf.set('HAVE_C99_VSNPRINTF', false)
615 vsnprintf_c99_test_code = '''
627 r = vsnprintf(buffer, 5, s, args);
633 /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
634 implementation. The above will return 7 but if you replace
635 the size of the buffer with 0, it borks! */
637 r = vsnprintf(buffer, 0, s, args);
653 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
654 if rres.compiled() and rres.returncode() == 0
655 glib_conf.set('HAVE_C99_VSNPRINTF', 1)
656 have_good_vsnprintf = true
659 snprintf_c99_test_code = '''
670 r = snprintf(buffer, 5, "1234567");
675 r = snprintf(buffer, 0, "1234567");
680 r = snprintf(NULL, 0, "1234567");
695 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
696 if rres.compiled() and rres.returncode() == 0
697 glib_conf.set('HAVE_C99_SNPRINTF', 1)
698 have_good_snprintf = true
702 if host_system == 'windows'
703 glib_conf.set_quoted('EXEEXT', '.exe')
705 glib_conf.set('EXEEXT', '')
708 if have_good_vsnprintf and have_good_snprintf
709 # Our printf is 'good' only if vsnpintf()/snprintf() supports C99 well enough
710 glib_conf.set('HAVE_GOOD_PRINTF', 1) # FIXME: Check for HAVE_UNIX98_PRINTF?
712 glib_conf.set('HAVE_VASPRINTF', 1)
715 # Check whether the printf() family supports Unix98 %n$ positional parameters
716 # AC_FUNC_PRINTF_UNIX98
717 # Nothing uses HAVE_UNIX98_PRINTF
720 # Check for nl_langinfo and CODESET
721 # FIXME: Check for HAVE_BIND_TEXTDOMAIN_CODESET
722 if cc.links('''#include <langinfo.h>
723 int main (int argc, char ** argv) {
724 char *codeset = nl_langinfo (CODESET);
726 }''', name : 'nl_langinfo and CODESET')
727 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
728 glib_conf.set('HAVE_CODESET', 1)
731 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
732 if cc.links('''#include <langinfo.h>
733 int main (int argc, char ** argv) {
735 str = nl_langinfo (PM_STR);
736 str = nl_langinfo (D_T_FMT);
737 str = nl_langinfo (D_FMT);
738 str = nl_langinfo (T_FMT);
739 str = nl_langinfo (T_FMT_AMPM);
740 str = nl_langinfo (MON_1);
741 str = nl_langinfo (ABMON_12);
742 str = nl_langinfo (DAY_1);
743 str = nl_langinfo (ABDAY_7);
745 }''', name : 'nl_langinfo (PM_STR)')
746 glib_conf.set('HAVE_LANGINFO_TIME', 1)
748 if cc.links('''#include <langinfo.h>
749 int main (int argc, char ** argv) {
751 str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
752 str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
753 str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
754 str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
755 str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
756 str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
757 str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
758 str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
759 str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
760 str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
762 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
763 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
766 # Check if C compiler supports the 'signed' keyword
767 if not cc.compiles('''signed char x;''', name : 'signed')
768 glib_conf.set('signed', '/* NOOP */')
771 # Check if the ptrdiff_t type exists
772 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
773 glib_conf.set('HAVE_PTRDIFF_T', 1)
776 # Check for sig_atomic_t type
777 if cc.links('''#include <signal.h>
778 #include <sys/types.h>
779 sig_atomic_t val = 42;
780 int main (int argc, char ** argv) {
781 return val == 42 ? 0 : 1;
782 }''', name : 'sig_atomic_t')
783 glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
786 # Check if 'long long' works and what format can be used to print it
787 # jm_AC_TYPE_LONG_LONG
788 # Nothing uses HAVE_LONG_LONG_FORMAT and HAVE_INT64_AND_I64
789 if cc.compiles('''long long ll = 1LL;
791 int some_func (void) {
792 long long llmax = (long long) -1;
793 return ll << i | ll >> i | llmax / ll | llmax % ll;
794 }''', name : 'long long')
795 glib_conf.set('HAVE_LONG_LONG', 1)
796 have_long_long = true
798 have_long_long = false
801 # Test whether the compiler supports the 'long double' type.
802 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
803 long double foo = 0.0;
804 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
805 int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
806 name : 'long double')
807 glib_conf.set('HAVE_LONG_DOUBLE', 1)
810 #dnl Test whether <stddef.h> has the 'wchar_t' type.
811 if cc.has_header_symbol('stddef.h', 'wchar_t')
812 glib_conf.set('HAVE_WCHAR_T', 1)
815 # Test whether <wchar.h> has the 'wint_t' type.
816 if cc.has_header_symbol('wchar.h', 'wint_t')
817 glib_conf.set('HAVE_WINT_T', 1)
820 found_uintmax_t = false
822 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
823 # doesn't clash with <sys/types.h>, and declares uintmax_t.
824 # jm_AC_HEADER_INTTYPES_H
825 if cc.compiles('''#include <sys/types.h>
826 #include <inttypes.h>
827 void some_func (void) {
828 uintmax_t i = (uintmax_t) -1;
829 }''', name : 'uintmax_t in inttypes.h')
830 glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
831 found_uintmax_t = true
834 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
835 # doesn't clash with <sys/types.h>, and declares uintmax_t.
836 # jm_AC_HEADER_STDINT_H
837 if cc.compiles('''#include <sys/types.h>
839 void some_func (void) {
840 uintmax_t i = (uintmax_t) -1;
841 }''', name : 'uintmax_t in stdint.h')
842 glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
843 found_uintmax_t = true
846 # Define intmax_t to 'long' or 'long long'
847 # if it is not already defined in <stdint.h> or <inttypes.h>.
848 # For simplicity, we assume that a header file defines 'intmax_t' if and
849 # only if it defines 'uintmax_t'.
851 glib_conf.set('HAVE_INTMAX_T', 1)
853 glib_conf.set('intmax_t', 'long long')
855 glib_conf.set('intmax_t', 'long')
858 char_size = cc.sizeof('char')
859 short_size = cc.sizeof('short')
860 int_size = cc.sizeof('int')
861 voidp_size = cc.sizeof('void*')
862 long_size = cc.sizeof('long')
864 long_long_size = cc.sizeof('long long')
868 sizet_size = cc.sizeof('size_t')
869 if cc.get_id() == 'msvc'
870 ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
872 ssizet_size = cc.sizeof('ssize_t')
875 # On Windows, MSVC supports both ll and I64 as format specifiers for 64-bit
876 # integers, but some versions (at least 4.7.x) of MinGW only support I64.
877 if host_system == 'windows'
883 char_align = cc.alignment('char')
884 short_align = cc.alignment('short')
885 int_align = cc.alignment('int')
886 voidp_align = cc.alignment('void*')
887 long_align = cc.alignment('long')
888 long_long_align = cc.alignment('long long')
889 # NOTE: We don't check for size of __int64 because long long is guaranteed to
890 # be 64-bit in C99, and it is available on all supported compilers
891 sizet_align = cc.alignment('size_t')
893 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
895 glib_conf.set('SIZEOF_CHAR', char_size)
896 glib_conf.set('SIZEOF_INT', int_size)
897 glib_conf.set('SIZEOF_SHORT', short_size)
898 glib_conf.set('SIZEOF_LONG', long_size)
899 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
900 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
901 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
902 glib_conf.set('SIZEOF_VOID_P', voidp_size)
915 error('Compiler provides no native 16-bit integer type')
917 glibconfig_conf.set('gint16', gint16)
918 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
919 glibconfig_conf.set_quoted('gint16_format', gint16_format)
920 glibconfig_conf.set_quoted('guint16_format', guint16_format)
927 guint32_align = short_align
933 guint32_align = int_align
939 guint32_align = long_align
941 error('Compiler provides no native 32-bit integer type')
943 glibconfig_conf.set('gint32', gint32)
944 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
945 glibconfig_conf.set_quoted('gint32_format', gint32_format)
946 glibconfig_conf.set_quoted('guint32_format', guint32_format)
947 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
955 gint64_constant='(val)'
956 guint64_constant='(val)'
957 guint64_align = int_align
964 gint64_constant='(val##L)'
965 guint64_constant='(val##UL)'
966 guint64_align = long_align
967 elif long_long_size == 8
969 glib_extension='G_GNUC_EXTENSION '
970 gint64_modifier=int64_m
971 gint64_format=int64_m + 'i'
972 guint64_format=int64_m + 'u'
973 gint64_constant='(G_GNUC_EXTENSION (val##LL))'
974 guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
975 guint64_align = long_long_align
977 error('Compiler provides no native 64-bit integer type')
979 glibconfig_conf.set('glib_extension', glib_extension)
980 glibconfig_conf.set('gint64', gint64)
981 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
982 glibconfig_conf.set_quoted('gint64_format', gint64_format)
983 glibconfig_conf.set_quoted('guint64_format', guint64_format)
984 glibconfig_conf.set('gint64_constant', gint64_constant)
985 glibconfig_conf.set('guint64_constant', guint64_constant)
986 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
988 if host_system == 'windows'
989 glibconfig_conf.set('g_pid_type', 'void*')
990 glibconfig_conf.set_quoted('g_pid_format', 'p')
991 if host_machine.cpu_family() == 'x86_64'
992 glibconfig_conf.set_quoted('g_pollfd_format', '%#I64x')
994 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
997 glibconfig_conf.set('g_pid_type', 'int')
998 glibconfig_conf.set_quoted('g_pid_format', 'i')
999 glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1002 if sizet_size == short_size
1003 glibconfig_conf.set('glib_size_type_define', 'short')
1004 glibconfig_conf.set_quoted('gsize_modifier', 'h')
1005 glibconfig_conf.set_quoted('gssize_modifier', 'h')
1006 glibconfig_conf.set_quoted('gsize_format', 'hu')
1007 glibconfig_conf.set_quoted('gssize_format', 'hi')
1008 glibconfig_conf.set('glib_msize_type', 'SHRT')
1009 elif sizet_size == int_size
1010 glibconfig_conf.set('glib_size_type_define', 'int')
1011 glibconfig_conf.set_quoted('gsize_modifier', '')
1012 glibconfig_conf.set_quoted('gssize_modifier', '')
1013 glibconfig_conf.set_quoted('gsize_format', 'u')
1014 glibconfig_conf.set_quoted('gssize_format', 'i')
1015 glibconfig_conf.set('glib_msize_type', 'INT')
1016 elif sizet_size == long_size
1017 glibconfig_conf.set('glib_size_type_define', 'long')
1018 glibconfig_conf.set_quoted('gsize_modifier', 'l')
1019 glibconfig_conf.set_quoted('gssize_modifier', 'l')
1020 glibconfig_conf.set_quoted('gsize_format', 'lu')
1021 glibconfig_conf.set_quoted('gssize_format', 'li')
1022 glibconfig_conf.set('glib_msize_type', 'LONG')
1023 elif sizet_size == long_long_size
1024 glibconfig_conf.set('glib_size_type_define', 'long long')
1025 glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1026 glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1027 glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1028 glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1029 glibconfig_conf.set('glib_msize_type', 'INT64')
1031 error('Could not determine size of size_t.')
1034 if voidp_size == int_size
1035 glibconfig_conf.set('glib_intptr_type_define', 'int')
1036 glibconfig_conf.set_quoted('gintptr_modifier', '')
1037 glibconfig_conf.set_quoted('gintptr_format', 'i')
1038 glibconfig_conf.set_quoted('guintptr_format', 'u')
1039 glibconfig_conf.set('glib_gpi_cast', '(gint)')
1040 glibconfig_conf.set('glib_gpui_cast', '(guint)')
1041 elif voidp_size == long_size
1042 glibconfig_conf.set('glib_intptr_type_define', 'long')
1043 glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1044 glibconfig_conf.set_quoted('gintptr_format', 'li')
1045 glibconfig_conf.set_quoted('guintptr_format', 'lu')
1046 glibconfig_conf.set('glib_gpi_cast', '(glong)')
1047 glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1048 elif voidp_size == long_long_size
1049 glibconfig_conf.set('glib_intptr_type_define', 'long long')
1050 glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1051 glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1052 glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1053 glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1054 glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1056 error('Could not determine size of void *')
1059 if long_size != 8 and long_long_size != 8 and int_size != 8
1060 error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1063 glibconfig_conf.set('gintbits', int_size * 8)
1064 glibconfig_conf.set('glongbits', long_size * 8)
1065 glibconfig_conf.set('gsizebits', sizet_size * 8)
1066 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1068 # FIXME: maybe meson should tell us the libsuffix?
1069 if host_system == 'windows'
1070 g_module_suffix = 'dll'
1071 elif host_system == 'darwin'
1072 g_module_suffix = 'dylib'
1074 g_module_suffix = 'so'
1076 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1078 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1079 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1080 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1081 glibconfig_conf.set('GLIB_VERSION', glib_version)
1083 glibconfig_conf.set('glib_void_p', voidp_size)
1084 glibconfig_conf.set('glib_long', long_size)
1085 glibconfig_conf.set('glib_size_t', sizet_size)
1086 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1087 if host_machine.endian() == 'big'
1088 glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1089 glibconfig_conf.set('g_bs_native', 'BE')
1090 glibconfig_conf.set('g_bs_alien', 'LE')
1092 glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1093 glibconfig_conf.set('g_bs_native', 'LE')
1094 glibconfig_conf.set('g_bs_alien', 'BE')
1097 # === va_copy checks ===
1098 # we currently check for all three va_copy possibilities, so we get
1099 # all results in config.log for bug reports.
1102 foreach try_func : [ '__va_copy', 'va_copy' ]
1103 if cc.compiles('''#include <stdarg.h>
1106 # include "msvc_recommended_pragmas.h"
1108 void f (int i, ...) {
1109 va_list args1, args2;
1110 va_start (args1, i);
1112 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1114 va_end (args1); va_end (args2);
1119 }'''.format(try_func),
1120 name : try_func + ' check')
1121 va_copy_func = try_func
1124 if va_copy_func != ''
1125 glib_conf.set('G_VA_COPY', va_copy_func)
1126 glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1128 glib_vacopy = '/* #undef G_VA_COPY */'
1131 va_list_val_copy_prog = '''
1134 void f (int i, ...) {
1135 va_list args1, args2;
1136 va_start (args1, i);
1138 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1140 va_end (args1); va_end (args2);
1147 # We do this in two steps so if compilation fails already it looks less alarming
1148 glib_va_val_copy = false
1149 if cc.compiles(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1150 # FIXME: what to do when cross-compiling?
1151 if cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values').returncode() == 0
1152 glib_va_val_copy = true
1155 if not glib_va_val_copy
1156 glib_va_val_copy = false
1157 glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1158 glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1160 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1162 # check for flavours of varargs macros
1163 g_have_iso_c_varargs = cc.compiles('''
1164 void some_func (void) {
1165 int a(int p1, int p2, int p3);
1166 #define call_a(...) a(1,__VA_ARGS__)
1168 }''', name : 'ISO C99 varargs macros in C')
1170 if g_have_iso_c_varargs
1171 glibconfig_conf.set('g_have_iso_c_varargs', '''
1173 # define G_HAVE_ISO_VARARGS 1
1177 g_have_iso_cxx_varargs = cxx.compiles('''
1178 void some_func (void) {
1179 int a(int p1, int p2, int p3);
1180 #define call_a(...) a(1,__VA_ARGS__)
1182 }''', name : 'ISO C99 varargs macros in C++')
1184 if g_have_iso_cxx_varargs
1185 glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1187 # define G_HAVE_ISO_VARARGS 1
1191 g_have_gnuc_varargs = cc.compiles('''
1192 void some_func (void) {
1193 int a(int p1, int p2, int p3);
1194 #define call_a(params...) a(1,params)
1196 }''', name : 'GNUC varargs macros')
1198 if cc.has_header('alloca.h')
1199 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1201 has_syspoll = cc.has_header('sys/poll.h')
1202 has_systypes = cc.has_header('sys/types.h')
1204 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1206 has_winsock2 = cc.has_header('winsock2.h')
1208 if has_syspoll and has_systypes
1209 templ = '''#include<sys/poll.h>
1210 #include<sys/types.h>
1212 int main(int argc, char **argv) {
1213 printf("%d\n", (int)@0@);
1217 templ = '''#define _WIN32_WINNT 0x0600
1219 #include <winsock2.h>
1220 int main(int argc, char **argv) {
1221 printf("%d\n", (int)@0@);
1226 error('FIX POLL* defines')
1229 value_POLLIN = cc.run(templ.format('POLLIN'), name : 'POLLIN value').stdout().strip()
1230 value_POLLOUT = cc.run(templ.format('POLLOUT'), name : 'POLLOUT value').stdout().strip()
1231 value_POLLPRI = cc.run(templ.format('POLLPRI'), name : 'POLLPRI value').stdout().strip()
1232 value_POLLERR = cc.run(templ.format('POLLERR'), name : 'POLLERR value').stdout().strip()
1233 value_POLLHUP = cc.run(templ.format('POLLHUP'), name : 'POLLHUP value').stdout().strip()
1234 value_POLLNVAL = cc.run(templ.format('POLLNVAL'), name : 'POLLNVAL value').stdout().strip()
1236 glibconfig_conf.set('g_pollin', value_POLLIN)
1237 glibconfig_conf.set('g_pollout', value_POLLOUT)
1238 glibconfig_conf.set('g_pollpri', value_POLLPRI)
1239 glibconfig_conf.set('g_pollerr', value_POLLERR)
1240 glibconfig_conf.set('g_pollhup', value_POLLHUP)
1241 glibconfig_conf.set('g_pollnval', value_POLLNVAL)
1243 # Internet address families
1244 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1245 if host_system == 'windows'
1246 glib_inet_includes= '''
1247 #include <winsock2.h>
1250 glib_inet_includes='''
1251 #include <sys/types.h>
1252 #include <sys/socket.h>
1257 [ 'AF_UNIX', 'g_af_unix' ],
1258 [ 'AF_INET', 'g_af_inet' ],
1259 [ 'AF_INET6', 'g_af_inet6' ],
1260 [ 'MSG_OOB', 'g_msg_oob' ],
1261 [ 'MSG_PEEK', 'g_msg_peek' ],
1262 [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1264 foreach d : net_defines
1267 int main(int argc, char **argv) {
1268 printf("%d\n", (int)@1@);
1271 # FIXME: fix for cross-compilation
1272 if not meson.has_exe_wrapper()
1273 error('Fix sys define detection for cross build')
1275 val = cc.run(templ.format(glib_inet_includes, d[0]), name : d[0] + ' value').stdout().strip()
1276 glibconfig_conf.set(d[1], val)
1279 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', true) # FIXME!
1281 # We need a more robust approach here...
1282 host_cpu_family = host_machine.cpu_family()
1283 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')
1284 glib_memory_barrier_needed = false
1285 elif host_cpu_family.startswith('sparc') or host_cpu_family.startswith('alpha') or host_cpu_family.startswith('powerpc') or host_cpu_family == 'ia64'
1286 glib_memory_barrier_needed = true
1288 error('Unknown host cpu: ' + host_cpu_family)
1289 glib_memory_barrier_needed = true
1291 glibconfig_conf.set('G_ATOMIC_OP_MEMORY_BARRIER_NEEDED', glib_memory_barrier_needed)
1293 # Note that the atomic ops are only available with GCC on x86 when
1294 # using -march=i486 or higher. If we detect that the atomic ops are
1295 # not available but would be available given the right flags, we want
1296 # to abort and advise the user to fix their CFLAGS. It's better to do
1297 # that then to silently fall back on emulated atomic ops just because
1298 # the user had the wrong build environment.
1299 atomictest = '''void func() {
1300 volatile int atomic = 2;
1301 __sync_bool_compare_and_swap (&atomic, 2, 3);
1304 if cc.compiles(atomictest)
1305 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', true)
1307 if host_machine.cpu_family() == 'x86' and cc.compiles(atomictest, args : '-march=i486')
1308 error('GLib must be built with -march=i486 or later.')
1310 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', false)
1315 # Let meson figure out all this business and whether -pthread or whatnot is needed
1316 # FIXME: probably needs more tweaking in meson for things like -D_REENTRANT etc.
1317 thread_dep = dependency('threads')
1319 # Determination of thread implementation
1320 if host_system == 'windows'
1321 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1322 glib_conf.set('THREADS_WIN32', 1)
1324 glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1325 glib_conf.set('THREADS_POSIX', 1)
1326 if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1327 glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1329 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1330 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1332 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1333 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1335 # Assume that pthread_setname_np is available in some form; same as configure
1336 if cc.links('''#ifndef _GNU_SOURCE
1337 # define _GNU_SOURCE
1339 #include <pthread.h>
1341 pthread_setname_np("example");
1343 name : 'pthread_setname_np(const char*)',
1344 dependencies : thread_dep)
1346 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1347 elif cc.links('''#ifndef _GNU_SOURCE
1348 # define _GNU_SOURCE
1350 #include <pthread.h>
1352 pthread_setname_np(pthread_self(), "example");
1354 name : 'pthread_setname_np(pthread_t, const char*)',
1355 dependencies : thread_dep)
1356 # Linux, Solaris, etc.
1357 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1361 # FIXME: how to do this when cross-compiling?
1362 # FIXME: we should make it print the result and always return 0, so that
1363 # the output in meson shows up as green
1364 stack_grows_check_prog = '''
1365 volatile int *a = 0, *b = 0;
1377 return b > a ? 0 : 1;
1379 stack_grows_run_result = cc.run(stack_grows_check_prog, name : 'stack grows check')
1380 if stack_grows_run_result.compiled() and stack_grows_run_result.returncode() == 0
1381 glibconfig_conf.set('G_HAVE_GROWING_STACK', 1)
1383 glibconfig_conf.set('G_HAVE_GROWING_STACK', 0)
1388 # USE_LIBICONV_GNU: Using GNU libiconv
1389 # USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library
1391 # We should never use the MinGW C library's iconv. On Windows we use the
1392 # GNU implementation that ships with MinGW.
1394 # On Windows, just always use the built-in implementation
1395 if host_system == 'windows'
1397 glib_conf.set('USE_LIBICONV_NATIVE', true)
1400 iconv_opt = get_option('iconv')
1401 if iconv_opt == 'libc'
1402 if cc.has_function('iconv_open')
1406 elif iconv_opt == 'gnu'
1407 if cc.has_header_symbol('iconv.h', 'libiconv_open')
1408 glib_conf.set('USE_LIBICONV_GNU', true)
1409 libiconv = [cc.find_library('iconv')]
1412 elif iconv_opt == 'native'
1413 if cc.has_header_symbol('iconv.h', 'iconv_open')
1414 glib_conf.set('USE_LIBICONV_NATIVE', true)
1415 libiconv = [cc.find_library('iconv')]
1421 error('No iconv() implementation found in C library or libiconv')
1426 if get_option('internal_pcre')
1428 use_system_pcre = false
1430 pcre = dependency('libpcre', required : false) # Should check for Unicode support, too. FIXME
1432 if cc.get_id() == 'msvc'
1433 # MSVC: Search for the PCRE library by the configuration, which corresponds
1434 # to the output of CMake builds of PCRE. Note that debugoptimized
1435 # is really a Release build with .PDB files.
1436 if buildtype == 'debug'
1437 pcre = cc.find_library('pcred', required : false)
1439 pcre = cc.find_library('pcre', required : false)
1443 use_system_pcre = pcre.found()
1445 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1447 use_pcre_static_flag = false
1449 if host_system == 'windows'
1450 if not use_system_pcre
1451 use_pcre_static_flag = true
1453 pcre_static = cc.links('''#define PCRE_STATIC
1461 name : 'Windows system PCRE is a static build')
1463 use_pcre_static_flag = true
1468 libm = cc.find_library('m', required : false)
1469 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
1470 zlib_libname = '-lz'
1471 if cc.get_id() != 'msvc'
1472 libz_dep = dependency('zlib', fallback : ['zlib', 'zlib_dep'])
1474 # MSVC: Don't use the bundled ZLib sources until we are sure that we can't
1475 # find the ZLib .lib
1476 libz_dep = dependency('zlib', required : false)
1478 # MSVC: Search for the ZLib .lib, which corresponds to the results of
1479 # of using ZLib's win32/makefile.msc.
1480 if not libz_dep.found()
1481 libz_dep = cc.find_library('zlib1', required : false)
1483 zlib_libname = '-lzlib1'
1485 libz_dep = cc.find_library('zlib', required : false)
1487 zlib_libname = '-lzlib'
1489 libz_dep = subproject('zlib').get_variable('zlib_dep')
1495 # Only used on non-glibc targets
1496 libintl = cc.find_library('intl', required : false)
1497 if host_system == 'windows' and not libintl.found()
1498 # Used only when the gettext library is not available (MSVC, not MinGW)
1499 libintl = subproject('proxy-libintl').get_variable('intl_dep')
1500 glib_conf.set('HAVE_DCGETTEXT', 1)
1502 glib_conf.set('HAVE_DCGETTEXT', cc.has_header_symbol('libintl.h', 'dcgettext'))
1504 # We require gettext to always be present
1505 glib_conf.set('HAVE_GETTEXT', 1)
1506 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
1507 # xgettext is optional (on Windows for instance)
1508 xgettext = find_program('xgettext', required : false)
1510 # libmount is only used by gio, but we need to fetch the libs to generate the
1511 # pkg-config file below
1513 if get_option('libmount')
1514 libmount_dep = [dependency('mount', version : '>=2.28', required : false)]
1515 if not libmount_dep[0].found()
1516 libmount_dep = [cc.find_library('mount', required : true)]
1517 if not cc.has_header('libmount/libmount.h')
1518 error('libmount support needs libmount/libmount.h header')
1523 if host_system == 'windows'
1524 winsock2 = cc.find_library('ws2_32')
1528 if get_option('selinux')
1529 selinux_dep = [dependency('libselinux')]
1530 glib_conf.set('SELINUX_LIBS', '-lselinux')
1531 glib_conf.set('HAVE_SELINUX', 1)
1535 if get_option('xattr')
1536 # either glibc or libattr can provide xattr support
1537 # for both of them, we check for getxattr being in
1538 # the library and a valid xattr header.
1541 if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
1542 glib_conf.set('HAVE_SYS_XATTR_H', 1)
1543 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
1544 #failure. try libattr
1545 elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
1546 glib_conf.set('HAVE_ATTR_XATTR_H', 1)
1547 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
1548 xattr_dep = [cc.find_library('xattr')]
1550 error('No getxattr implementation found in C library or libxattr')
1553 glib_conf.set('HAVE_XATTR', 1)
1554 if cc.compiles(glib_conf_prefix + '''
1556 #ifdef HAVE_SYS_TYPES_H
1557 #include <sys/types.h>
1559 #ifdef HAVE_SYS_XATTR_H
1560 #include <sys/xattr.h>
1561 #elif HAVE_ATTR_XATTR_H
1562 #include <attr/xattr.h>
1566 ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
1568 name : 'XATTR_NOFOLLOW')
1569 glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
1573 python = import('python3').find_python()
1575 # Determine which user environment-dependent files that we want to install
1576 have_bash = find_program('bash', required : false).found() # For completion scripts
1577 have_m4 = find_program('m4', required : false).found() # For m4 macros
1578 have_sh = find_program('sh', required : false).found() # For glib-gettextize
1580 # FIXME: defines in config.h that are not actually used anywhere
1581 # (we add them for now to minimise the diff)
1582 glib_conf.set('HAVE_DLFCN_H', 1)
1583 glib_conf.set('__EXTENSIONS__', 1)
1584 glib_conf.set('STDC_HEADERS', 1)
1586 glib_conf.set('SIZEOF___INT64', 8)
1588 # Various substs needed for our pkg-config files
1589 # FIXME: Derive these from the dependency() objects (Meson support needed)
1590 glib_conf.set('ZLIB_LIBS', zlib_libname)
1591 glib_conf.set('LIBFFI_LIBS', '-lffi')
1593 glib_conf.set('INTLLIBS', '-lintl')
1595 if libiconv.length() != 0
1596 glib_conf.set('ICONV_LIBS', '-liconv')
1599 glib_conf.set('PCRE_LIBS', '-lpcre')
1601 if libmount_dep.length() != 0
1602 glib_conf.set('LIBMOUNT_LIBS', '-lmount')
1603 glib_conf.set('HAVE_LIBMOUNT', 1)
1605 glib_conf.set('GIO_MODULE_DIR', glib_giomodulesdir)
1607 # @G_MODULE_LIBS@ @COCOA_LIBS@ @CARBON_LIBS@ @G_LIBS_EXTRA@
1608 # @PCRE_REQUIRES@ @GLIB_EXTRA_CFLAGS@ @G_THREAD_CFLAGS@
1611 want_dtrace = get_option('dtrace')
1612 enable_dtrace = false
1614 # Since dtrace support is opt-in we just error out if it was requested but
1615 # is not available. We don't bother with autodetection yet.
1618 error('GLib dtrace support not yet compatible with macOS dtrace')
1620 dtrace = find_program('dtrace', required : true) # error out if not found
1621 if not cc.has_header('sys/sdt.h')
1622 error('dtrace support needs sys/sdt.h header')
1624 # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
1625 dtrace_obj_gen = generator(dtrace,
1626 output : '@BASENAME@.o',
1627 arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1628 # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
1629 # -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
1630 dtrace_hdr_gen = generator(dtrace,
1631 output : '@BASENAME@.h',
1632 arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1633 glib_conf.set('HAVE_DTRACE', 1)
1634 enable_dtrace = true
1638 want_systemtap = get_option('systemtap')
1639 enable_systemtap = false
1641 if want_systemtap and enable_dtrace
1642 tapset_install_dir = get_option('tapset_install_dir')
1643 if tapset_install_dir == ''
1644 tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
1646 stp_cdata = configuration_data()
1647 stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
1648 stp_cdata.set('LT_CURRENT', minor_version.to_int() * 100)
1649 stp_cdata.set('LT_REVISION', micro_version.to_int())
1650 enable_systemtap = true
1654 windows = import('windows')
1665 # Configure and install pkg-config files
1671 'gmodule-export-2.0.pc',
1672 'gmodule-no-export-2.0.pc',
1675 if host_system == 'windows'
1676 pc_files += ['gio-windows-2.0.pc']
1678 pc_files += ['gio-unix-2.0.pc']
1681 foreach pc : pc_files
1682 configure_file(input : pc + '.in',
1684 install_dir : glib_pkgconfigreldir,
1686 configuration : glib_conf)
1689 # NOTE: We skip glib-zip.in because the filenames it assumes don't match ours
1691 # Install glib-gettextize executable, if a UNIX-style shell is found
1693 configure_file(input : 'glib-gettextize.in',
1695 install_dir : 'bin',
1696 output : 'glib-gettextize',
1697 configuration : glib_conf)
1701 # Install m4 macros that other projects use
1702 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
1703 install_dir : join_paths(get_option('datadir'), 'aclocal'))
1706 if host_system != 'windows'
1707 # Install Valgrind suppression file (except on Windows,
1708 # as Valgrind is currently not supported on Windows)
1709 install_data('glib.supp',
1710 install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
1713 configure_file(input : 'config.h.meson',
1714 output : 'config.h',
1715 configuration : glib_conf)
1717 if host_system == 'windows'
1718 install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
1721 if get_option('man')
1722 xsltproc = find_program('xsltproc', required : true)
1723 xsltproc_command = [
1726 '--stringparam', 'man.output.quietly', '1',
1727 '--stringparam', 'funcsynopsis.style', 'ansi',
1728 '--stringparam', 'man.th.extra1.suppress', '1',
1729 '--stringparam', 'man.authors.section.enabled', '0',
1730 '--stringparam', 'man.copyright.section.enabled', '0',
1732 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
1735 man1_dir = get_option('mandir') + '/man1'
1738 gnome = import('gnome')
1739 subdir('docs/reference/glib')
1740 subdir('docs/reference/gobject')
1741 subdir('docs/reference/gio')