• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1configure_file(input : 'glibconfig.h.in', output : 'glibconfig.h',
2  install_dir : join_paths(get_option('libdir'), 'glib-2.0/include'),
3  configuration : glibconfig_conf)
4
5subdir('libcharset')
6if not use_system_pcre
7  subdir('pcre')
8endif
9
10# libsysprof-capture support
11libsysprof_capture_dep = dependency('sysprof-capture-4', version: '>= 3.38.0',
12  required: get_option('sysprof'),
13  default_options: [
14    'enable_examples=false',
15    'enable_gtk=false',
16    'enable_tests=false',
17    'enable_tools=false',
18    'libsysprof=false',
19    'with_sysprofd=none',
20    'help=false',
21  ],
22  fallback: ['sysprof', 'libsysprof_capture_dep'],
23)
24glib_conf.set('HAVE_SYSPROF', libsysprof_capture_dep.found())
25
26# TODO: gnulib_objects, pcre_objects and pcre_deps are a workaround for
27# <https://github.com/mesonbuild/meson/issues/3934> and
28# <https://github.com/mesonbuild/meson/issues/3937>. When we can depend
29# on a meson version where those are fixed, revert the commit that
30# introduced this workaround.
31if use_system_printf
32  gnulib_lib = []
33  gnulib_objects = []
34  gnulib_libm_dependency = []
35  glib_conf.set ('gl_unused', '')
36  glib_conf.set ('gl_extern_inline', '')
37else
38  subdir ('gnulib/gl_extern_inline')
39  subdir ('gnulib/gl_cv_long_double_equals_double')
40  subdir ('gnulib/gl_cv_cc_double_expbit0')
41  subdir ('gnulib/gl_cv_func_printf_precision')
42  subdir ('gnulib/gl_cv_func_printf_enomem')
43  subdir ('gnulib/gl_cv_func_printf_flag_zero')
44  subdir ('gnulib/gl_cv_func_printf_flag_leftadjust')
45  subdir ('gnulib/gl_cv_func_printf_flag_grouping')
46  subdir ('gnulib/gl_cv_func_printf_directive_a')
47  subdir ('gnulib/gl_cv_func_printf_directive_f')
48  subdir ('gnulib/gl_cv_func_printf_directive_ls')
49  subdir ('gnulib/gl_cv_func_printf_long_double')
50  subdir ('gnulib/gl_cv_func_printf_infinite')
51  subdir ('gnulib/gl_cv_func_printf_infinite_long_double')
52
53  gl_unused = '''
54/* Define as a marker that can be attached to declarations that might not
55    be used.  This helps to reduce warnings, such as from
56    GCC -Wunused-parameter.  */
57#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
58# define _GL_UNUSED __attribute__ ((__unused__))
59#else
60# define _GL_UNUSED
61#endif
62'''
63  glib_conf.set ('gl_unused', gl_unused)
64  glib_conf.set ('gl_extern_inline', gl_extern_inline)
65
66  if (gl_cv_long_double_equals_double)
67    glib_conf.set ('HAVE_SAME_LONG_DOUBLE_AS_DOUBLE', 1)
68  endif
69
70  if (gl_cv_cc_double_expbit0_word >= 0 and
71      gl_cv_cc_double_expbit0_bit >= 0)
72    glib_conf.set('DBL_EXPBIT0_WORD', gl_cv_cc_double_expbit0_word)
73    glib_conf.set('DBL_EXPBIT0_BIT', gl_cv_cc_double_expbit0_bit)
74  endif
75
76  if not gl_cv_func_printf_precision
77    glib_conf.set('NEED_PRINTF_UNBOUNDED_PRECISION', 1)
78  endif
79
80  if not gl_cv_func_printf_enomem
81    glib_conf.set('NEED_PRINTF_ENOMEM', 1)
82  endif
83
84  if not gl_cv_func_printf_flag_leftadjust
85    glib_conf.set('NEED_PRINTF_FLAG_LEFTADJUST', 1)
86  endif
87
88  if not gl_cv_func_printf_flag_zero
89    glib_conf.set('NEED_PRINTF_FLAG_ZERO', 1)
90  endif
91
92  if not gl_cv_func_printf_flag_grouping
93    glib_conf.set('NEED_PRINTF_FLAG_GROUPING', 1)
94  endif
95
96  if not gl_cv_func_printf_directive_a
97    glib_conf.set('NEED_PRINTF_DIRECTIVE_A', 1)
98  endif
99
100  if not gl_cv_func_printf_directive_f
101    glib_conf.set('NEED_PRINTF_DIRECTIVE_F', 1)
102  endif
103
104  if not gl_cv_func_printf_directive_ls
105    glib_conf.set('NEED_PRINTF_DIRECTIVE_LS', 1)
106  endif
107
108  if (not gl_cv_func_printf_precision or
109      not gl_cv_func_printf_enomem)
110    glib_conf.set('NEED_PRINTF_DOUBLE', 1)
111    glib_conf.set('NEED_PRINTF_LONG_DOUBLE', 1)
112  endif
113
114  if not gl_cv_func_printf_infinite
115    glib_conf.set('NEED_PRINTF_INFINITE_DOUBLE', 1)
116  endif
117
118  if gl_cv_func_printf_long_double and gl_cv_func_printf_infinite_long_double
119    glib_conf.set('NEED_PRINTF_INFINITE_LONG_DOUBLE', 1)
120  endif
121
122  subdir('gnulib')
123  gnulib_objects = [gnulib_lib.extract_all_objects()]
124endif
125
126glib_headers = files(
127  'glib.h',
128  'glib-unix.h',
129  'glib-object.h',
130)
131install_headers(glib_headers, subdir : 'glib-2.0')
132
133glib_deprecated_headers = files(
134  'deprecated/gallocator.h',
135  'deprecated/gcache.h',
136  'deprecated/gcompletion.h',
137  'deprecated/gmain.h',
138  'deprecated/grel.h',
139  'deprecated/gthread.h',
140)
141install_headers(glib_deprecated_headers, subdir : 'glib-2.0/glib/deprecated')
142
143glib_sub_headers = files(
144  'glib-autocleanups.h',
145  'galloca.h',
146  'garray.h',
147  'gasyncqueue.h',
148  'gatomic.h',
149  'gbacktrace.h',
150  'gbase64.h',
151  'gbitlock.h',
152  'gbookmarkfile.h',
153  'gbytes.h',
154  'gcharset.h',
155  'gchecksum.h',
156  'gconvert.h',
157  'gdataset.h',
158  'gdate.h',
159  'gdatetime.h',
160  'gdir.h',
161  'genviron.h',
162  'gerror.h',
163  'gfileutils.h',
164  'ggettext.h',
165  'ghash.h',
166  'ghmac.h',
167  'ghook.h',
168  'ghostutils.h',
169  'gi18n.h',
170  'gi18n-lib.h',
171  'giochannel.h',
172  'gkeyfile.h',
173  'glist.h',
174  'gmacros.h',
175  'gmain.h',
176  'gmappedfile.h',
177  'gmarkup.h',
178  'gmem.h',
179  'gmessages.h',
180  'gnode.h',
181  'goption.h',
182  'gpattern.h',
183  'gpoll.h',
184  'gprimes.h',
185  'gqsort.h',
186  'gquark.h',
187  'gqueue.h',
188  'grand.h',
189  'grcbox.h',
190  'grefcount.h',
191  'grefstring.h',
192  'gregex.h',
193  'gscanner.h',
194  'gsequence.h',
195  'gshell.h',
196  'gslice.h',
197  'gslist.h',
198  'gspawn.h',
199  'gstdio.h',
200  'gstrfuncs.h',
201  'gstrvbuilder.h',
202  'gtestutils.h',
203  'gstring.h',
204  'gstringchunk.h',
205  'gthread.h',
206  'gthreadpool.h',
207  'gtimer.h',
208  'gtimezone.h',
209  'gtrashstack.h',
210  'gtree.h',
211  'gtypes.h',
212  'guuid.h',
213  'gunicode.h',
214  'guri.h',
215  'gutils.h',
216  'gvarianttype.h',
217  'gvariant.h',
218  'gversion.h',
219  'gversionmacros.h',
220  'gwin32.h',
221  'gprintf.h',
222)
223install_headers(glib_sub_headers, subdir : 'glib-2.0/glib')
224
225deprecated_sources = files(
226  'deprecated/gallocator.c',
227  'deprecated/gcache.c',
228  'deprecated/gcompletion.c',
229  'deprecated/grel.c',
230  'deprecated/gthread-deprecated.c'
231)
232
233glib_sources = files(
234  'garcbox.c',
235  'garray.c',
236  'gasyncqueue.c',
237  'gatomic.c',
238  'gbacktrace.c',
239  'gbase64.c',
240  'gbitlock.c',
241  'gbookmarkfile.c',
242  'gbytes.c',
243  'gcharset.c',
244  'gchecksum.c',
245  'gconvert.c',
246  'gdataset.c',
247  'gdate.c',
248  'gdatetime.c',
249  'gdir.c',
250  'genviron.c',
251  'gerror.c',
252  'gfileutils.c',
253  'ggettext.c',
254  'ghash.c',
255  'ghmac.c',
256  'ghook.c',
257  'ghostutils.c',
258  'giochannel.c',
259  'gkeyfile.c',
260  'glib-init.c',
261  'glib-private.c',
262  'glist.c',
263  'gmain.c',
264  'gmappedfile.c',
265  'gmarkup.c',
266  'gmem.c',
267  'gmessages.c',
268  'gnode.c',
269  'goption.c',
270  'gpattern.c',
271  'gpoll.c',
272  'gprimes.c',
273  'gqsort.c',
274  'gquark.c',
275  'gqueue.c',
276  'grand.c',
277  'grcbox.c',
278  'grefcount.c',
279  'grefstring.c',
280  'gregex.c',
281  'gscanner.c',
282  'gsequence.c',
283  'gshell.c',
284  'gslice.c',
285  'gslist.c',
286  'gstdio.c',
287  'gstrfuncs.c',
288  'gstring.c',
289  'gstringchunk.c',
290  'gstrvbuilder.c',
291  'gtestutils.c',
292  'gthread.c',
293  'gthreadpool.c',
294  'gtimer.c',
295  'gtimezone.c',
296  'gtrace.c',
297  'gtrace-private.h',
298  'gtranslit.c',
299  'gtrashstack.c',
300  'gtree.c',
301  'guniprop.c',
302  'gutf8.c',
303  'gunibreak.c',
304  'gunicollate.c',
305  'gunidecomp.c',
306  'guri.c',
307  'guriprivate.h',
308  'gutils.c',
309  'gutilsprivate.h',
310  'guuid.c',
311  'gvariant.c',
312  'gvariant-core.c',
313  'gvariant-parser.c',
314  'gvariant-serialiser.c',
315  'gvarianttypeinfo.c',
316  'gvarianttype.c',
317  'gversion.c',
318  'gwakeup.c',
319  'gprintf.c',
320)
321
322if host_system == 'windows'
323  glib_win_rc = configure_file(
324    input: 'glib.rc.in',
325    output: 'glib.rc',
326    configuration: glibconfig_conf,
327  )
328  glib_win_res = windows.compile_resources(glib_win_rc)
329  glib_sources += [glib_win_res]
330  glib_sources += files('gwin32.c', 'gspawn-win32.c', 'giowin32.c')
331  platform_deps = [winsock2, cc.find_library('winmm')]
332  if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
333    glib_sources += files('dirent/wdirent.c')
334  endif
335else
336  glib_sources += files('glib-unix.c', 'gspawn.c', 'giounix.c')
337  platform_deps = []
338endif
339
340if glib_have_cocoa
341  glib_sources += files('gosxutils.m')
342endif
343
344glib_sources += files('gthread-@0@.c'.format(threads_implementation))
345
346if enable_dtrace
347  glib_dtrace_obj = dtrace_obj_gen.process('glib_probes.d')
348  glib_dtrace_hdr = dtrace_hdr_gen.process('glib_probes.d')
349else
350  glib_dtrace_obj = []
351  glib_dtrace_hdr = []
352endif
353
354if use_system_pcre
355  pcre_deps = [pcre2]
356  pcre_objects = []
357else
358  pcre_deps = []
359  pcre_objects = [libpcre.extract_all_objects()]
360endif
361
362glib_c_args = ['-DG_LOG_DOMAIN="GLib"', '-DGLIB_COMPILATION'] + glib_hidden_visibility_args
363libglib = library('glib-2.0',
364  glib_dtrace_obj, glib_dtrace_hdr,
365  sources : [deprecated_sources, glib_sources],
366  objects : [charset_lib.extract_all_objects()] + gnulib_objects + pcre_objects,
367  version : library_version,
368  soversion : soversion,
369  darwin_versions : darwin_versions,
370  install : true,
371  # intl.lib is not compatible with SAFESEH
372  link_args : [noseh_link_args, glib_link_flags, win32_ldflags],
373  include_directories : configinc,
374  dependencies : [pcre2, thread_dep, librt] + libintl_deps + libiconv + platform_deps + [gnulib_libm_dependency, libm] + [libsysprof_capture_dep],
375  c_args : glib_c_args,
376  objc_args : glib_c_args,
377)
378
379libglib_dep = declare_dependency(
380  link_with : libglib,
381  dependencies : libintl_deps,
382  # We sadly need to export configinc here because everyone includes <glib/*.h>
383  include_directories : [configinc, glibinc])
384
385pkg.generate(libglib,
386  libraries : [libintl_deps],
387  libraries_private : [osx_ldflags, win32_ldflags],
388  subdirs : ['glib-2.0'],
389  extra_cflags : ['-I${libdir}/glib-2.0/include'] + win32_cflags,
390  variables : ['bindir=' + join_paths('${prefix}', get_option('bindir')),
391               'glib_genmarshal=' + join_paths('${bindir}', 'glib-genmarshal'),
392               'gobject_query=' + join_paths('${bindir}', 'gobject-query'),
393               'glib_mkenums=' + join_paths('${bindir}', 'glib-mkenums')],
394  version : glib_version,
395  install_dir : glib_pkgconfigreldir,
396  filebase : 'glib-2.0',
397  name : 'GLib',
398  description : 'C Utility Library',
399)
400
401if meson.version().version_compare('>=0.54.0')
402  meson.override_dependency('glib-2.0', libglib_dep)
403endif
404
405# On Windows, glib needs a spawn helper for g_spawn* API
406if host_system == 'windows'
407  if host_machine.cpu_family() == 'x86'
408    executable('gspawn-win32-helper', 'gspawn-win32-helper.c',
409      install : true,
410      gui_app : true,
411      include_directories : configinc,
412      dependencies : [libglib_dep])
413    executable('gspawn-win32-helper-console', 'gspawn-win32-helper.c',
414      install : true,
415      c_args : ['-DHELPER_CONSOLE'],
416      include_directories : configinc,
417      dependencies : [libglib_dep])
418  else
419    executable('gspawn-win64-helper', 'gspawn-win32-helper.c',
420      install : true,
421      gui_app : true,
422      include_directories : configinc,
423      dependencies : [libglib_dep])
424    executable('gspawn-win64-helper-console', 'gspawn-win32-helper.c',
425      install : true,
426      c_args : ['-DHELPER_CONSOLE'],
427      include_directories : configinc,
428      dependencies : [libglib_dep])
429  endif
430else
431  gtester = executable('gtester', 'gtester.c',
432    install : true,
433    c_args : ['-UG_DISABLE_ASSERT'],
434    include_directories : configinc,
435    dependencies : [libglib_dep])
436endif
437
438report_conf = configuration_data()
439report_conf.set('GLIB_VERSION', glib_version)
440report_conf.set('PYTHON', python_name)
441configure_file(
442  input: 'gtester-report.in',
443  output: 'gtester-report',
444  install_dir: get_option('bindir'),
445  configuration: report_conf,
446  install_mode: 'rwxr-xr-x'
447)
448
449install_data('glib_gdb.py', install_dir : join_paths(glib_pkgdatadir, 'gdb'))
450
451gdb_conf = configuration_data()
452gdb_conf.set('datadir', glib_datadir)
453# This is also used in gobject/meson.build
454if host_system != 'windows'
455  # XXX: We add a leading './' because glib_libdir is an absolute path and we
456  # need it to be a relative path so that join_paths appends it to the end.
457  gdb_install_dir = join_paths(glib_datadir, 'gdb', 'auto-load', './' + glib_libdir)
458else
459  # FIXME: Cannot install on Windows because the path will contain a drive
460  # letter and colons are not allowed in paths.
461  gdb_install_dir = false
462endif
463configure_file(
464  input: 'libglib-gdb.py.in',
465  output: 'libglib-2.0.so.@0@-gdb.py'.format(library_version),
466  configuration: gdb_conf,
467  install_dir: gdb_install_dir,
468)
469
470if enable_systemtap
471  glib_stp = configure_file(input : 'glib.stp.in',
472    output : '@0@.stp'.format(libglib.full_path().split('/').get(-1)),
473    configuration : stp_cdata,
474    install_dir : tapset_install_dir,
475  )
476endif
477
478if build_tests
479  subdir('tests')
480endif
481