Merge branch 'wip/lantw/freebsd-kqueue-simple' into 'master'
[glib.git] / meson.build
blob91b8721a198ce414cb71150db368daeadd590322
1 project('glib', 'c', 'cpp',
2   version : '2.57.1',
3   meson_version : '>= 0.46.0',
4   default_options : [
5     'buildtype=debugoptimized',
6     'warning_level=1',
7     'c_std=gnu89'
8   ]
11 cc = meson.get_compiler('c')
12 cxx = meson.get_compiler('cpp')
14 cc_can_run = not meson.is_cross_build() or meson.has_exe_wrapper()
16 if cc.get_id() == 'msvc'
17   # Ignore several spurious warnings for things glib does very commonly
18   # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
19   # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
20   # NOTE: Only add warnings here if you are sure they're spurious
21   add_project_arguments('/wd4035', '/wd4715', '/wd4116',
22     '/wd4046', '/wd4068', '/wo4090', '/FImsvc_recommended_pragmas.h',language : 'c')
23   # Disable SAFESEH with MSVC for plugins and libs that use external deps that
24   # are built with MinGW
25   noseh_link_args = ['/SAFESEH:NO']
26   # Set the input and exec encoding to utf-8, like is the default with GCC
27   add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c')
28 else
29   noseh_link_args = []
30   # -mms-bitfields vs -fnative-struct ?
31 endif
33 host_system = host_machine.system()
35 glib_version = meson.project_version()
36 glib_api_version = '2.0'
37 version_arr = glib_version.split('.')
38 major_version = version_arr[0].to_int()
39 minor_version = version_arr[1].to_int()
40 micro_version = version_arr[2].to_int()
42 interface_age = minor_version.is_odd() ? 0 : micro_version
43 binary_age = 100 * minor_version + micro_version
45 soversion = 0
46 # Maintain compatibility with previous libtool versioning
47 # current = minor * 100 + micro
48 library_version = '@0@.@1@.@2@'.format(soversion, binary_age - interface_age, interface_age)
50 configinc = include_directories('.')
51 glibinc = include_directories('glib')
52 gobjectinc = include_directories('gobject')
53 gmoduleinc = include_directories('gmodule')
54 gioinc = include_directories('gio')
56 glib_prefix = get_option('prefix')
57 glib_bindir = join_paths(glib_prefix, get_option('bindir'))
58 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
59 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
60 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
61 glib_includedir = join_paths(glib_prefix, get_option('includedir'))
62 glib_giomodulesdir = get_option('gio_module_dir')
63 if glib_giomodulesdir == ''
64   glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
65 endif
67 glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
69 add_project_arguments('-D_GNU_SOURCE', language: 'c')
71 # Disable strict aliasing;
72 # see https://bugzilla.gnome.org/show_bug.cgi?id=791622
73 if cc.has_argument('-fno-strict-aliasing')
74   add_project_arguments('-fno-strict-aliasing', language: 'c')
75 endif
77 ########################
78 # Configuration begins #
79 ########################
80 glib_conf = configuration_data()
81 glibconfig_conf = configuration_data()
83 # accumulated list of defines as we check for them, so we can easily
84 # use them later in test programs (autoconf does this automatically)
85 glib_conf_prefix = ''
87 glib_conf.set('GLIB_MAJOR_VERSION', major_version)
88 glib_conf.set('GLIB_MINOR_VERSION', minor_version)
89 glib_conf.set('GLIB_MICRO_VERSION', micro_version)
90 glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
91 glib_conf.set('GLIB_BINARY_AGE', binary_age)
92 glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
93 glib_conf.set_quoted('PACKAGE_BUGREPORT', 'http://bugzilla.gnome.org/enter_bug.cgi?product=glib')
94 glib_conf.set_quoted('PACKAGE_NAME', 'glib')
95 glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
96 glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
97 glib_conf.set_quoted('PACKAGE_URL', '')
98 glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
99 glib_conf.set('ENABLE_NLS', 1)
101 # used by the .rc.in files
102 glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
104 glib_conf.set('_GNU_SOURCE', 1)
106 if host_system == 'windows'
107   # Poll doesn't work on devices on Windows
108   glib_conf.set('BROKEN_POLL', true)
109 endif
111 # Check for GNU visibility attributes
112 g_have_gnuc_visibility = cc.compiles('''
113   void
114   __attribute__ ((visibility ("hidden")))
115        f_hidden (void)
116   {
117   }
118   void
119   __attribute__ ((visibility ("internal")))
120        f_internal (void)
121   {
122   }
123   void
124   __attribute__ ((visibility ("protected")))
125        f_protected (void)
126   {
127   }
128   void
129   __attribute__ ((visibility ("default")))
130        f_default (void)
131   {
132   }
133   int main (void)
134   {
135     f_hidden();
136     f_internal();
137     f_protected();
138     f_default();
139     return 0;
140   }
141   ''',
142   # Not supported by MSVC, but MSVC also won't support visibility,
143   # so it's OK to pass -Werror explicitly. Replace with
144   # override_options : 'werror=true' once that is supported
145   args: ['-Werror'],
146   name : 'GNU C visibility attributes test')
148 if g_have_gnuc_visibility
149   glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
150 endif
152 # Detect and set symbol visibility
153 glib_hidden_visibility_args = []
154 if get_option('default_library') != 'static'
155   if host_system == 'windows'
156     glib_conf.set('DLL_EXPORT', true)
157     if cc.get_id() == 'msvc'
158       glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
159     elif cc.has_argument('-fvisibility=hidden')
160       glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
161       glib_hidden_visibility_args = ['-fvisibility=hidden']
162     endif
163   elif cc.has_argument('-fvisibility=hidden')
164     glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
165     glib_hidden_visibility_args = ['-fvisibility=hidden']
166   endif
167 endif
169 if host_system == 'windows' and get_option('default_library') == 'static'
170     glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
171     glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
172 endif
174 # FIXME: what about Cygwin (G_WITH_CYGWIN)
175 if host_system == 'windows'
176   glib_os = '''#define G_OS_WIN32
177 #define G_PLATFORM_WIN32'''
178 else
179   glib_os = '#define G_OS_UNIX'
180 endif
181 glibconfig_conf.set('glib_os', glib_os)
183 # We need to know the build type to determine what .lib files we need on Visual Studio
184 # for dependencies that don't normally come with pkg-config files for Visual Studio builds
185 buildtype = get_option('buildtype')
187 glib_debug_cflags = []
188 if buildtype.startswith('debug')
189   glib_debug_cflags += ['-DG_ENABLE_DEBUG']
190 elif buildtype == 'release'
191   glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
192 endif
194 add_project_arguments(glib_debug_cflags, language: 'c')
196 # check for header files
198 headers = [
199   'alloca.h',
200   'crt_externs.h',
201   'dirent.h', # MSC does not come with this by default
202   'float.h',
203   'fstab.h',
204   'grp.h',
205   'inttypes.h',
206   'limits.h',
207   'linux/magic.h',
208   'locale.h',
209   'mach/mach_time.h',
210   'malloc.h',
211   'memory.h',
212   'mntent.h',
213   'poll.h',
214   'pwd.h',
215   'sched.h',
216   'stdint.h',
217   'stdlib.h',
218   'string.h',
219   'strings.h',
220   'sys/auxv.h',
221   'sys/event.h',
222   'sys/filio.h',
223   'sys/inotify.h',
224   'sys/mkdev.h',
225   'sys/mntctl.h',
226   'sys/mnttab.h',
227   'sys/mount.h',
228   'sys/param.h',
229   'sys/resource.h',
230   'sys/select.h',
231   'sys/statfs.h',
232   'sys/stat.h',
233   'sys/statvfs.h',
234   'sys/sysctl.h',
235   'sys/time.h', # MSC does not come with this by default
236   'sys/times.h',
237   'sys/types.h',
238   'sys/uio.h',
239   'sys/vfs.h',
240   'sys/vfstab.h',
241   'sys/vmount.h',
242   'sys/wait.h',
243   'termios.h',
244   'unistd.h',
245   'values.h',
246   'xlocale.h',
249 foreach h : headers
250   if cc.has_header(h)
251     define = 'HAVE_' + h.underscorify().to_upper()
252     glib_conf.set(define, 1)
253     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
254   endif
255 endforeach
257 if cc.has_header('linux/netlink.h')
258   glib_conf.set('HAVE_NETLINK', 1)
259 endif
261 if glib_conf.has('HAVE_LOCALE_H')
262   if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
263     glib_conf.set('HAVE_LC_MESSAGES', 1)
264   endif
265 endif
267 struct_stat_blkprefix = '''
268 #include <sys/types.h>
269 #include <sys/stat.h>
270 #ifdef HAVE_UNISTD_H
271 #include <unistd.h>
272 #endif
273 #ifdef HAVE_SYS_STATFS_H
274 #include <sys/statfs.h>
275 #endif
276 #ifdef HAVE_SYS_PARAM_H
277 #include <sys/param.h>
278 #endif
279 #ifdef HAVE_SYS_MOUNT_H
280 #include <sys/mount.h>
281 #endif
284 struct_members = [
285   [ 'stat', 'st_mtimensec' ],
286   [ 'stat', 'st_mtim.tv_nsec' ],
287   [ 'stat', 'st_atimensec' ],
288   [ 'stat', 'st_atim.tv_nsec' ],
289   [ 'stat', 'st_ctimensec' ],
290   [ 'stat', 'st_ctim.tv_nsec' ],
291   [ 'stat', 'st_birthtime' ],
292   [ 'stat', 'st_birthtimensec' ],
293   [ 'stat', 'st_birthtim' ],
294   [ 'stat', 'st_birthtim.tv_nsec' ],
295   [ 'stat', 'st_blksize', struct_stat_blkprefix ],
296   [ 'stat', 'st_blocks', struct_stat_blkprefix ],
297   [ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
298   [ 'statfs', 'f_bavail', struct_stat_blkprefix ],
299   [ 'dirent', 'd_type', '''#include <sys/types.h>
300                            #include <dirent.h>''' ],
303 foreach m : struct_members
304   header_check_prefix = glib_conf_prefix
305   if m.length() == 3
306     header_check_prefix = header_check_prefix + m[2]
307   else
308     header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
309   endif
310   if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
311     define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
312     glib_conf.set(define, 1)
313     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
314   else
315   endif
316 endforeach
318 # Compiler flags
319 if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
320   test_c_args = [
321     '-Wall',
322     '-Wduplicated-branches',
323     '-Wmisleading-indentation',
324     '-Wstrict-prototypes',
325     '-Wunused',
326     '-Werror=declaration-after-statement',
327     '-Werror=format=2',
328     '-Werror=format-security',
329     '-Werror=implicit-function-declaration',
330     '-Werror=init-self',
331     '-Werror=missing-include-dirs',
332     '-Werror=missing-prototypes',
333     '-Werror=pointer-arith',
334   ]
335   test_c_link_args = [
336     '-Wl,-z,nodelete',
337   ]
338   if get_option('bsymbolic_functions')
339     test_c_link_args += ['-Wl,-Bsymbolic-functions']
340   endif
341 else
342   test_c_args = []
343   test_c_link_args = []
344 endif
346 add_project_arguments(cc.get_supported_arguments(test_c_args), language: 'c')
348 # FIXME: We cannot build some of the GResource tests with -z nodelete, which
349 # means we cannot use that flag in add_project_link_arguments(), and must add
350 # it to the relevant targets manually. We do the same with -Bsymbolic-functions
351 # because that is what the autotools build did.
352 # See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
353 # improve this.
354 glib_link_flags = cc.get_supported_link_arguments(test_c_link_args)
356 # Windows Support (7+)
357 if host_system == 'windows'
358   glib_conf.set('_WIN32_WINNT', '0x0601')
359 endif
361 functions = [
362   'alloca',
363   'endmntent',
364   'endservent',
365   'fallocate',
366   'fchmod',
367   'fchown',
368   'fdwalk',
369   'fsync',
370   'getc_unlocked',
371   'getfsstat',
372   'getgrgid_r',
373   'getmntent_r',
374   'getpwuid_r',
375   'getresuid',
376   'getvfsstat',
377   'gmtime_r',
378   'hasmntopt',
379   'inotify_init1',
380   'issetugid',
381   'kevent',
382   'kqueue',
383   'lchmod',
384   'lchown',
385   'link',
386   'localtime_r',
387   'lstat',
388   'mbrtowc',
389   'memalign',
390   'mmap',
391   'newlocale',
392   'pipe2',
393   'poll',
394   'prlimit',
395   'readlink',
396   'recvmmsg',
397   'sendmmsg',
398   'setenv',
399   'setmntent',
400   'strerror_r',
401   'strnlen',
402   'strsignal',
403   'strtod_l',
404   'strtoll_l',
405   'strtoull_l',
406   'symlink',
407   'timegm',
408   'unsetenv',
409   'uselocale',
410   'utimes',
411   'valloc',
412   'vasprintf',
413   'vsnprintf',
414   'wcrtomb',
415   'wcslen',
416   'wcsnlen',
419 if glib_conf.has('HAVE_SYS_STATVFS_H')
420   functions += ['statvfs']
421 else
422   have_func_statvfs = false
423 endif
424 if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
425   functions += ['statfs']
426 else
427   have_func_statfs = false
428 endif
430 if host_system == 'windows'
431   iphlpapi_dep = cc.find_library('iphlpapi')
432   iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
433   foreach ifunc : iphlpapi_funcs
434     iphl_prefix =  '''#define _WIN32_WINNT @0@
435       #include <winsock2.h>
436       #include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
437     if cc.has_function(ifunc,
438                        prefix : iphl_prefix,
439                        dependencies : iphlpapi_dep)
440       idefine = 'HAVE_' + ifunc.underscorify().to_upper()
441       glib_conf.set(idefine, 1)
442       glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
443       set_variable('have_func_' + ifunc, true)
444     else
445       set_variable('have_func_' + ifunc, false)
446     endif
447   endforeach
448 else
449   functions += ['if_indextoname', 'if_nametoindex']
450 endif
452 # AIX splice is something else
453 if host_system != 'aix'
454   functions += ['splice']
455 endif
457 foreach f : functions
458   if cc.has_function(f)
459     define = 'HAVE_' + f.underscorify().to_upper()
460     glib_conf.set(define, 1)
461     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
462     set_variable('have_func_' + f, true)
463   else
464     set_variable('have_func_' + f, false)
465   endif
466 endforeach
468 # Check that stpcpy() is usable; must use header
469 if cc.has_function('stpcpy', prefix : '#include <string.h>')
470   glib_conf.set('HAVE_STPCPY', 1)
471 endif
473 # Check that posix_memalign() is usable; must use header
474 if cc.has_function('posix_memalign', prefix : '#include <stdlib.h>')
475   glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
476 endif
478 # Check whether strerror_r returns char *
479 if have_func_strerror_r
480   if cc.compiles('''#define _GNU_SOURCE
481                     #include <string.h>
482                     int func (void) {
483                       char error_string[256];
484                       char *ptr = strerror_r (-2, error_string, 256);
485                       char c = *strerror_r (-2, error_string, 256);
486                       return c != 0 && ptr != (void*) 0L;
487                     }
488                  ''',
489                  name : 'strerror_r() returns char *')
490     glib_conf.set('STRERROR_R_CHAR_P', 1,
491                   description: 'Defined if strerror_r returns char *')
492   endif
493 endif
495 # Special-case these functions that have alternative names on Windows/MSVC
496 if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
497   glib_conf.set('HAVE_SNPRINTF', 1)
498   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
499 elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
500   hack_define = '1\n#define snprintf _snprintf'
501   glib_conf.set('HAVE_SNPRINTF', hack_define)
502   glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
503 endif
505 if cc.has_function('strcasecmp')
506   glib_conf.set('HAVE_STRCASECMP', 1)
507   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
508 elif cc.has_function('_stricmp')
509   hack_define = '1\n#define strcasecmp _stricmp'
510   glib_conf.set('HAVE_STRCASECMP', hack_define)
511   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
512 endif
514 if cc.has_function('strncasecmp')
515   glib_conf.set('HAVE_STRNCASECMP', 1)
516   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
517 elif cc.has_function('_strnicmp')
518   hack_define = '1\n#define strncasecmp _strnicmp'
519   glib_conf.set('HAVE_STRNCASECMP', hack_define)
520   glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
521 endif
523 if cc.has_header_symbol('sys/sysmacros.h', 'major')
524   glib_conf.set('MAJOR_IN_SYSMACROS', 1)
525 elif cc.has_header_symbol('sys/mkdev.h', 'major')
526   glib_conf.set('MAJOR_IN_MKDEV', 1)
527 endif
529 if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
530   glib_conf.set('HAVE_RTLD_LAZY', 1)
531 endif
533 if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
534   glib_conf.set('HAVE_RTLD_NOW', 1)
535 endif
537 if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
538   glib_conf.set('HAVE_RTLD_GLOBAL', 1)
539 endif
541 # Check whether to use statfs or statvfs
542 # Some systems have both statfs and statvfs, pick the most "native" for these
543 if have_func_statfs and have_func_statvfs
544   # on solaris and irix, statfs doesn't even have the f_bavail field
545   if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
546     have_func_statfs = false
547   else
548     # at least on linux, statfs is the actual syscall
549     have_func_statvfs = false
550   endif
551 endif
552 if have_func_statfs
553   glib_conf.set('USE_STATFS', 1)
554   stat_func_to_use = 'statfs'
555 elif have_func_statvfs
556   glib_conf.set('USE_STATVFS', 1)
557   stat_func_to_use = 'statvfs'
558 else
559   stat_func_to_use = 'neither'
560 endif
561 message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
563 if host_system == 'linux'
564   if cc.has_function('mkostemp',
565                      prefix: '''#define _GNU_SOURCE
566                                 #include <stdlib.h>''')
567     glib_conf.set('HAVE_MKOSTEMP', 1)
568   endif
569 endif
571 osx_ldflags = []
572 glib_have_os_x_9_or_later = false
573 glib_have_carbon = false
574 glib_have_cocoa = false
575 if host_system == 'darwin'
576   add_languages('objc')
577   objcc = meson.get_compiler('objc')
579   osx_ldflags += ['-Wl,-framework,CoreFoundation']
581   # Mac OS X Carbon support
582   glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
583                                        #include <CoreServices/CoreServices.h>''',
584                                     name : 'Mac OS X Carbon support')
586   if glib_have_carbon
587     glib_conf.set('HAVE_CARBON', true)
588     osx_ldflags += '-Wl,-framework,Carbon'
589     glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
590                                                   #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
591                                                   #error Compiling for minimum OS X version before 10.9
592                                                   #endif''',
593                                                name : 'OS X 9 or later')
594   endif
596   # Mac OS X Cocoa support
597   glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
598                                       #ifdef GNUSTEP_BASE_VERSION
599                                       #error "Detected GNUstep, not Cocoa"
600                                       #endif''',
601                                    name : 'Mac OS X Cocoa support')
603   if glib_have_cocoa
604     glib_conf.set('HAVE_COCOA', true)
605     osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
606   endif
608   # FIXME: libgio mix C and objC source files and there is no way to reliably
609   # know which language flags it's going to use to link. Add to both languages
610   # for now. See https://github.com/mesonbuild/meson/issues/3585.
611   add_project_link_arguments(osx_ldflags, language : ['objc', 'c'])
612 endif
614 # Check for futex(2)
615 if cc.links('''#include <linux/futex.h>
616                #include <sys/syscall.h>
617                #include <unistd.h>
618                int main (int argc, char ** argv) {
619                  syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
620                  return 0;
621                }''', name : 'futex(2) system call')
622   glib_conf.set('HAVE_FUTEX', 1)
623 endif
625 # Check for eventfd(2)
626 if cc.links('''#include <sys/eventfd.h>
627                #include <unistd.h>
628                int main (int argc, char ** argv) {
629                  eventfd (0, EFD_CLOEXEC);
630                  return 0;
631                }''', name : 'eventfd(2) system call')
632   glib_conf.set('HAVE_EVENTFD', 1)
633 endif
635 clock_gettime_test_code = '''
636   #include <time.h>
637   struct timespec t;
638   int main (int argc, char ** argv) {
639     return clock_gettime(CLOCK_REALTIME, &t);
640   }'''
641 librt = []
642 if cc.links(clock_gettime_test_code, name : 'clock_gettime')
643   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
644 elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
645   glib_conf.set('HAVE_CLOCK_GETTIME', 1)
646   librt = cc.find_library('rt')
647 endif
649 # if statfs() takes 2 arguments (Posix) or 4 (Solaris)
650 if have_func_statfs
651   if cc.compiles(glib_conf_prefix + '''
652                  #include <unistd.h>
653                         #ifdef HAVE_SYS_PARAM_H
654                         #include <sys/param.h>
655                         #endif
656                         #ifdef HAVE_SYS_VFS_H
657                         #include <sys/vfs.h>
658                         #endif
659                         #ifdef HAVE_SYS_MOUNT_H
660                         #include <sys/mount.h>
661                         #endif
662                         #ifdef HAVE_SYS_STATFS_H
663                         #include <sys/statfs.h>
664                         #endif
665                         void some_func (void) {
666                           struct statfs st;
667                           statfs("/", &st);
668                         }''', name : 'number of arguments to statfs() (n=2)')
669     glib_conf.set('STATFS_ARGS', 2)
670   elif cc.compiles(glib_conf_prefix + '''
671                    #include <unistd.h>
672                           #ifdef HAVE_SYS_PARAM_H
673                           #include <sys/param.h>
674                           #endif
675                           #ifdef HAVE_SYS_VFS_H
676                           #include <sys/vfs.h>
677                           #endif
678                           #ifdef HAVE_SYS_MOUNT_H
679                           #include <sys/mount.h>
680                           #endif
681                           #ifdef HAVE_SYS_STATFS_H
682                           #include <sys/statfs.h>
683                           #endif
684                           void some_func (void) {
685                             struct statfs st;
686                             statfs("/", &st, sizeof (st), 0);
687                           }''', name : 'number of arguments to statfs() (n=4)')
688     glib_conf.set('STATFS_ARGS', 4)
689   else
690     error('Unable to determine number of arguments to statfs()')
691   endif
692 endif
694 # open takes O_DIRECTORY as an option
695 #AC_MSG_CHECKING([])
696 if cc.compiles('''#include <fcntl.h>
697                   #include <sys/types.h>
698                   #include <sys/stat.h>],
699                   void some_func (void) {
700                     open(0, O_DIRECTORY, 0);
701                   }''', name : 'open() option O_DIRECTORY')
702   glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
703 endif
705 # Check whether there is a vsnprintf() function with C99 semantics installed.
706 # AC_FUNC_VSNPRINTF_C99
707 # Check whether there is a snprintf() function with C99 semantics installed.
708 # AC_FUNC_SNPRINTF_C99
710 have_good_vsnprintf = false
711 have_good_snprintf = false
713 if host_system == 'windows' and cc.get_id() == 'msvc'
714   # Unfortunately the Visual Studio 2015+ implementations of C99-style
715   # snprintf and vsnprintf don't seem to be quite good enough.
716   # (Sorry, I don't know exactly what is the problem,
717   # but it is related to floating point formatting and decimal point vs. comma.)
718   # The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
719   # rigorous enough to notice, though.
720   glib_conf.set('HAVE_C99_SNPRINTF', false)
721   glib_conf.set('HAVE_C99_VSNPRINTF', false)
722 else
723   vsnprintf_c99_test_code = '''
724 #include <stdio.h>
725 #include <stdarg.h>
728 doit(char * s, ...)
730   char buffer[32];
731   va_list args;
732   int r;
734   va_start(args, s);
735   r = vsnprintf(buffer, 5, s, args);
736   va_end(args);
738   if (r != 7)
739     exit(1);
741   /* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
742      implementation. The above will return 7 but if you replace
743      the size of the buffer with 0, it borks! */
744   va_start(args, s);
745   r = vsnprintf(buffer, 0, s, args);
746   va_end(args);
748   if (r != 7)
749     exit(1);
751   exit(0);
755 main(void)
757   doit("1234567");
758   exit(1);
759 }'''
761   if cc_can_run
762     rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
763     if rres.compiled() and rres.returncode() == 0
764       glib_conf.set('HAVE_C99_VSNPRINTF', 1)
765       have_good_vsnprintf = true
766     endif
767   else
768       have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
769       glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
770   endif
772   snprintf_c99_test_code = '''
773 #include <stdio.h>
774 #include <stdarg.h>
777 doit()
779   char buffer[32];
780   va_list args;
781   int r;
783   r = snprintf(buffer, 5, "1234567");
785   if (r != 7)
786     exit(1);
788   r = snprintf(buffer, 0, "1234567");
790   if (r != 7)
791     exit(1);
793   r = snprintf(NULL, 0, "1234567");
795   if (r != 7)
796     exit(1);
798   exit(0);
802 main(void)
804   doit();
805   exit(1);
806 }'''
808   if cc_can_run
809     rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
810     if rres.compiled() and rres.returncode() == 0
811       glib_conf.set('HAVE_C99_SNPRINTF', 1)
812       have_good_snprintf = true
813     endif
814   else
815       have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
816       glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
817   endif
818 endif
820 if host_system == 'windows'
821   glib_conf.set_quoted('EXEEXT', '.exe')
822 else
823   glib_conf.set('EXEEXT', '')
824 endif
826 if have_good_vsnprintf and have_good_snprintf
827   # Our printf is 'good' only if vsnpintf()/snprintf() supports C99 well enough
828   glib_conf.set('HAVE_GOOD_PRINTF', 1) # FIXME: Check for HAVE_UNIX98_PRINTF?
829 else
830   glib_conf.set('HAVE_VASPRINTF', 1)
831 endif
833 # Check whether the printf() family supports Unix98 %n$ positional parameters
834 # AC_FUNC_PRINTF_UNIX98
835 # Nothing uses HAVE_UNIX98_PRINTF
838 # Check for nl_langinfo and CODESET
839 # FIXME: Check for HAVE_BIND_TEXTDOMAIN_CODESET
840 if cc.links('''#include <langinfo.h>
841                int main (int argc, char ** argv) {
842                  char *codeset = nl_langinfo (CODESET);
843                  return 0;
844                }''', name : 'nl_langinfo and CODESET')
845   glib_conf.set('HAVE_LANGINFO_CODESET', 1)
846   glib_conf.set('HAVE_CODESET', 1)
847 endif
849 # Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
850 if cc.links('''#include <langinfo.h>
851                int main (int argc, char ** argv) {
852                  char *str;
853                  str = nl_langinfo (PM_STR);
854                  str = nl_langinfo (D_T_FMT);
855                  str = nl_langinfo (D_FMT);
856                  str = nl_langinfo (T_FMT);
857                  str = nl_langinfo (T_FMT_AMPM);
858                  str = nl_langinfo (MON_1);
859                  str = nl_langinfo (ABMON_12);
860                  str = nl_langinfo (DAY_1);
861                  str = nl_langinfo (ABDAY_7);
862                  return 0;
863                }''', name : 'nl_langinfo (PM_STR)')
864   glib_conf.set('HAVE_LANGINFO_TIME', 1)
865 endif
866 if cc.links('''#include <langinfo.h>
867                int main (int argc, char ** argv) {
868                  char *str;
869                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
870                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
871                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
872                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
873                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
874                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
875                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
876                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
877                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
878                  str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
879                  return 0;
880                }''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
881   glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
882 endif
884 # Check for nl_langinfo and alternative month names
885 if cc.links('''#ifndef _GNU_SOURCE
886               # define _GNU_SOURCE
887               #endif
888               #include <langinfo.h>
889                int main (int argc, char ** argv) {
890                  char *str;
891                  str = nl_langinfo (ALTMON_1);
892                  str = nl_langinfo (ALTMON_2);
893                  str = nl_langinfo (ALTMON_3);
894                  str = nl_langinfo (ALTMON_4);
895                  str = nl_langinfo (ALTMON_5);
896                  str = nl_langinfo (ALTMON_6);
897                  str = nl_langinfo (ALTMON_7);
898                  str = nl_langinfo (ALTMON_8);
899                  str = nl_langinfo (ALTMON_9);
900                  str = nl_langinfo (ALTMON_10);
901                  str = nl_langinfo (ALTMON_11);
902                  str = nl_langinfo (ALTMON_12);
903                  return 0;
904                }''', name : 'nl_langinfo (ALTMON_n)')
905   glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
906 endif
908 # Check for nl_langinfo and abbreviated alternative month names
909 if cc.links('''#ifndef _GNU_SOURCE
910               # define _GNU_SOURCE
911               #endif
912               #include <langinfo.h>
913                int main (int argc, char ** argv) {
914                  char *str;
915                  str = nl_langinfo (_NL_ALTMON_1);
916                  str = nl_langinfo (_NL_ALTMON_2);
917                  str = nl_langinfo (_NL_ALTMON_3);
918                  str = nl_langinfo (_NL_ALTMON_4);
919                  str = nl_langinfo (_NL_ALTMON_5);
920                  str = nl_langinfo (_NL_ALTMON_6);
921                  str = nl_langinfo (_NL_ALTMON_7);
922                  str = nl_langinfo (_NL_ALTMON_8);
923                  str = nl_langinfo (_NL_ALTMON_9);
924                  str = nl_langinfo (_NL_ALTMON_10);
925                  str = nl_langinfo (_NL_ALTMON_11);
926                  str = nl_langinfo (_NL_ALTMON_12);
927                  return 0;
928                }''', name : 'nl_langinfo (_NL_ALTMON_n)')
929   glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
930 endif
932 # Check if C compiler supports the 'signed' keyword
933 if not cc.compiles('''signed char x;''', name : 'signed')
934   glib_conf.set('signed', '/* NOOP */')
935 endif
937 # Check if the ptrdiff_t type exists
938 if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
939   glib_conf.set('HAVE_PTRDIFF_T', 1)
940 endif
942 # Check for sig_atomic_t type
943 if cc.links('''#include <signal.h>
944                #include <sys/types.h>
945                sig_atomic_t val = 42;
946                int main (int argc, char ** argv) {
947                  return val == 42 ? 0 : 1;
948                }''', name : 'sig_atomic_t')
949   glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
950 endif
952 # Check if 'long long' works
953 # jm_AC_TYPE_LONG_LONG
954 if cc.compiles('''long long ll = 1LL;
955                   int i = 63;
956                   int some_func (void) {
957                     long long llmax = (long long) -1;
958                     return ll << i | ll >> i | llmax / ll | llmax % ll;
959                   }''', name : 'long long')
960   glib_conf.set('HAVE_LONG_LONG', 1)
961   have_long_long = true
962 else
963   have_long_long = false
964 endif
966 # Test whether the compiler supports the 'long double' type.
967 if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it.  */
968                   long double foo = 0.0;
969                   /* On Ultrix 4.3 cc, long double is 4 and double is 8.  */
970                   int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
971                name : 'long double')
972   glib_conf.set('HAVE_LONG_DOUBLE', 1)
973 endif
975 # Test whether <stddef.h> has the 'wchar_t' type.
976 if cc.has_header_symbol('stddef.h', 'wchar_t')
977   glib_conf.set('HAVE_WCHAR_T', 1)
978 endif
980 # Test whether <wchar.h> has the 'wint_t' type.
981 if cc.has_header_symbol('wchar.h', 'wint_t')
982   glib_conf.set('HAVE_WINT_T', 1)
983 endif
985 found_uintmax_t = false
987 # Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
988 # doesn't clash with <sys/types.h>, and declares uintmax_t.
989 # jm_AC_HEADER_INTTYPES_H
990 if cc.compiles('''#include <sys/types.h>
991                   #include <inttypes.h>
992                   void some_func (void) {
993                     uintmax_t i = (uintmax_t) -1;
994                   }''', name : 'uintmax_t in inttypes.h')
995   glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
996   found_uintmax_t = true
997 endif
999 # Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
1000 # doesn't clash with <sys/types.h>, and declares uintmax_t.
1001 # jm_AC_HEADER_STDINT_H
1002 if cc.compiles('''#include <sys/types.h>
1003                   #include <stdint.h>
1004                   void some_func (void) {
1005                     uintmax_t i = (uintmax_t) -1;
1006                   }''', name : 'uintmax_t in stdint.h')
1007   glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
1008   found_uintmax_t = true
1009 endif
1011 # Define intmax_t to 'long' or 'long long'
1012 # if it is not already defined in <stdint.h> or <inttypes.h>.
1013 # For simplicity, we assume that a header file defines 'intmax_t' if and
1014 # only if it defines 'uintmax_t'.
1015 if found_uintmax_t
1016   glib_conf.set('HAVE_INTMAX_T', 1)
1017 elif have_long_long
1018   glib_conf.set('intmax_t', 'long long')
1019 else
1020   glib_conf.set('intmax_t', 'long')
1021 endif
1023 char_size = cc.sizeof('char')
1024 short_size = cc.sizeof('short')
1025 int_size = cc.sizeof('int')
1026 voidp_size = cc.sizeof('void*')
1027 long_size = cc.sizeof('long')
1028 if have_long_long
1029   long_long_size = cc.sizeof('long long')
1030 else
1031   long_long_size = 0
1032 endif
1033 sizet_size = cc.sizeof('size_t')
1034 if cc.get_id() == 'msvc'
1035   ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
1036 else
1037   ssizet_size = cc.sizeof('ssize_t')
1038 endif
1040 int64_m = 'll'
1041 char_align = cc.alignment('char')
1042 short_align = cc.alignment('short')
1043 int_align = cc.alignment('int')
1044 voidp_align = cc.alignment('void*')
1045 long_align = cc.alignment('long')
1046 long_long_align = cc.alignment('long long')
1047 # NOTE: We don't check for size of __int64 because long long is guaranteed to
1048 # be 64-bit in C99, and it is available on all supported compilers
1049 sizet_align = cc.alignment('size_t')
1051 glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
1053 glib_conf.set('SIZEOF_CHAR', char_size)
1054 glib_conf.set('SIZEOF_INT', int_size)
1055 glib_conf.set('SIZEOF_SHORT', short_size)
1056 glib_conf.set('SIZEOF_LONG', long_size)
1057 glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
1058 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
1059 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
1060 glib_conf.set('SIZEOF_VOID_P', voidp_size)
1062 if short_size == 2
1063   gint16 = 'short'
1064   gint16_modifier='h'
1065   gint16_format='hi'
1066   guint16_format='hu'
1067 elif int_size == 2
1068   gint16 = 'int'
1069   gint16_modifier=''
1070   gint16_format='i'
1071   guint16_format='u'
1072 else
1073   error('Compiler provides no native 16-bit integer type')
1074 endif
1075 glibconfig_conf.set('gint16', gint16)
1076 glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
1077 glibconfig_conf.set_quoted('gint16_format', gint16_format)
1078 glibconfig_conf.set_quoted('guint16_format', guint16_format)
1080 if short_size == 4
1081   gint32 = 'short'
1082   gint32_modifier='h'
1083   gint32_format='hi'
1084   guint32_format='hu'
1085   guint32_align = short_align
1086 elif int_size == 4
1087   gint32 = 'int'
1088   gint32_modifier=''
1089   gint32_format='i'
1090   guint32_format='u'
1091   guint32_align = int_align
1092 elif long_size == 4
1093   gint32 = 'long'
1094   gint32_modifier='l'
1095   gint32_format='li'
1096   guint32_format='lu'
1097   guint32_align = long_align
1098 else
1099   error('Compiler provides no native 32-bit integer type')
1100 endif
1101 glibconfig_conf.set('gint32', gint32)
1102 glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
1103 glibconfig_conf.set_quoted('gint32_format', gint32_format)
1104 glibconfig_conf.set_quoted('guint32_format', guint32_format)
1105 glib_conf.set('ALIGNOF_GUINT32', guint32_align)
1107 if int_size == 8
1108   gint64 = 'int'
1109   gint64_modifier=''
1110   gint64_format='i'
1111   guint64_format='u'
1112   glib_extension=''
1113   gint64_constant='(val)'
1114   guint64_constant='(val)'
1115   guint64_align = int_align
1116 elif long_size == 8
1117   gint64 = 'long'
1118   glib_extension=''
1119   gint64_modifier='l'
1120   gint64_format='li'
1121   guint64_format='lu'
1122   gint64_constant='(val##L)'
1123   guint64_constant='(val##UL)'
1124   guint64_align = long_align
1125 elif long_long_size == 8
1126   gint64 = 'long long'
1127   glib_extension='G_GNUC_EXTENSION '
1128   gint64_modifier=int64_m
1129   gint64_format=int64_m + 'i'
1130   guint64_format=int64_m + 'u'
1131   gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1132   guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
1133   guint64_align = long_long_align
1134 else
1135   error('Compiler provides no native 64-bit integer type')
1136 endif
1137 glibconfig_conf.set('glib_extension', glib_extension)
1138 glibconfig_conf.set('gint64', gint64)
1139 glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
1140 glibconfig_conf.set_quoted('gint64_format', gint64_format)
1141 glibconfig_conf.set_quoted('guint64_format', guint64_format)
1142 glibconfig_conf.set('gint64_constant', gint64_constant)
1143 glibconfig_conf.set('guint64_constant', guint64_constant)
1144 glib_conf.set('ALIGNOF_GUINT64', guint64_align)
1146 if host_system == 'windows'
1147   glibconfig_conf.set('g_pid_type', 'void*')
1148   glibconfig_conf.set_quoted('g_pid_format', 'p')
1149   if host_machine.cpu_family() == 'x86_64'
1150     glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
1151   else
1152     glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
1153   endif
1154   glibconfig_conf.set('g_dir_separator', '\\\\')
1155   glibconfig_conf.set('g_searchpath_separator', ';')
1156 else
1157   glibconfig_conf.set('g_pid_type', 'int')
1158   glibconfig_conf.set_quoted('g_pid_format', 'i')
1159   glibconfig_conf.set_quoted('g_pollfd_format', '%d')
1160   glibconfig_conf.set('g_dir_separator', '/')
1161   glibconfig_conf.set('g_searchpath_separator', ':')
1162 endif
1164 if sizet_size == short_size
1165   glibconfig_conf.set('glib_size_type_define', 'short')
1166   glibconfig_conf.set_quoted('gsize_modifier', 'h')
1167   glibconfig_conf.set_quoted('gssize_modifier', 'h')
1168   glibconfig_conf.set_quoted('gsize_format', 'hu')
1169   glibconfig_conf.set_quoted('gssize_format', 'hi')
1170   glibconfig_conf.set('glib_msize_type', 'SHRT')
1171 elif sizet_size == int_size
1172   glibconfig_conf.set('glib_size_type_define', 'int')
1173   glibconfig_conf.set_quoted('gsize_modifier', '')
1174   glibconfig_conf.set_quoted('gssize_modifier', '')
1175   glibconfig_conf.set_quoted('gsize_format', 'u')
1176   glibconfig_conf.set_quoted('gssize_format', 'i')
1177   glibconfig_conf.set('glib_msize_type', 'INT')
1178 elif sizet_size == long_size
1179   glibconfig_conf.set('glib_size_type_define', 'long')
1180   glibconfig_conf.set_quoted('gsize_modifier', 'l')
1181   glibconfig_conf.set_quoted('gssize_modifier', 'l')
1182   glibconfig_conf.set_quoted('gsize_format', 'lu')
1183   glibconfig_conf.set_quoted('gssize_format', 'li')
1184   glibconfig_conf.set('glib_msize_type', 'LONG')
1185 elif sizet_size == long_long_size
1186   glibconfig_conf.set('glib_size_type_define', 'long long')
1187   glibconfig_conf.set_quoted('gsize_modifier', int64_m)
1188   glibconfig_conf.set_quoted('gssize_modifier', int64_m)
1189   glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
1190   glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
1191   glibconfig_conf.set('glib_msize_type', 'INT64')
1192 else
1193   error('Could not determine size of size_t.')
1194 endif
1196 if voidp_size == int_size
1197   glibconfig_conf.set('glib_intptr_type_define', 'int')
1198   glibconfig_conf.set_quoted('gintptr_modifier', '')
1199   glibconfig_conf.set_quoted('gintptr_format', 'i')
1200   glibconfig_conf.set_quoted('guintptr_format', 'u')
1201   glibconfig_conf.set('glib_gpi_cast', '(gint)')
1202   glibconfig_conf.set('glib_gpui_cast', '(guint)')
1203 elif voidp_size == long_size
1204   glibconfig_conf.set('glib_intptr_type_define', 'long')
1205   glibconfig_conf.set_quoted('gintptr_modifier', 'l')
1206   glibconfig_conf.set_quoted('gintptr_format', 'li')
1207   glibconfig_conf.set_quoted('guintptr_format', 'lu')
1208   glibconfig_conf.set('glib_gpi_cast', '(glong)')
1209   glibconfig_conf.set('glib_gpui_cast', '(gulong)')
1210 elif voidp_size == long_long_size
1211   glibconfig_conf.set('glib_intptr_type_define', 'long long')
1212   glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
1213   glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
1214   glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
1215   glibconfig_conf.set('glib_gpi_cast', '(gint64)')
1216   glibconfig_conf.set('glib_gpui_cast', '(guint64)')
1217 else
1218   error('Could not determine size of void *')
1219 endif
1221 if long_size != 8 and long_long_size != 8 and int_size != 8
1222   error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
1223 endif
1225 glibconfig_conf.set('gintbits', int_size * 8)
1226 glibconfig_conf.set('glongbits', long_size * 8)
1227 glibconfig_conf.set('gsizebits', sizet_size * 8)
1228 glibconfig_conf.set('gssizebits', ssizet_size * 8)
1230 # FIXME: maybe meson should tell us the libsuffix?
1231 if host_system == 'windows'
1232   g_module_suffix = 'dll'
1233 elif host_system == 'darwin'
1234   g_module_suffix = 'dylib'
1235 else
1236   g_module_suffix = 'so'
1237 endif
1238 glibconfig_conf.set('g_module_suffix', g_module_suffix)
1240 glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
1241 glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
1242 glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
1243 glibconfig_conf.set('GLIB_VERSION', glib_version)
1245 glibconfig_conf.set('glib_void_p', voidp_size)
1246 glibconfig_conf.set('glib_long', long_size)
1247 glibconfig_conf.set('glib_size_t', sizet_size)
1248 glibconfig_conf.set('glib_ssize_t', ssizet_size)
1249 if host_machine.endian() == 'big'
1250   glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
1251   glibconfig_conf.set('g_bs_native', 'BE')
1252   glibconfig_conf.set('g_bs_alien', 'LE')
1253 else
1254   glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
1255   glibconfig_conf.set('g_bs_native', 'LE')
1256   glibconfig_conf.set('g_bs_alien', 'BE')
1257 endif
1259 # === va_copy checks ===
1260 # we currently check for all three va_copy possibilities, so we get
1261 # all results in config.log for bug reports.
1263 va_copy_func = ''
1264 foreach try_func : [ '__va_copy', 'va_copy' ]
1265   if cc.compiles('''#include <stdarg.h>
1266                     #include <stdlib.h>
1267                     #ifdef _MSC_VER
1268                     # include "msvc_recommended_pragmas.h"
1269                     #endif
1270                     void f (int i, ...) {
1271                     va_list args1, args2;
1272                     va_start (args1, i);
1273                     @0@ (args2, args1);
1274                     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1275                       exit (1);
1276                     va_end (args1); va_end (args2);
1277                     }
1278                     int main() {
1279                       f (0, 42);
1280                       return 0;
1281                     }'''.format(try_func),
1282                     name : try_func + ' check')
1283     va_copy_func = try_func
1284   endif
1285 endforeach
1286 if va_copy_func != ''
1287   glib_conf.set('G_VA_COPY', va_copy_func)
1288   glib_vacopy = '#define G_VA_COPY ' + va_copy_func
1289 else
1290   glib_vacopy = '/* #undef G_VA_COPY */'
1291 endif
1293 va_list_val_copy_prog = '''
1294   #include <stdarg.h>
1295   #include <stdlib.h>
1296   void f (int i, ...) {
1297     va_list args1, args2;
1298     va_start (args1, i);
1299     args2 = args1;
1300     if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
1301       exit (1);
1302     va_end (args1); va_end (args2);
1303   }
1304   int main() {
1305     f (0, 42);
1306     return 0;
1307   }'''
1309 if cc_can_run
1310   rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
1311   glib_va_val_copy = rres.returncode() == 0
1312 else
1313   glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
1314 endif
1315 if not glib_va_val_copy
1316   glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
1317   glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
1318 endif
1319 glibconfig_conf.set('glib_vacopy', glib_vacopy)
1321 # check for flavours of varargs macros
1322 g_have_iso_c_varargs = cc.compiles('''
1323   void some_func (void) {
1324     int a(int p1, int p2, int p3);
1325     #define call_a(...) a(1,__VA_ARGS__)
1326     call_a(2,3);
1327   }''', name : 'ISO C99 varargs macros in C')
1329 if g_have_iso_c_varargs
1330   glibconfig_conf.set('g_have_iso_c_varargs', '''
1331 #ifndef __cplusplus
1332 # define G_HAVE_ISO_VARARGS 1
1333 #endif''')
1334 endif
1336 g_have_iso_cxx_varargs = cxx.compiles('''
1337   void some_func (void) {
1338     int a(int p1, int p2, int p3);
1339     #define call_a(...) a(1,__VA_ARGS__)
1340     call_a(2,3);
1341   }''', name : 'ISO C99 varargs macros in C++')
1343 if g_have_iso_cxx_varargs
1344   glibconfig_conf.set('g_have_iso_cxx_varargs', '''
1345 #ifdef __cplusplus
1346 # define G_HAVE_ISO_VARARGS 1
1347 #endif''')
1348 endif
1350 g_have_gnuc_varargs = cc.compiles('''
1351   void some_func (void) {
1352     int a(int p1, int p2, int p3);
1353     #define call_a(params...) a(1,params)
1354     call_a(2,3);
1355   }''', name : 'GNUC varargs macros')
1357 if cc.has_header('alloca.h')
1358   glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
1359 endif
1360 has_syspoll = cc.has_header('sys/poll.h')
1361 has_systypes = cc.has_header('sys/types.h')
1362 if has_syspoll
1363   glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
1364 endif
1365 has_winsock2 = cc.has_header('winsock2.h')
1367 if has_syspoll and has_systypes
1368   poll_includes = '''
1369       #include<sys/poll.h>
1370       #include<sys/types.h>'''
1371 elif has_winsock2
1372   poll_includes = '''
1373       #define _WIN32_WINNT @0@
1374       #include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
1375 else
1376   # FIXME?
1377   error('FIX POLL* defines')
1378 endif
1380 poll_defines = [
1381   [ 'POLLIN', 'g_pollin', 1 ],
1382   [ 'POLLOUT', 'g_pollout', 4 ],
1383   [ 'POLLPRI', 'g_pollpri', 2 ],
1384   [ 'POLLERR', 'g_pollerr', 8 ],
1385   [ 'POLLHUP', 'g_pollhup', 16 ],
1386   [ 'POLLNVAL', 'g_pollnval', 32 ],
1389 if has_syspoll and has_systypes
1390   foreach d : poll_defines
1391     val = cc.compute_int(d[0], prefix: poll_includes)
1392     glibconfig_conf.set(d[1], val)
1393   endforeach
1394 elif has_winsock2
1395   # Due to a missed bug in configure.ac the poll test
1396   # never succeeded on Windows and used some pre-defined
1397   # values as a fallback. Keep using them to maintain
1398   # ABI compatibility with autotools builds of glibs
1399   # and with *any* glib-using code compiled against them,
1400   # since these values end up in a public header glibconfig.h.
1401   foreach d : poll_defines
1402     glibconfig_conf.set(d[1], d[2])
1403   endforeach
1404 endif
1406 # Internet address families
1407 # FIXME: what about Cygwin (G_WITH_CYGWIN)
1408 if host_system == 'windows'
1409   inet_includes = '''
1410       #include <winsock2.h>'''
1411 else
1412   inet_includes = '''
1413       #include <sys/types.h>
1414       #include <sys/socket.h>'''
1415 endif
1417 inet_defines = [
1418   [ 'AF_UNIX', 'g_af_unix' ],
1419   [ 'AF_INET', 'g_af_inet' ],
1420   [ 'AF_INET6', 'g_af_inet6' ],
1421   [ 'MSG_OOB', 'g_msg_oob' ],
1422   [ 'MSG_PEEK', 'g_msg_peek' ],
1423   [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
1425 foreach d : inet_defines
1426   val = cc.compute_int(d[0], prefix: inet_includes)
1427   glibconfig_conf.set(d[1], val)
1428 endforeach
1430 glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', true) # FIXME!
1432 # We need a more robust approach here...
1433 host_cpu_family = host_machine.cpu_family()
1434 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')
1435   glib_memory_barrier_needed = false
1436 elif host_cpu_family.startswith('sparc') or host_cpu_family.startswith('alpha') or host_cpu_family.startswith('powerpc') or host_cpu_family == 'ia64'
1437   glib_memory_barrier_needed = true
1438 else
1439   warning('Unknown host cpu: ' + host_cpu_family)
1440   glib_memory_barrier_needed = true
1441 endif
1442 glibconfig_conf.set('G_ATOMIC_OP_MEMORY_BARRIER_NEEDED', glib_memory_barrier_needed)
1444 # We need to decide at configure time if GLib will use real atomic
1445 # operations ("lock free") or emulated ones with a mutex.  This is
1446 # because we must put this information in glibconfig.h so we know if
1447 # it is safe or not to inline using compiler intrinsics directly from
1448 # the header.
1450 # We also publish the information via G_ATOMIC_LOCK_FREE in case the
1451 # user is interested in knowing if they can use the atomic ops across
1452 # processes.
1454 # We can currently support the atomic ops natively when building GLib
1455 # with recent versions of GCC or MSVC.
1457 # Note that the atomic ops are only available with GCC on x86 when
1458 # using -march=i486 or higher.  If we detect that the atomic ops are
1459 # not available but would be available given the right flags, we want
1460 # to abort and advise the user to fix their CFLAGS.  It's better to do
1461 # that then to silently fall back on emulated atomic ops just because
1462 # the user had the wrong build environment.
1463 atomictest = '''int main() {
1464   volatile int atomic = 2;
1465   __sync_bool_compare_and_swap (&atomic, 2, 3);
1466   return 0;
1470 atomicdefine = '''
1471 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1472 #error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
1473 #endif
1476 # We know that we can always use real ("lock free") atomic operations with MSVC
1477 if cc.get_id() == 'msvc' or cc.links(atomictest, name : 'atomic ops')
1478   have_atomic_lock_free = true
1479   if host_system == 'android' and not cc.compiles(atomicdefine, name : 'atomic ops define')
1480     # When building for armv5 on Android, gcc 4.9 provides
1481     # __sync_bool_compare_and_swap but doesn't define
1482     # __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
1483     glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
1484   endif
1485 else
1486   have_atomic_lock_free = false
1487   if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
1488     error('GLib must be built with -march=i486 or later.')
1489   endif
1490 endif
1491 glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
1493 # === Threads ===
1495 # Determination of thread implementation
1496 if host_system == 'windows' and not get_option('force_posix_threads')
1497   thread_dep = []
1498   threads_implementation = 'win32'
1499   glibconfig_conf.set('g_threads_impl_def', 'WIN32')
1500   glib_conf.set('THREADS_WIN32', 1)
1501 else
1502   # FIXME: probably needs more tweaking in meson for things like -D_REENTRANT etc.
1503   thread_dep = dependency('threads')
1504   threads_implementation = 'posix'
1505   pthread_prefix = '''
1506       #ifndef _GNU_SOURCE
1507       # define _GNU_SOURCE
1508       #endif
1509       #include <pthread.h>'''
1510   glibconfig_conf.set('g_threads_impl_def', 'POSIX')
1511   glib_conf.set('THREADS_POSIX', 1)
1512   if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
1513     glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
1514   endif
1515   if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
1516     glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
1517   endif
1518   if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
1519     glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
1520   endif
1521   if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
1522     glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
1523   endif
1524   # Assume that pthread_setname_np is available in some form; same as configure
1525   if cc.links(pthread_prefix + '''
1526               int main() {
1527                 pthread_setname_np("example");
1528                 return 0;
1529               }''',
1530               name : 'pthread_setname_np(const char*)',
1531               dependencies : thread_dep)
1532     # macOS and iOS
1533     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
1534   elif cc.links(pthread_prefix + '''
1535                 int main() {
1536                   pthread_setname_np(pthread_self(), "example");
1537                   return 0;
1538                 }''',
1539                 name : 'pthread_setname_np(pthread_t, const char*)',
1540                 dependencies : thread_dep)
1541     # Linux, Solaris, etc.
1542     glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
1543   endif
1544 endif
1546 # FIXME: we should make it print the result and always return 0, so that
1547 # the output in meson shows up as green
1548 stack_grows_check_prog = '''
1549   volatile int *a = 0, *b = 0;
1550   void f (int i) {
1551     volatile int x = 5;
1552     if (i == 0)
1553       b = &x;
1554     else
1555       f (i - 1);
1556   }
1557   int main () {
1558     volatile int y = 7;
1559     a = &y;
1560     f (100);
1561     return b > a ? 0 : 1;
1562   }'''
1564 if cc_can_run
1565   rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
1566   growing_stack = rres.returncode() == 0
1567 else
1568   growing_stack = meson.get_cross_property('growing_stack', false)
1569 endif
1571 glibconfig_conf.set('G_HAVE_GROWING_STACK', growing_stack)
1573 # Tests for iconv
1575 # USE_LIBICONV_GNU: Using GNU libiconv
1576 # USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library
1578 # We should never use the MinGW C library's iconv. On Windows we use the
1579 # GNU implementation that ships with MinGW.
1581 # On Windows, just always use the built-in implementation
1582 if host_system == 'windows'
1583   libiconv = []
1584   glib_conf.set('USE_LIBICONV_NATIVE', true)
1585 else
1586   found_iconv = false
1587   iconv_opt = get_option('iconv')
1588   if iconv_opt == 'libc'
1589     if cc.has_function('iconv_open')
1590       libiconv = []
1591       found_iconv = true
1592     endif
1593   elif iconv_opt == 'gnu'
1594     if cc.has_header_symbol('iconv.h', 'libiconv_open')
1595       glib_conf.set('USE_LIBICONV_GNU', true)
1596       libiconv = [cc.find_library('iconv')]
1597       found_iconv = true
1598     endif
1599   elif iconv_opt == 'native'
1600     if cc.has_header_symbol('iconv.h', 'iconv_open')
1601       glib_conf.set('USE_LIBICONV_NATIVE', true)
1602       libiconv = [cc.find_library('iconv')]
1603       found_iconv = true
1604     endif
1605   endif
1607   if not found_iconv
1608     error('iconv implementation "@0@" not found'.format(iconv_opt))
1609   endif
1611 endif
1613 if get_option('internal_pcre')
1614   pcre = []
1615   use_system_pcre = false
1616 else
1617   pcre = dependency('libpcre', required : false) # Should check for Unicode support, too. FIXME
1618   if not pcre.found()
1619     if cc.get_id() == 'msvc'
1620     # MSVC: Search for the PCRE library by the configuration, which corresponds
1621     # to the output of CMake builds of PCRE.  Note that debugoptimized
1622     # is really a Release build with .PDB files.
1623       if buildtype == 'debug'
1624         pcre = cc.find_library('pcred', required : false)
1625       else
1626         pcre = cc.find_library('pcre', required : false)
1627       endif
1628     endif
1629   endif
1630   use_system_pcre = pcre.found()
1631 endif
1632 glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
1634 use_pcre_static_flag = false
1636 if host_system == 'windows'
1637   if not use_system_pcre
1638     use_pcre_static_flag = true
1639   else
1640     pcre_static = cc.links('''#define PCRE_STATIC
1641                               #include <pcre.h>
1642                               int main() {
1643                                 void *p = NULL;
1644                                 pcre_free(p);
1645                                 return 0;
1646                               }''',
1647                            dependencies: pcre,
1648                            name : 'Windows system PCRE is a static build')
1649     if pcre_static
1650       use_pcre_static_flag = true
1651     endif
1652   endif
1653 endif
1655 libm = cc.find_library('m', required : false)
1656 libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
1657 if cc.get_id() != 'msvc'
1658   libz_dep = dependency('zlib', fallback : ['zlib', 'zlib_dep'])
1659 else
1660   # MSVC: Don't use the bundled ZLib sources until we are sure that we can't
1661   # find the ZLib .lib
1662   libz_dep = dependency('zlib', required : false)
1664   # MSVC: Search for the ZLib .lib, which corresponds to the results of
1665   # of using ZLib's win32/makefile.msc.
1666   if not libz_dep.found()
1667     libz_dep = cc.find_library('zlib1', required : false)
1668     if not libz_dep.found()
1669       libz_dep = cc.find_library('zlib', required : false)
1670       if not libz_dep.found()
1671         libz_dep = subproject('zlib').get_variable('zlib_dep')
1672       endif
1673     endif
1674   endif
1675 endif
1677 # First check in libc, fallback to libintl, and as last chance build
1678 # proxy-libintl subproject.
1679 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
1680 # implementations. This could be extended if issues are found in some platforms.
1681 if cc.has_function('ngettext')
1682   libintl = []
1683 else
1684   libintl = cc.find_library('intl', required : false)
1685   if not libintl.found()
1686     libintl = subproject('proxy-libintl').get_variable('intl_dep')
1687   endif
1688 endif
1690 # We require gettext to always be present
1691 glib_conf.set('HAVE_DCGETTEXT', 1)
1692 glib_conf.set('HAVE_GETTEXT', 1)
1694 glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
1695 # xgettext is optional (on Windows for instance)
1696 xgettext = find_program('xgettext', required : false)
1698 # libmount is only used by gio, but we need to fetch the libs to generate the
1699 # pkg-config file below
1700 libmount_dep = []
1701 if host_system == 'linux' and get_option('libmount')
1702   libmount_dep = [dependency('mount', version : '>=2.23', required : true)]
1703   glib_conf.set('HAVE_LIBMOUNT', 1)
1704 endif
1706 if host_system == 'windows'
1707   winsock2 = cc.find_library('ws2_32')
1708 endif
1710 selinux_dep = []
1711 if host_system == 'linux' and get_option('selinux')
1712   selinux_dep = [dependency('libselinux')]
1713   glib_conf.set('HAVE_SELINUX', 1)
1714 endif
1716 xattr_dep = []
1717 if host_system != 'windows' and get_option('xattr')
1718   # either glibc or libattr can provide xattr support
1719   # for both of them, we check for getxattr being in
1720   # the library and a valid xattr header.
1722   # try glibc
1723   if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
1724     glib_conf.set('HAVE_SYS_XATTR_H', 1)
1725     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
1726   #failure. try libattr
1727   elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
1728     glib_conf.set('HAVE_ATTR_XATTR_H', 1)
1729     glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
1730     xattr_dep = [cc.find_library('xattr')]
1731   else
1732     error('No getxattr implementation found in C library or libxattr')
1733   endif
1735   glib_conf.set('HAVE_XATTR', 1)
1736   if cc.compiles(glib_conf_prefix + '''
1737                  #include <stdio.h>
1738                  #ifdef HAVE_SYS_TYPES_H
1739                  #include <sys/types.h>
1740                  #endif
1741                  #ifdef HAVE_SYS_XATTR_H
1742                  #include <sys/xattr.h>
1743                  #elif HAVE_ATTR_XATTR_H
1744                  #include <attr/xattr.h>
1745                  #endif
1747                  int main (void) {
1748                    ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
1749                    return len;
1750                  }''',
1751                  name : 'XATTR_NOFOLLOW')
1752     glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
1753   endif
1754 endif
1756 python = import('python3').find_python()
1758 # Determine which user environment-dependent files that we want to install
1759 have_bash = find_program('bash', required : false).found() # For completion scripts
1760 have_m4 = find_program('m4', required : false).found() # For m4 macros
1761 have_sh = find_program('sh', required : false).found() # For glib-gettextize
1763 # FIXME: defines in config.h that are not actually used anywhere
1764 # (we add them for now to minimise the diff)
1765 glib_conf.set('HAVE_DLFCN_H', 1)
1766 glib_conf.set('STDC_HEADERS', 1)
1767 # THREADS_NONE
1768 glib_conf.set('SIZEOF___INT64', 8)
1770 # FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
1771 if host_system == 'sunos'
1772   glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
1773   glib_conf.set('_XOPEN_SOURCE', 2)
1774   glib_conf.set('__EXTENSIONS__',1)
1775 endif
1777 # Sadly Meson does not expose this value:
1778 # https://github.com/mesonbuild/meson/pull/3460
1779 if host_system == 'windows'
1780   # Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
1781   # with no explanation. Do the same here for now but this could be revisited if
1782   # if causes issues.
1783   export_dynamic_ldflags = []
1784 elif host_system == 'cygwin'
1785   export_dynamic_ldflags = ['-Wl,--export-all-symbols']
1786 elif host_system == 'darwin'
1787   export_dynamic_ldflags = []
1788 else
1789   export_dynamic_ldflags = ['-Wl,--export-dynamic']
1790 endif
1792 win32_cflags = []
1793 win32_ldflags = []
1794 if host_system == 'windows' and cc.get_id() != 'msvc'
1795   # Ensure MSVC-compatible struct packing convention is used when
1796   # compiling for Win32 with gcc. It is used for the whole project and exposed
1797   # in glib-2.0.pc.
1798   win32_cflags = ['-mms-bitfields']
1799   add_project_arguments(win32_cflags, language : 'c')
1801   # Win32 API libs, used only by libglib and exposed in glib-2.0.pc
1802   win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi']
1803 elif host_system == 'cygwin'
1804   win32_ldflags = ['-luser32', '-lkernel32']
1805 endif
1807 # Tracing: dtrace
1808 want_dtrace = get_option('dtrace')
1809 enable_dtrace = false
1811 # Since dtrace support is opt-in we just error out if it was requested but
1812 # is not available. We don't bother with autodetection yet.
1813 if want_dtrace
1814   if glib_have_carbon
1815     error('GLib dtrace support not yet compatible with macOS dtrace')
1816   endif
1817   dtrace = find_program('dtrace', required : true) # error out if not found
1818   if not cc.has_header('sys/sdt.h')
1819     error('dtrace support needs sys/sdt.h header')
1820   endif
1821   # FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
1822   dtrace_obj_gen = generator(dtrace,
1823     output : '@BASENAME@.o',
1824     arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1825   # FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
1826   #               -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
1827   dtrace_hdr_gen = generator(dtrace,
1828     output : '@BASENAME@.h',
1829     arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
1830   glib_conf.set('HAVE_DTRACE', 1)
1831   enable_dtrace = true
1832 endif
1834 # systemtap
1835 want_systemtap = get_option('systemtap')
1836 enable_systemtap = false
1838 if want_systemtap and enable_dtrace
1839   tapset_install_dir = get_option('tapset_install_dir')
1840   if tapset_install_dir == ''
1841     tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
1842   endif
1843   stp_cdata = configuration_data()
1844   stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
1845   stp_cdata.set('LT_CURRENT', minor_version * 100)
1846   stp_cdata.set('LT_REVISION', micro_version)
1847   enable_systemtap = true
1848 endif
1851 pkg = import('pkgconfig')
1852 windows = import('windows')
1853 subdir('glib')
1854 subdir('gobject')
1855 subdir('gthread')
1856 subdir('gmodule')
1857 subdir('gio')
1858 if xgettext.found()
1859   subdir('po')
1860 endif
1861 subdir('tests')
1863 # Install glib-gettextize executable, if a UNIX-style shell is found
1864 if have_sh
1865   # These should not contain " quotes around the values
1866   gettexize_conf = configuration_data()
1867   gettexize_conf.set('PACKAGE', 'glib')
1868   gettexize_conf.set('VERSION', meson.project_version())
1869   gettexize_conf.set('prefix', glib_prefix)
1870   gettexize_conf.set('datarootdir', glib_datadir)
1871   gettexize_conf.set('datadir', glib_datadir)
1872   configure_file(input : 'glib-gettextize.in',
1873     install : true,
1874     install_dir : 'bin',
1875     output : 'glib-gettextize',
1876     configuration : gettexize_conf)
1877 endif
1879 if have_m4
1880   # Install m4 macros that other projects use
1881   install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
1882     install_dir : join_paths(get_option('datadir'), 'aclocal'))
1883 endif
1885 if host_system != 'windows'
1886   # Install Valgrind suppression file (except on Windows,
1887   # as Valgrind is currently not supported on Windows)
1888   install_data('glib.supp',
1889     install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
1890 endif
1892 configure_file(output : 'config.h', configuration : glib_conf)
1894 if host_system == 'windows'
1895   install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
1896 endif
1898 if get_option('man')
1899   xsltproc = find_program('xsltproc', required : true)
1900   xsltproc_command = [
1901     xsltproc,
1902     '--nonet',
1903     '--stringparam', 'man.output.quietly', '1',
1904     '--stringparam', 'funcsynopsis.style', 'ansi',
1905     '--stringparam', 'man.th.extra1.suppress', '1',
1906     '--stringparam', 'man.authors.section.enabled', '0',
1907     '--stringparam', 'man.copyright.section.enabled', '0',
1908     '-o', '@OUTPUT@',
1909     'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
1910     '@INPUT@',
1911   ]
1912   man1_dir = get_option('mandir') + '/man1'
1913 endif
1915 gnome = import('gnome')
1916 subdir('docs/reference/glib')
1917 subdir('docs/reference/gobject')
1918 subdir('docs/reference/gio')