1 project('glib', 'c', 'cpp',
3 meson_version : '>= 0.38.1',
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 = join_paths(glib_libdir, 'gio', 'modules')
59 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
61 add_project_arguments('-D_GNU_SOURCE', language: 'c')
63 ########################
64 # Configuration begins #
65 ########################
66 glib_conf = configuration_data()
67 glibconfig_conf = configuration_data()
69 # accumulated list of defines as we check for them, so we can easily
70 # use them later in test programs (autoconf does this automatically)
73 glib_conf.set('GLIB_VERSION', glib_version)
74 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
75 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
76 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
77 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
78 glib_conf.set('GLIB_BINARY_AGE', binary_age)
79 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
80 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'http://bugzilla.gnome.org/enter_bug.cgi?product=glib')
81 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
82 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
83 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
84 glib_conf.set_quoted('PACKAGE_URL', '')
85 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
86 glib_conf.set('ENABLE_NLS', 1)
88 # Variables used in glib-gettextize and pkg-config files
89 # These should not contain " quotes around the values
90 glib_conf.set('PACKAGE', 'glib')
91 glib_conf.set('VERSION', meson.project_version())
92 glib_conf.set('prefix', glib_prefix)
93 glib_conf.set('exec_prefix', glib_prefix)
94 glib_conf.set('libdir', glib_libdir)
95 glib_conf.set('includedir', glib_includedir)
96 glib_conf.set('datadir', glib_datadir)
97 glib_conf.set('datarootdir', glib_datadir)
99 glib_conf.set('_GNU_SOURCE', 1)
101 if host_system == 'windows'
102 # Poll doesn't work on devices on Windows
103 glib_conf.set('BROKEN_POLL', true)
106 # Detect and set symbol visibility
107 glib_hidden_visibility_args = []
108 if get_option('default_library') != 'static'
109 if host_system == 'windows'
110 glib_conf.set('DLL_EXPORT', true)
111 if cc.get_id() == 'msvc'
112 glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
113 elif cc.has_argument('-fvisibility=hidden')
114 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
115 glib_hidden_visibility_args = ['-fvisibility=hidden']
117 elif cc.has_argument('-fvisibility=hidden')
118 glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
119 glib_hidden_visibility_args = ['-fvisibility=hidden']
123 # FIXME: what about Cygwin (G_WITH_CYGWIN)
124 if host_system == 'windows'
125 glib_os = '''#define G_OS_WIN32
126 #define G_PLATFORM_WIN32'''
128 glib_os = '#define G_OS_UNIX'
130 glibconfig_conf.set('glib_os', glib_os)
132 # We need to know the build type to determine what .lib files we need on Visual Studio
133 # for dependencies that don't normally come with pkg-config files for Visual Studio builds
134 buildtype = get_option('buildtype')
136 # check for header files
172 'dirent.h', # MSC does not come with this by default
173 'sys/time.h', # MSC does not come with this by default
191 define = 'HAVE_' + h.underscorify().to_upper()
192 glib_conf.set(define, 1)
193 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
197 if cc.has_header('linux/netlink.h')
198 glib_conf.set('HAVE_NETLINK', 1)
201 if glib_conf.has('HAVE_LOCALE_H')
202 if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
203 glib_conf.set('HAVE_LC_MESSAGES', 1)
207 struct_stat_blkprefix = '''
208 #include <sys/types.h>
209 #include <sys/stat.h>
213 #ifdef HAVE_SYS_STATFS_H
214 #include <sys/statfs.h>
216 #ifdef HAVE_SYS_PARAM_H
217 #include <sys/param.h>
219 #ifdef HAVE_SYS_MOUNT_H
220 #include <sys/mount.h>
225 [ 'stat', 'st_mtimensec' ],
226 [ 'stat', 'st_mtim.tv_nsec' ],
227 [ 'stat', 'st_atimensec' ],
228 [ 'stat', 'st_atim.tv_nsec' ],
229 [ 'stat', 'st_ctimensec' ],
230 [ 'stat', 'st_ctim.tv_nsec' ],
231 [ 'stat', 'st_birthtime' ],
232 [ 'stat', 'st_birthtimensec' ],
233 [ 'stat', 'st_birthtim' ],
234 [ 'stat', 'st_birthtim.tv_nsec' ],
235 [ 'stat', 'st_blksize', struct_stat_blkprefix ],
236 [ 'stat', 'st_blocks', struct_stat_blkprefix ],
237 [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
238 [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
239 [ 'dirent', 'd_type', '''#include <sys/types.h>
240 #include <dirent.h>''' ],
243 foreach m : struct_members
244 header_check_prefix = glib_conf_prefix
246 header_check_prefix = header_check_prefix + m[2]
248 header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
250 if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
251 define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
252 glib_conf.set(define, 1)
253 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
258 # Windows Support (Vista+)
259 if host_system == 'windows'
260 glib_conf.set('_WIN32_WINNT', '0x0601')
323 if glib_conf.has('HAVE_SYS_STATVFS_H')
324 functions += ['statvfs']
326 have_func_statvfs = false
328 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
329 functions += ['statfs']
331 have_func_statfs = false
334 if host_system == 'windows'
335 iphlpapi_dep = cc.find_library('iphlpapi')
336 iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
337 foreach ifunc : iphlpapi_funcs
338 if cc.has_function(ifunc,
339 prefix : '#define _WIN32_WINNT 0x0601\n#include <winsock2.h>\n#include <iphlpapi.h>',
340 dependencies : iphlpapi_dep)
341 idefine = 'HAVE_' + ifunc.underscorify().to_upper()
342 glib_conf.set(idefine, 1)
343 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
344 set_variable('have_func_' + ifunc, true)
346 set_variable('have_func_' + ifunc, false)
350 functions += ['if_indextoname', 'if_nametoindex']
353 # AIX splice is something else
354 if host_system != 'aix'
355 functions += ['splice']
358 foreach f : functions
359 if cc.has_function(f)
360 define = 'HAVE_' + f.underscorify().to_upper()
361 glib_conf.set(define, 1)
362 glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
363 set_variable('have_func_' + f, true)
365 set_variable('have_func_' + f, false)
369 # Check whether strerror_r returns char *
370 if have_func_strerror_r
371 if cc.compiles('''#define _GNU_SOURCE
374 char error_string[256];
375 char *ptr = strerror_r (-2, error_string, 256);
376 char c = *strerror_r (-2, error_string, 256);
377 return c != 0 && ptr != (void*) 0L;
380 name : 'strerror_r() returns char *')
381 glib_conf.set('STRERROR_R_CHAR_P', 1,
382 description: 'Defined if strerror_r returns char *')
386 # Special-case these functions that have alternative names on Windows/MSVC
387 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
388 glib_conf.set('HAVE_SNPRINTF', 1)
389 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
390 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
391 hack_define = '1\n#define snprintf _snprintf'
392 glib_conf.set('HAVE_SNPRINTF', hack_define)
393 glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
396 if cc.has_function('strcasecmp')
397 glib_conf.set('HAVE_STRCASECMP', 1)
398 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
399 elif cc.has_function('_stricmp')
400 hack_define = '1\n#define strcasecmp _stricmp'
401 glib_conf.set('HAVE_STRCASECMP', hack_define)
402 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
405 if cc.has_function('strncasecmp')
406 glib_conf.set('HAVE_STRNCASECMP', 1)
407 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
408 elif cc.has_function('_strnicmp')
409 hack_define = '1\n#define strncasecmp _strnicmp'
410 glib_conf.set('HAVE_STRNCASECMP', hack_define)
411 glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
414 if cc.has_header_symbol('sys/sysmacros.h', 'major')
415 glib_conf.set('MAJOR_IN_SYSMACROS', 1)
416 elif cc.has_header_symbol('sys/mkdev.h', 'major')
417 glib_conf.set('MAJOR_IN_MKDEV', 1)
420 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
421 glib_conf.set('HAVE_RTLD_LAZY', 1)
424 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
425 glib_conf.set('HAVE_RTLD_NOW', 1)
428 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
429 glib_conf.set('HAVE_RTLD_GLOBAL', 1)
432 # Check whether to use statfs or statvfs
433 # Some systems have both statfs and statvfs, pick the most "native" for these
434 if have_func_statfs and have_func_statvfs
435 # on solaris and irix, statfs doesn't even have the f_bavail field
436 if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
437 have_func_statfs = false
439 # at least on linux, statfs is the actual syscall
440 have_func_statvfs = false
444 glib_conf.set('USE_STATFS', 1)
445 stat_func_to_use = 'statfs'
446 elif have_func_statvfs
447 glib_conf.set('USE_STATVFS', 1)
448 stat_func_to_use = 'statvfs'
450 stat_func_to_use = 'neither'
452 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
454 # Mac OS X Carbon support
455 glib_have_carbon = cc.compiles('''#include <Carbon/Carbon.h>
456 #include <CoreServices/CoreServices.h>''',
457 name : 'Mac OS X Carbon support')
459 glib_have_os_x_9_or_later = false
462 glib_conf.set('HAVE_CARBON', true)
463 CARBON_LIBS='-Wl,-framework,Carbon' # FIXME: propagate to .pc files as well
464 glib_have_os_x_9_or_later = cc.compiles('''#include <AvailabilityMacros.h>
465 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
466 #error Compiling for minimum OS X version before 10.9
467 #endif''', name : 'OS X 9 or later')
472 # Mac OS X Cocoa support
473 glib_have_cocoa = cc.compiles('''#include <Cocoa/Cocoa.h>
474 #ifdef GNUSTEP_BASE_VERSION
475 #error "Detected GNUstep, not Cocoa"
477 name : 'Mac OS X Cocoa support')
480 glib_conf.set('HAVE_COCOA', true)
481 COCOA_LIBS='-Wl,-framework,Foundation' # FIXME: propagate to .pc files as well
487 if cc.links('''#include <linux/futex.h>
488 #include <sys/syscall.h>
490 int main (int argc, char ** argv) {
491 syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
493 }''', name : 'futex(2) system call')
494 glib_conf.set('HAVE_FUTEX', 1)
497 # Check for eventfd(2)
498 if cc.links('''#include <sys/eventfd.h>
500 int main (int argc, char ** argv) {
501 eventfd (0, EFD_CLOEXEC);
503 }''', name : 'eventfd(2) system call')
504 glib_conf.set('HAVE_EVENTFD', 1)
507 clock_gettime_test_code = '''
510 int main (int argc, char ** argv) {
511 return clock_gettime(CLOCK_REALTIME, &t);
514 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
515 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
516 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
517 glib_conf.set('HAVE_CLOCK_GETTIME', 1)
518 librt = cc.find_library('rt')
521 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
523 if cc.compiles(glib_conf_prefix + '''
525 #ifdef HAVE_SYS_PARAM_H
526 #include <sys/param.h>
528 #ifdef HAVE_SYS_VFS_H
531 #ifdef HAVE_SYS_MOUNT_H
532 #include <sys/mount.h>
534 #ifdef HAVE_SYS_STATFS_H
535 #include <sys/statfs.h>
537 void some_func (void) {
540 }''', name : 'number of arguments to statfs() (n=2)')
541 glib_conf.set('STATFS_ARGS', 2)
542 elif cc.compiles(glib_conf_prefix + '''
544 #ifdef HAVE_SYS_PARAM_H
545 #include <sys/param.h>
547 #ifdef HAVE_SYS_VFS_H
550 #ifdef HAVE_SYS_MOUNT_H
551 #include <sys/mount.h>
553 #ifdef HAVE_SYS_STATFS_H
554 #include <sys/statfs.h>
556 void some_func (void) {
558 statfs("/", &st, sizeof (st), 0);
559 }''', name : 'number of arguments to statfs() (n=4)')
560 glib_conf.set('STATFS_ARGS', 4)
562 error('Unable to determine number of arguments to statfs()')
566 # open takes O_DIRECTORY as an option
568 if cc.compiles('''#include <fcntl.h>
569 #include <sys/types.h>
570 #include <sys/stat.h>],
571 void some_func (void) {
572 open(0, O_DIRECTORY, 0);
573 }''', name : 'open() option O_DIRECTORY')
574 glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
577 # Check whether there is a vsnprintf() function with C99 semantics installed.
578 # AC_FUNC_VSNPRINTF_C99
579 # Check whether there is a snprintf() function with C99 semantics installed.
580 # AC_FUNC_SNPRINTF_C99
582 have_good_vsnprintf = false
583 have_good_snprintf = false
585 if host_system == 'windows'
586 # Unfortunately the mingw and Visual Studio 2015+ implementations of C99-style
587 # snprintf and vsnprintf don't seem to be quite good enough, at least not in
588 # mingw-runtime-3.14. (Sorry, I don't know exactly what is the problem,
589 # but it is related to floating point formatting and decimal point vs. comma.)
590 # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
591 # rigorous enough to notice, though.
592 glib_conf.set('HAVE_C99_SNPRINTF', false)
593 glib_conf.set('HAVE_C99_VSNPRINTF', false)
595 vsnprintf_c99_test_code = '''
607 r = vsnprintf(buffer, 5, s, args);
613 /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
614 implementation. The above will return 7 but if you replace
615 the size of the buffer with 0, it borks! */
617 r = vsnprintf(buffer, 0, s, args);
633 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
634 if rres.compiled() and rres.returncode() == 0
635 glib_conf.set('HAVE_C99_VSNPRINTF', 1)
636 have_good_vsnprintf = true
639 snprintf_c99_test_code = '''
650 r = snprintf(buffer, 5, "1234567");
655 r = snprintf(buffer, 0, "1234567");
660 r = snprintf(NULL, 0, "1234567");
675 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
676 if rres.compiled() and rres.returncode() == 0
677 glib_conf.set('HAVE_C99_SNPRINTF', 1)
678 have_good_snprintf = true
682 if host_system == 'windows'
683 glib_conf.set_quoted('EXEEXT', '.exe')
685 glib_conf.set('EXEEXT', '')
688 if have_good_vsnprintf and have_good_snprintf
689 # Our printf is 'good' only if vsnpintf()/snprintf() supports C99 well enough
690 glib_conf.set('HAVE_GOOD_PRINTF', 1) # FIXME: Check for HAVE_UNIX98_PRINTF?
692 glib_conf.set('HAVE_VASPRINTF', 1)
695 # Check whether the printf() family supports Unix98 %n$ positional parameters
696 # AC_FUNC_PRINTF_UNIX98
697 # Nothing uses HAVE_UNIX98_PRINTF
700 # Check for nl_langinfo and CODESET
701 # FIXME: Check for HAVE_BIND_TEXTDOMAIN_CODESET
702 if cc.links('''#include <langinfo.h>
703 int main (int argc, char ** argv) {
704 char *codeset = nl_langinfo (CODESET);
706 }''', name : 'nl_langinfo and CODESET')
707 glib_conf.set('HAVE_LANGINFO_CODESET', 1)
708 glib_conf.set('HAVE_CODESET', 1)
711 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
712 if cc.links('''#include <langinfo.h>
713 int main (int argc, char ** argv) {
715 str = nl_langinfo (PM_STR);
716 str = nl_langinfo (D_T_FMT);
717 str = nl_langinfo (D_FMT);
718 str = nl_langinfo (T_FMT);
719 str = nl_langinfo (T_FMT_AMPM);
720 str = nl_langinfo (MON_1);
721 str = nl_langinfo (ABMON_12);
722 str = nl_langinfo (DAY_1);
723 str = nl_langinfo (ABDAY_7);
725 }''', name : 'nl_langinfo (PM_STR)')
726 glib_conf.set('HAVE_LANGINFO_TIME', 1)
728 if cc.links('''#include <langinfo.h>
729 int main (int argc, char ** argv) {
731 str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
732 str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
733 str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
734 str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
735 str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
736 str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
737 str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
738 str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
739 str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
740 str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
742 }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
743 glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
746 # Check if C compiler supports the 'signed' keyword
747 if not cc.compiles('''signed char x;''', name : 'signed')
748 glib_conf.set('signed', '/* NOOP */')
751 # Check if the ptrdiff_t type exists
752 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
753 glib_conf.set('HAVE_PTRDIFF_T', 1)
756 # Check for sig_atomic_t type
757 if cc.links('''#include <signal.h>
758 #include <sys/types.h>
759 sig_atomic_t val = 42;
760 int main (int argc, char ** argv) {
761 return val == 42 ? 0 : 1;
762 }''', name : 'sig_atomic_t')
763 glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
766 # Check if 'long long' works and what format can be used to print it
767 # jm_AC_TYPE_LONG_LONG
768 # Nothing uses HAVE_LONG_LONG_FORMAT and HAVE_INT64_AND_I64
769 if cc.compiles('''long long ll = 1LL;
771 int some_func (void) {
772 long long llmax = (long long) -1;
773 return ll << i | ll >> i | llmax / ll | llmax % ll;
774 }''', name : 'long long')
775 glib_conf.set('HAVE_LONG_LONG', 1)
776 have_long_long = true
778 have_long_long = false
781 # Test whether the compiler supports the 'long double' type.
782 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
783 long double foo = 0.0;
784 /* On Ultrix 4.3 cc, long double is 4 and double is 8. */
785 int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
786 name : 'long double')
787 glib_conf.set('HAVE_LONG_DOUBLE', 1)
790 #dnl Test whether <stddef.h> has the 'wchar_t' type.
791 if cc.has_header_symbol('stddef.h', 'wchar_t')
792 glib_conf.set('HAVE_WCHAR_T', 1)
795 # Test whether <wchar.h> has the 'wint_t' type.
796 if cc.has_header_symbol('wchar.h', 'wint_t')
797 glib_conf.set('HAVE_WINT_T', 1)
800 found_uintmax_t = false
802 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
803 # doesn't clash with <sys/types.h>, and declares uintmax_t.
804 # jm_AC_HEADER_INTTYPES_H
805 if cc.compiles('''#include <sys/types.h>
806 #include <inttypes.h>
807 void some_func (void) {
808 uintmax_t i = (uintmax_t) -1;
809 }''', name : 'uintmax_t in inttypes.h')
810 glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
811 found_uintmax_t = true
814 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
815 # doesn't clash with <sys/types.h>, and declares uintmax_t.
816 # jm_AC_HEADER_STDINT_H
817 if cc.compiles('''#include <sys/types.h>
819 void some_func (void) {
820 uintmax_t i = (uintmax_t) -1;
821 }''', name : 'uintmax_t in stdint.h')
822 glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
823 found_uintmax_t = true
826 # Define intmax_t to 'long' or 'long long'
827 # if it is not already defined in <stdint.h> or <inttypes.h>.
828 # For simplicity, we assume that a header file defines 'intmax_t' if and
829 # only if it defines 'uintmax_t'.
831 glib_conf.set('HAVE_INTMAX_T', 1)
833 glib_conf.set('intmax_t', 'long long')
835 glib_conf.set('intmax_t', 'long')
838 char_size = cc.sizeof('char')
839 short_size = cc.sizeof('short')
840 int_size = cc.sizeof('int')
841 voidp_size = cc.sizeof('void*')
842 long_size = cc.sizeof('long')
844 long_long_size = cc.sizeof('long long')
848 sizet_size = cc.sizeof('size_t')
849 if cc.get_id() == 'msvc'
850 ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
852 ssizet_size = cc.sizeof('ssize_t')
855 # On Windows, MSVC supports both ll and I64 as format specifiers for 64-bit
856 # integers, but some versions (at least 4.7.x) of MinGW only support I64.
857 if host_system == 'windows'
863 char_align = cc.alignment('char')
864 short_align = cc.alignment('short')
865 int_align = cc.alignment('int')
866 voidp_align = cc.alignment('void*')
867 long_align = cc.alignment('long')
868 long_long_align = cc.alignment('long long')
869 # NOTE: We don't check for size of __int64 because long long is guaranteed to
870 # be 64-bit in C99, and it is available on all supported compilers
871 sizet_align = cc.alignment('size_t')
873 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
875 glib_conf.set('SIZEOF_CHAR', char_size)
876 glib_conf.set('SIZEOF_INT', int_size)
877 glib_conf.set('SIZEOF_SHORT', short_size)
878 glib_conf.set('SIZEOF_LONG', long_size)
879 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
880 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
881 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
882 glib_conf.set('SIZEOF_VOID_P', voidp_size)
895 error('Compiler provides no native 16-bit integer type')
897 glibconfig_conf.set('gint16', gint16)
898 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
899 glibconfig_conf.set_quoted('gint16_format', gint16_format)
900 glibconfig_conf.set_quoted('guint16_format', guint16_format)
907 guint32_align = short_align
913 guint32_align = int_align
919 guint32_align = long_align
921 error('Compiler provides no native 32-bit integer type')
923 glibconfig_conf.set('gint32', gint32)
924 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
925 glibconfig_conf.set_quoted('gint32_format', gint32_format)
926 glibconfig_conf.set_quoted('guint32_format', guint32_format)
927 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
935 gint64_constant='(val)'
936 guint64_constant='(val)'
937 guint64_align = int_align
944 gint64_constant='(val##L)'
945 guint64_constant='(val##UL)'
946 guint64_align = long_align
947 elif long_long_size == 8
949 glib_extension='G_GNUC_EXTENSION '
950 gint64_modifier=int64_m
951 gint64_format=int64_m + 'i'
952 guint64_format=int64_m + 'u'
953 gint64_constant='(G_GNUC_EXTENSION (val##LL))'
954 guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
955 guint64_align = long_long_align
957 error('Compiler provides no native 64-bit integer type')
959 glibconfig_conf.set('glib_extension', glib_extension)
960 glibconfig_conf.set('gint64', gint64)
961 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
962 glibconfig_conf.set_quoted('gint64_format', gint64_format)
963 glibconfig_conf.set_quoted('guint64_format', guint64_format)
964 glibconfig_conf.set('gint64_constant', gint64_constant)
965 glibconfig_conf.set('guint64_constant', guint64_constant)
966 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
968 if host_system == 'windows'
969 glibconfig_conf.set('g_pid_type', 'void*')
970 glibconfig_conf.set_quoted('g_pid_format', 'p')
971 if host_machine.cpu_family() == 'x86_64'
972 glibconfig_conf.set_quoted('g_pollfd_format', '%#I64x')
974 glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
977 glibconfig_conf.set('g_pid_type', 'int')
978 glibconfig_conf.set_quoted('g_pid_format', 'i')
979 glibconfig_conf.set_quoted('g_pollfd_format', '%d')
982 if sizet_size == short_size
983 glibconfig_conf.set('glib_size_type_define', 'short')
984 glibconfig_conf.set_quoted('gsize_modifier', 'h')
985 glibconfig_conf.set_quoted('gssize_modifier', 'h')
986 glibconfig_conf.set_quoted('gsize_format', 'hu')
987 glibconfig_conf.set_quoted('gssize_format', 'hi')
988 glibconfig_conf.set('glib_msize_type', 'SHRT')
989 elif sizet_size == int_size
990 glibconfig_conf.set('glib_size_type_define', 'int')
991 glibconfig_conf.set_quoted('gsize_modifier', '')
992 glibconfig_conf.set_quoted('gssize_modifier', '')
993 glibconfig_conf.set_quoted('gsize_format', 'u')
994 glibconfig_conf.set_quoted('gssize_format', 'i')
995 glibconfig_conf.set('glib_msize_type', 'INT')
996 elif sizet_size == long_size
997 glibconfig_conf.set('glib_size_type_define', 'long')
998 glibconfig_conf.set_quoted('gsize_modifier', 'l')
999 glibconfig_conf.set_quoted('gssize_modifier', 'l')
1000 glibconfig_conf.set_quoted('gsize_format', 'lu')
1001 glibconfig_conf.set_quoted('gssize_format', 'li')
1002 glibconfig_conf.set('glib_msize_type', 'LONG')
1003 elif sizet_size == long_long_size
1004 glibconfig_conf.set('glib_size_type_define', 'long long')
1005 glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1006 glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1007 glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1008 glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1009 glibconfig_conf.set('glib_msize_type', 'INT64')
1011 error('Could not determine size of size_t.')
1014 if voidp_size == int_size
1015 glibconfig_conf.set('glib_intptr_type_define', 'int')
1016 glibconfig_conf.set_quoted('gintptr_modifier', '')
1017 glibconfig_conf.set_quoted('gintptr_format', 'i')
1018 glibconfig_conf.set_quoted('guintptr_format', 'u')
1019 glibconfig_conf.set('glib_gpi_cast', '(gint)')
1020 glibconfig_conf.set('glib_gpui_cast', '(guint)')
1021 elif voidp_size == long_size
1022 glibconfig_conf.set('glib_intptr_type_define', 'long')
1023 glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1024 glibconfig_conf.set_quoted('gintptr_format', 'li')
1025 glibconfig_conf.set_quoted('guintptr_format', 'lu')
1026 glibconfig_conf.set('glib_gpi_cast', '(glong)')
1027 glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1028 elif voidp_size == long_long_size
1029 glibconfig_conf.set('glib_intptr_type_define', 'long long')
1030 glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1031 glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1032 glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1033 glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1034 glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1036 error('Could not determine size of void *')
1039 if long_size != 8 and long_long_size != 8 and int_size != 8
1040 error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1043 glibconfig_conf.set('gintbits', int_size * 8)
1044 glibconfig_conf.set('glongbits', long_size * 8)
1045 glibconfig_conf.set('gsizebits', sizet_size * 8)
1046 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1048 # FIXME: maybe meson should tell us the libsuffix?
1049 if host_system == 'windows'
1050 g_module_suffix = 'dll'
1051 elif host_system == 'darwin'
1052 g_module_suffix = 'dylib'
1054 g_module_suffix = 'so'
1056 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1058 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1059 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1060 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1062 glibconfig_conf.set('glib_void_p', voidp_size)
1063 glibconfig_conf.set('glib_long', long_size)
1064 glibconfig_conf.set('glib_size_t', sizet_size)
1065 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1066 if host_machine.endian() == 'big'
1067 glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1068 glibconfig_conf.set('g_bs_native', 'BE')
1069 glibconfig_conf.set('g_bs_alien', 'LE')
1071 glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1072 glibconfig_conf.set('g_bs_native', 'LE')
1073 glibconfig_conf.set('g_bs_alien', 'BE')
1076 # === va_copy checks ===
1077 # we currently check for all three va_copy possibilities, so we get
1078 # all results in config.log for bug reports.
1081 foreach try_func : [ '__va_copy', 'va_copy' ]
1082 if cc.compiles('''#include <stdarg.h>
1085 # include "msvc_recommended_pragmas.h"
1087 void f (int i, ...) {
1088 va_list args1, args2;
1089 va_start (args1, i);
1091 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1093 va_end (args1); va_end (args2);
1098 }'''.format(try_func),
1099 name : try_func + ' check')
1100 va_copy_func = try_func
1103 if va_copy_func != ''
1104 glib_conf.set('G_VA_COPY', va_copy_func)
1105 glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1107 glib_vacopy = '/* #undef G_VA_COPY */'
1110 va_list_val_copy_prog = '''
1113 void f (int i, ...) {
1114 va_list args1, args2;
1115 va_start (args1, i);
1117 if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1119 va_end (args1); va_end (args2);
1126 # We do this in two steps so if compilation fails already it looks less alarming
1127 glib_va_val_copy = false
1128 if cc.compiles(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1129 # FIXME: what to do when cross-compiling?
1130 if cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values').returncode() == 0
1131 glib_va_val_copy = true
1134 if not glib_va_val_copy
1135 glib_va_val_copy = false
1136 glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1137 glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1139 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1141 # check for flavours of varargs macros
1142 g_have_iso_c_varargs = cc.compiles('''
1143 void some_func (void) {
1144 int a(int p1, int p2, int p3);
1145 #define call_a(...) a(1,__VA_ARGS__)
1147 }''', name : 'ISO C99 varargs macros in C')
1149 if g_have_iso_c_varargs
1150 glibconfig_conf.set('g_have_iso_c_varargs', '''
1152 # define G_HAVE_ISO_VARARGS 1
1156 g_have_iso_cxx_varargs = cxx.compiles('''
1157 void some_func (void) {
1158 int a(int p1, int p2, int p3);
1159 #define call_a(...) a(1,__VA_ARGS__)
1161 }''', name : 'ISO C99 varargs macros in C++')
1163 if g_have_iso_cxx_varargs
1164 glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1166 # define G_HAVE_ISO_VARARGS 1
1170 g_have_gnuc_varargs = cc.compiles('''
1171 void some_func (void) {
1172 int a(int p1, int p2, int p3);
1173 #define call_a(params...) a(1,params)
1175 }''', name : 'GNUC varargs macros')
1177 if cc.has_header('alloca.h')
1178 glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1180 has_syspoll = cc.has_header('sys/poll.h')
1181 has_systypes = cc.has_header('sys/types.h')
1183 glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1185 has_winsock2 = cc.has_header('winsock2.h')
1187 if has_syspoll and has_systypes
1188 templ = '''#include<sys/poll.h>
1189 #include<sys/types.h>
1191 int main(int argc, char **argv) {
1192 printf("%d\n", (int)@0@);
1196 templ = '''#define _WIN32_WINNT 0x0600
1198 #include <winsock2.h>
1199 int main(int argc, char **argv) {
1200 printf("%d\n", (int)@0@);
1205 error('FIX POLL* defines')
1208 value_POLLIN = cc.run(templ.format('POLLIN'), name : 'POLLIN value').stdout().strip()
1209 value_POLLOUT = cc.run(templ.format('POLLOUT'), name : 'POLLOUT value').stdout().strip()
1210 value_POLLPRI = cc.run(templ.format('POLLPRI'), name : 'POLLPRI value').stdout().strip()
1211 value_POLLERR = cc.run(templ.format('POLLERR'), name : 'POLLERR value').stdout().strip()
1212 value_POLLHUP = cc.run(templ.format('POLLHUP'), name : 'POLLHUP value').stdout().strip()
1213 value_POLLNVAL = cc.run(templ.format('POLLNVAL'), name : 'POLLNVAL value').stdout().strip()
1215 glibconfig_conf.set('g_pollin', value_POLLIN)
1216 glibconfig_conf.set('g_pollout', value_POLLOUT)
1217 glibconfig_conf.set('g_pollpri', value_POLLPRI)
1218 glibconfig_conf.set('g_pollerr', value_POLLERR)
1219 glibconfig_conf.set('g_pollhup', value_POLLHUP)
1220 glibconfig_conf.set('g_pollnval', value_POLLNVAL)
1222 # Internet address families
1223 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1224 if host_system == 'windows'
1225 glib_inet_includes= '''
1226 #include <winsock2.h>
1229 glib_inet_includes='''
1230 #include <sys/types.h>
1231 #include <sys/socket.h>
1236 [ 'AF_UNIX', 'g_af_unix' ],
1237 [ 'AF_INET', 'g_af_inet' ],
1238 [ 'AF_INET6', 'g_af_inet6' ],
1239 [ 'MSG_OOB', 'g_msg_oob' ],
1240 [ 'MSG_PEEK', 'g_msg_peek' ],
1241 [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1243 foreach d : net_defines
1246 int main(int argc, char **argv) {
1247 printf("%d\n", (int)@1@);
1250 # FIXME: fix for cross-compilation
1251 if not meson.has_exe_wrapper()
1252 error('Fix sys define detection for cross build')
1254 val = cc.run(templ.format(glib_inet_includes, d[0]), name : d[0] + ' value').stdout().strip()
1255 glibconfig_conf.set(d[1], val)
1258 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', true) # FIXME!
1260 # We need a more robust approach here...
1261 host_cpu_family = host_machine.cpu_family()
1262 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')
1263 glib_memory_barrier_needed = false
1264 elif host_cpu_family.startswith('sparc') or host_cpu_family.startswith('alpha') or host_cpu_family.startswith('powerpc') or host_cpu_family == 'ia64'
1265 glib_memory_barrier_needed = true
1267 error('Unknown host cpu: ' + host_cpu_family)
1268 glib_memory_barrier_needed = true
1270 glibconfig_conf.set('G_ATOMIC_OP_MEMORY_BARRIER_NEEDED', glib_memory_barrier_needed)
1272 # Note that the atomic ops are only available with GCC on x86 when
1273 # using -march=i486 or higher. If we detect that the atomic ops are
1274 # not available but would be available given the right flags, we want
1275 # to abort and advise the user to fix their CFLAGS. It's better to do
1276 # that then to silently fall back on emulated atomic ops just because
1277 # the user had the wrong build environment.
1278 atomictest = '''void func() {
1279 volatile int atomic = 2;
1280 __sync_bool_compare_and_swap (&atomic, 2, 3);
1283 if cc.compiles(atomictest)
1284 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', true)
1286 if host_machine.cpu_family() == 'x86' and cc.compiles(atomictest, args : '-march=i486')
1287 error('GLib must be built with -march=i486 or later.')
1289 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', false)
1294 # Let meson figure out all this business and whether -pthread or whatnot is needed
1295 # FIXME: probably needs more tweaking in meson for things like -D_REENTRANT etc.
1296 thread_dep = dependency('threads')
1298 # Determination of thread implementation
1299 if host_system == 'windows'
1300 glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1301 glib_conf.set('THREADS_WIN32', 1)
1303 glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1304 glib_conf.set('THREADS_POSIX', 1)
1305 if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1306 glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1308 if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1309 glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1311 if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1312 glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1314 # Assume that pthread_setname_np is available in some form; same as configure
1315 if cc.links('''#ifndef _GNU_SOURCE
1316 # define _GNU_SOURCE
1318 #include <pthread.h>
1320 pthread_setname_np("example");
1322 name : 'pthread_setname_np(const char*)',
1323 dependencies : thread_dep)
1325 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1326 elif cc.links('''#ifndef _GNU_SOURCE
1327 # define _GNU_SOURCE
1329 #include <pthread.h>
1331 pthread_setname_np(pthread_self(), "example");
1333 name : 'pthread_setname_np(pthread_t, const char*)',
1334 dependencies : thread_dep)
1335 # Linux, Solaris, etc.
1336 glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1340 # FIXME: how to do this when cross-compiling?
1341 # FIXME: we should make it print the result and always return 0, so that
1342 # the output in meson shows up as green
1343 stack_grows_check_prog = '''
1344 volatile int *a = 0, *b = 0;
1356 return b > a ? 0 : 1;
1358 stack_grows_run_result = cc.run(stack_grows_check_prog, name : 'stack grows check')
1359 if stack_grows_run_result.compiled() and stack_grows_run_result.returncode() == 0
1360 glibconfig_conf.set('G_HAVE_GROWING_STACK', 1)
1362 glibconfig_conf.set('G_HAVE_GROWING_STACK', 0)
1367 # First, we check if the C library provides iconv, then GNU libiconv, then
1368 # a native implementation
1369 # FIXME: add option as well
1371 # USE_LIBICONV_GNU: Using GNU libiconv
1372 # USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library
1374 # We should never use the MinGW C library's iconv. On Windows we use the
1375 # GNU implementation that ships with MinGW.
1377 # On Windows, just always use the built-in implementation
1378 if host_system == 'windows'
1380 glib_conf.set('USE_LIBICONV_NATIVE', true)
1381 # Check C library; never check MinGW C library
1382 elif cc.has_function('iconv_open')
1384 # Check for libiconv
1385 elif cc.has_header_symbol('iconv.h', 'libiconv_open')
1386 glib_conf.set('USE_LIBICONV_GNU', true)
1387 libiconv = [cc.find_library('iconv')]
1388 # Check for a custom iconv implementation
1389 elif cc.has_header_symbol('iconv.h', 'iconv_open')
1390 glib_conf.set('USE_LIBICONV_NATIVE', true)
1391 libiconv = [cc.find_library('iconv')]
1393 error('No iconv() implementation found in C library or libiconv')
1396 if get_option('with-pcre') == 'internal'
1398 use_system_pcre = false
1400 pcre = dependency('libpcre', required : false) # Should check for Unicode support, too. FIXME
1402 if cc.get_id() == 'msvc'
1403 # MSVC: Search for the PCRE library by the configuration, which corresponds
1404 # to the output of CMake builds of PCRE. Note that debugoptimized
1405 # is really a Release build with .PDB files.
1406 if buildtype == 'debug'
1407 pcre = cc.find_library('pcred', required : false)
1409 pcre = cc.find_library('pcre', required : false)
1413 use_system_pcre = pcre.found()
1415 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1417 use_pcre_static_flag = false
1419 if host_system == 'windows'
1420 if not use_system_pcre
1421 use_pcre_static_flag = true
1423 pcre_static = cc.links('''#define PCRE_STATIC
1431 name : 'Windows system PCRE is a static build')
1433 use_pcre_static_flag = true
1438 libm = cc.find_library('m', required : false)
1439 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
1440 zlib_libname = '-lz'
1441 if cc.get_id() != 'msvc'
1442 libz_dep = dependency('zlib', fallback : ['zlib', 'zlib_dep'])
1444 # MSVC: Don't use the bundled ZLib sources until we are sure that we can't
1445 # find the ZLib .lib
1446 libz_dep = dependency('zlib', required : false)
1448 # MSVC: Search for the ZLib .lib, which corresponds to the results of
1449 # of using ZLib's win32/makefile.msc.
1450 if not libz_dep.found()
1451 libz_dep = cc.find_library('zlib1', required : false)
1453 zlib_libname = '-lzlib1'
1455 libz_dep = cc.find_library('zlib', required : false)
1457 zlib_libname = '-lzlib'
1459 zlib_dep = subproject('zlib').get_variable('zlib_dep')
1465 # Only used on non-glibc targets
1466 libintl = cc.find_library('intl', required : false)
1467 if host_system == 'windows' and not libintl.found()
1468 # Used only when the gettext library is not available (MSVC, not MinGW)
1469 libintl = subproject('proxy-libintl').get_variable('intl_dep')
1470 glib_conf.set('HAVE_DCGETTEXT', 1)
1472 glib_conf.set('HAVE_DCGETTEXT', cc.has_header_symbol('libintl.h', 'dcgettext'))
1474 # We require gettext to always be present
1475 glib_conf.set('HAVE_GETTEXT', 1)
1476 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
1477 # xgettext is optional (on Windows for instance)
1478 xgettext = find_program('xgettext', required : false)
1480 # libmount is only used by gio, but we need to fetch the libs to generate the
1481 # pkg-config file below
1483 libmount_opt = get_option('enable-libmount')
1484 if host_system == 'linux' and libmount_opt != 'no'
1485 libmount_dep = [dependency('mount', version : '>=2.28', required : false)]
1486 if not libmount_dep[0].found()
1487 libmount_dep = [cc.find_library('mount')]
1488 libmount_h = cc.has_header('libmount/libmount.h')
1489 libmount_needed = libmount_opt == 'yes' and host_system == 'linux'
1490 if libmount_needed and (not libmount_dep[0].found() or not libmount_h)
1491 error('Need libmount but couldn\'t find it')
1496 if host_system == 'windows'
1497 winsock2 = cc.find_library('ws2_32')
1500 python = import('python3').find_python()
1502 # FIXME: defines in config.h that are not actually used anywhere
1503 # (we add them for now to minimise the diff)
1504 glib_conf.set('HAVE_DLFCN_H', 1)
1505 glib_conf.set('__EXTENSIONS__', 1)
1506 glib_conf.set('STDC_HEADERS', 1)
1508 glib_conf.set('SIZEOF___INT64', 8)
1510 # Various substs needed for our pkg-config files
1511 # FIXME: Derive these from the dependency() objects (Meson support needed)
1512 glib_conf.set('ZLIB_LIBS', zlib_libname)
1513 glib_conf.set('LIBFFI_LIBS', '-lffi')
1515 glib_conf.set('INTLLIBS', '-lintl')
1517 if libiconv.length() != 0
1518 glib_conf.set('ICONV_LIBS', '-liconv')
1521 glib_conf.set('PCRE_LIBS', '-lpcre')
1523 if libmount_dep.length() == 1 and libmount_dep[0].found()
1524 glib_conf.set('LIBMOUNT_LIBS', '-lmount')
1526 glib_conf.set('GIO_MODULE_DIR', '${libdir}/gio/modules')
1528 # @G_MODULE_LIBS@ @SELINUX_LIBS@ @COCOA_LIBS@ @CARBON_LIBS@ @G_LIBS_EXTRA@
1529 # @PCRE_REQUIRES@ @GLIB_EXTRA_CFLAGS@ @G_THREAD_CFLAGS@
1532 want_dtrace = get_option('enable-dtrace')
1533 enable_dtrace = false
1535 # Since dtrace support is opt-in we just error out if it was requested but
1536 # is not available. We don't bother with autodetection yet.
1539 error('GLib dtrace support not yet compatible with macOS dtrace')
1541 dtrace = find_program('dtrace', required : true) # error out if not found
1542 if not cc.has_header('sys/sdt.h')
1543 error('dtrace support needs sys/sdt.h header')
1545 # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
1546 dtrace_obj_gen = generator(dtrace,
1547 output : '@BASENAME@.o',
1548 arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1549 # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
1550 # -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
1551 dtrace_hdr_gen = generator(dtrace,
1552 output : '@BASENAME@.h',
1553 arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1554 glib_conf.set('HAVE_DTRACE', 1)
1555 enable_dtrace = true
1559 want_systemtap = get_option('enable-systemtap')
1560 enable_systemtap = false
1562 if want_systemtap and enable_dtrace
1563 tapset_install_dir = get_option('tapset-install-dir')
1564 if tapset_install_dir == ''
1565 tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset')
1567 stp_cdata = configuration_data()
1568 stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
1569 stp_cdata.set('LT_CURRENT', minor_version.to_int() * 100)
1570 stp_cdata.set('LT_REVISION', micro_version.to_int())
1571 enable_systemtap = true
1585 # Configure and install pkg-config files
1591 'gmodule-export-2.0.pc',
1592 'gmodule-no-export-2.0.pc',
1595 if host_system == 'windows'
1596 pc_files += ['gio-windows-2.0.pc']
1598 pc_files += ['gio-unix-2.0.pc']
1601 foreach pc : pc_files
1602 configure_file(input : pc + '.in',
1604 install_dir : glib_pkgconfigreldir,
1606 configuration : glib_conf)
1609 # NOTE: We skip glib-zip.in because the filenames it assumes don't match ours
1611 # Install glib-gettextize executable
1612 configure_file(input : 'glib-gettextize.in',
1614 install_dir : 'bin',
1615 output : 'glib-gettextize',
1616 configuration : glib_conf)
1618 # Install m4 macros that other projects use
1619 install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
1620 install_dir : join_paths(get_option('datadir'), 'aclocal'))
1621 # Install Valgrind suppression file
1622 install_data('glib.supp',
1623 install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
1625 configure_file(input : 'config.h.meson',
1626 output : 'config.h',
1627 configuration : glib_conf)
1629 if host_system == 'windows'
1630 install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
1633 if get_option('with-man') != 'no'
1634 xsltproc = find_program('xsltproc', required : false)
1635 if not xsltproc.found() and get_option('with-man') == 'yes'
1636 error('man pages enabled and xsltproc not found')
1638 xsltproc_command = [
1641 '--stringparam', 'man.output.quietly', '1',
1642 '--stringparam', 'funcsynopsis.style', 'ansi',
1643 '--stringparam', 'man.th.extra1.suppress', '1',
1644 '--stringparam', 'man.authors.section.enabled', '0',
1645 '--stringparam', 'man.copyright.section.enabled', '0',
1647 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
1650 man1_dir = get_option('mandir') + '/man1'
1653 gnome = import('gnome')
1654 subdir('docs/reference/glib')
1655 subdir('docs/reference/gobject')
1656 subdir('docs/reference/gio')