summaryrefslogtreecommitdiff
path: root/glib/meson.build
blob: 898446e00421ce91550bffeaf162827d526a9eca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
glib_sources = []
glib_sub_includedir = glib_includedir / 'glib'

glibconfig_h = configure_file(input : 'glibconfig.h.in', output : 'glibconfig.h',
  install_dir : join_paths(get_option('libdir'), 'glib-2.0/include'),
  install_tag : 'devel',
  configuration : glibconfig_conf)
glib_sources += glibconfig_h

gversionmacros_h = custom_target(
  input: 'gversionmacros.h.in',
  output: 'gversionmacros.h',
  command: [gen_visibility_macros, meson.project_version(), 'versions-macros', '@INPUT@', '@OUTPUT@'],
  install: true,
  install_dir: glib_sub_includedir,
  # FIXME: Not needed with Meson >= 0.64.0
  install_tag: 'devel',
)

glib_visibility_h = custom_target(
  output: 'glib-visibility.h',
  command: [gen_visibility_macros, meson.project_version(), 'visibility-macros', 'GLIB', '@OUTPUT@'],
  install: true,
  install_dir: glib_sub_includedir,
  # FIXME: Not needed with Meson >= 0.64.0
  install_tag: 'devel',
)

glib_built_headers = [gversionmacros_h, glib_visibility_h]
glib_sources += glib_built_headers
glib_c_args_internal = [
  '-DGLIB_COMPILATION',
]

subdir('libcharset')

# libsysprof-capture support
libsysprof_capture_dep = dependency('sysprof-capture-4', version: '>= 3.38.0',
  required: get_option('sysprof'),
  default_options: [
    'examples=false',
    'gtk=false',
    'tests=false',
    'tools=false',
    'libsysprof=false',
    'sysprofd=none',
    'help=false',
  ],
  fallback: ['sysprof', 'libsysprof_capture_dep'],
)
glib_conf.set('HAVE_SYSPROF', libsysprof_capture_dep.found())

if use_system_printf
  gnulib_lib = []
  gnulib_libm_dependency = []
  glib_conf.set ('gl_unused', '')
  glib_conf.set ('gl_extern_inline', '')
else
  subdir ('gnulib/gl_extern_inline')
  subdir ('gnulib/gl_cv_long_double_equals_double')
  subdir ('gnulib/gl_cv_cc_double_expbit0')
  subdir ('gnulib/gl_cv_func_printf_precision')
  subdir ('gnulib/gl_cv_func_printf_enomem')
  subdir ('gnulib/gl_cv_func_printf_flag_zero')
  subdir ('gnulib/gl_cv_func_printf_flag_leftadjust')
  subdir ('gnulib/gl_cv_func_printf_flag_grouping')
  subdir ('gnulib/gl_cv_func_printf_directive_a')
  subdir ('gnulib/gl_cv_func_printf_directive_f')
  subdir ('gnulib/gl_cv_func_printf_directive_ls')
  subdir ('gnulib/gl_cv_func_printf_long_double')
  subdir ('gnulib/gl_cv_func_printf_infinite')
  subdir ('gnulib/gl_cv_func_printf_infinite_long_double')

  gl_unused = '''
/* Define as a marker that can be attached to declarations that might not
    be used.  This helps to reduce warnings, such as from
    GCC -Wunused-parameter.  */
#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
# define _GL_UNUSED __attribute__ ((__unused__))
#else
# define _GL_UNUSED
#endif
'''
  glib_conf.set ('gl_unused', gl_unused)
  glib_conf.set ('gl_extern_inline', gl_extern_inline)

  if (gl_cv_long_double_equals_double)
    glib_conf.set ('HAVE_SAME_LONG_DOUBLE_AS_DOUBLE', 1)
  endif

  if (gl_cv_cc_double_expbit0_word >= 0 and
      gl_cv_cc_double_expbit0_bit >= 0)
    glib_conf.set('DBL_EXPBIT0_WORD', gl_cv_cc_double_expbit0_word)
    glib_conf.set('DBL_EXPBIT0_BIT', gl_cv_cc_double_expbit0_bit)
  endif

  if not gl_cv_func_printf_precision
    glib_conf.set('NEED_PRINTF_UNBOUNDED_PRECISION', 1)
  endif

  if not gl_cv_func_printf_enomem
    glib_conf.set('NEED_PRINTF_ENOMEM', 1)
  endif

  if not gl_cv_func_printf_flag_leftadjust
    glib_conf.set('NEED_PRINTF_FLAG_LEFTADJUST', 1)
  endif

  if not gl_cv_func_printf_flag_zero
    glib_conf.set('NEED_PRINTF_FLAG_ZERO', 1)
  endif

  if not gl_cv_func_printf_flag_grouping
    glib_conf.set('NEED_PRINTF_FLAG_GROUPING', 1)
  endif

  if not gl_cv_func_printf_directive_a
    glib_conf.set('NEED_PRINTF_DIRECTIVE_A', 1)
  endif

  if not gl_cv_func_printf_directive_f
    glib_conf.set('NEED_PRINTF_DIRECTIVE_F', 1)
  endif

  if not gl_cv_func_printf_directive_ls
    glib_conf.set('NEED_PRINTF_DIRECTIVE_LS', 1)
  endif

  if (not gl_cv_func_printf_precision or
      not gl_cv_func_printf_enomem)
    glib_conf.set('NEED_PRINTF_DOUBLE', 1)
    glib_conf.set('NEED_PRINTF_LONG_DOUBLE', 1)
  endif

  if not gl_cv_func_printf_infinite
    glib_conf.set('NEED_PRINTF_INFINITE_DOUBLE', 1)
  endif

  if gl_cv_func_printf_long_double and gl_cv_func_printf_infinite_long_double
    glib_conf.set('NEED_PRINTF_INFINITE_LONG_DOUBLE', 1)
  endif

  subdir('gnulib')
endif

glib_headers = files(
  'glib.h',
  'glib-unix.h',
  'glib-object.h',
)
install_headers(glib_headers, install_dir : glib_includedir)

if host_system == 'windows'
  install_headers([ 'msvc_recommended_pragmas.h' ], install_dir : glib_includedir)
endif

# Expose as variable to be used by gobject-introspection
# when it includes GLib as a subproject
glib_unix_h = files('glib-unix.h')

glib_deprecated_headers = files(
  'deprecated/gallocator.h',
  'deprecated/gcache.h',
  'deprecated/gcompletion.h',
  'deprecated/gmain.h',
  'deprecated/grel.h',
  'deprecated/gthread.h',
)
install_headers(glib_deprecated_headers,
  install_dir : glib_sub_includedir / 'deprecated')

glib_sub_headers = files(
  'glib-autocleanups.h',
  'glib-typeof.h',
  'galloca.h',
  'garray.h',
  'gasyncqueue.h',
  'gatomic.h',
  'gbacktrace.h',
  'gbase64.h',
  'gbitlock.h',
  'gbookmarkfile.h',
  'gbytes.h',
  'gcharset.h',
  'gchecksum.h',
  'gconvert.h',
  'gdataset.h',
  'gdate.h',
  'gdatetime.h',
  'gdir.h',
  'genviron.h',
  'gerror.h',
  'gfileutils.h',
  'ggettext.h',
  'ghash.h',
  'ghmac.h',
  'ghook.h',
  'ghostutils.h',
  'gi18n.h',
  'gi18n-lib.h',
  'giochannel.h',
  'gkeyfile.h',
  'glist.h',
  'gmacros.h',
  'gmain.h',
  'gmappedfile.h',
  'gmarkup.h',
  'gmem.h',
  'gmessages.h',
  'gnode.h',
  'goption.h',
  'gpathbuf.h',
  'gpattern.h',
  'gpoll.h',
  'gprimes.h',
  'gqsort.h',
  'gquark.h',
  'gqueue.h',
  'grand.h',
  'grcbox.h',
  'grefcount.h',
  'grefstring.h',
  'gregex.h',
  'gscanner.h',
  'gsequence.h',
  'gshell.h',
  'gslice.h',
  'gslist.h',
  'gspawn.h',
  'gstdio.h',
  'gstrfuncs.h',
  'gstrvbuilder.h',
  'gtestutils.h',
  'gstring.h',
  'gstringchunk.h',
  'gthread.h',
  'gthreadpool.h',
  'gtimer.h',
  'gtimezone.h',
  'gtrashstack.h',
  'gtree.h',
  'gtypes.h',
  'guuid.h',
  'gunicode.h',
  'guri.h',
  'gutils.h',
  'gvarianttype.h',
  'gvariant.h',
  'gversion.h',
  'gwin32.h',
  'gprintf.h',
)

install_headers(glib_sub_headers, install_dir : glib_sub_includedir)

deprecated_sources = files(
  'deprecated/gallocator.c',
  'deprecated/gcache.c',
  'deprecated/gcompletion.c',
  'deprecated/grel.c',
  'deprecated/gthread-deprecated.c'
)

glib_sources += files(
  'garcbox.c',
  'garray.c',
  'gasyncqueue.c',
  'gatomic.c',
  'gbacktrace.c',
  'gbase64.c',
  'gbitlock.c',
  'gbookmarkfile.c',
  'gbytes.c',
  'gcharset.c',
  'gchecksum.c',
  'gconvert.c',
  'gdataset.c',
  'gdate.c',
  'gdatetime.c',
  'gdir.c',
  'genviron.c',
  'gerror.c',
  'gfileutils.c',
  'ggettext.c',
  'ghash.c',
  'ghmac.c',
  'ghook.c',
  'ghostutils.c',
  'giochannel.c',
  'gkeyfile.c',
  'glib-init.c',
  'glib-private.c',
  'glist.c',
  'gmain.c',
  'gmappedfile.c',
  'gmarkup.c',
  'gmem.c',
  'gmessages.c',
  'gnode.c',
  'goption.c',
  'gpathbuf.c',
  'gpattern.c',
  'gpoll.c',
  'gprimes.c',
  'gqsort.c',
  'gquark.c',
  'gqueue.c',
  'grand.c',
  'grcbox.c',
  'grefcount.c',
  'grefstring.c',
  'gregex.c',
  'gscanner.c',
  'gsequence.c',
  'gshell.c',
  'gslice.c',
  'gslist.c',
  'gstdio.c',
  'gstrfuncs.c',
  'gstring.c',
  'gstringchunk.c',
  'gstrvbuilder.c',
  'gtestutils.c',
  'gthread.c',
  'gthreadpool.c',
  'gtimer.c',
  'gtimezone.c',
  'gtrace.c',
  'gtrace-private.h',
  'gtranslit.c',
  'gtrashstack.c',
  'gtree.c',
  'guniprop.c',
  'gutf8.c',
  'gunibreak.c',
  'gunicollate.c',
  'gunidecomp.c',
  'guri.c',
  'guriprivate.h',
  'gutils.c',
  'gutilsprivate.h',
  'guuid.c',
  'gvariant.c',
  'gvariant-core.c',
  'gvariant-parser.c',
  'gvariant-serialiser.c',
  'gvarianttypeinfo.c',
  'gvarianttype.c',
  'gversion.c',
  'gwakeup.c',
  'gprintf.c',
)

platform_deps = []

if host_system == 'windows'
  if glib_build_shared
    glib_win_rc = configure_file(
      input: 'glib.rc.in',
      output: 'glib.rc',
      configuration: glibconfig_conf,
    )
    glib_win_res = windows.compile_resources(glib_win_rc)
    glib_sources += [glib_win_res]
  endif
  glib_sources += files('gwin32.c', 'gspawn-win32.c', 'giowin32.c')
  platform_deps = [winsock2, cc.find_library('winmm')]
  if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
    glib_sources += files('dirent/wdirent.c')
  endif
else
  glib_sources += files('glib-unix.c', 'glib-unixprivate.h', 'gspawn.c', 'giounix.c')
  platform_deps = []
endif

if host_system == 'linux'
  glib_sources += files('gjournal-private.c')
endif

if glib_have_cocoa
  glib_sources += files('gosxutils.m')
  framework_dep = dependency('appleframeworks', modules : ['Foundation', 'CoreFoundation', 'AppKit'])
  platform_deps += [framework_dep]
endif

if glib_have_carbon
  framework_dep = dependency('appleframeworks', modules : 'Carbon')
  platform_deps += [framework_dep]
endif

glib_sources += files('gthread-@0@.c'.format(threads_implementation))

if enable_dtrace
  glib_dtrace_obj = dtrace_obj_gen.process('glib_probes.d')
  glib_dtrace_hdr = dtrace_hdr_gen.process('glib_probes.d')
else
  glib_dtrace_obj = []
  glib_dtrace_hdr = []
endif

pcre2_static_args = []

if use_pcre2_static_flag
  pcre2_static_args = ['-DPCRE2_STATIC']
endif

glib_c_args = ['-DG_LOG_DOMAIN="GLib"'] + glib_c_args_internal + pcre2_static_args
libglib = library('glib-2.0',
  glib_dtrace_obj, glib_dtrace_hdr,
  sources : [deprecated_sources, glib_sources],
  version : library_version,
  soversion : soversion,
  darwin_versions : darwin_versions,
  install : true,
  # intl.lib is not compatible with SAFESEH
  link_args : [noseh_link_args, glib_link_flags, win32_ldflags],
  include_directories : configinc,
  link_with: [charset_lib, gnulib_lib],
  dependencies : [
    gnulib_libm_dependency,
    libiconv,
    libintl_deps,
    libm,
    librt,
    libsysprof_capture_dep,
    pcre2,
    platform_deps,
    thread_dep,
  ],
  c_args : glib_c_args,
  objc_args : glib_c_args,
  gnu_symbol_visibility : 'hidden',
)

libglib_dep = declare_dependency(
  link_with : libglib,
  dependencies : libintl_deps,
  sources : glib_built_headers,
  # We sadly need to export configinc here because everyone includes <glib/*.h>
  include_directories : [configinc, glibinc])

pkg.generate(libglib,
  libraries : [libintl_deps],
  libraries_private : [win32_ldflags],
  subdirs : ['glib-2.0'],
  extra_cflags : ['-I${libdir}/glib-2.0/include'] + win32_cflags,
  variables : [
    'bindir=' + '${prefix}' / get_option('bindir'),
    'datadir=' + '${prefix}' / get_option('datadir'),
    'glib_genmarshal=' + '${bindir}' / 'glib-genmarshal',
    'gobject_query=' + '${bindir}' / 'gobject-query',
    'glib_mkenums=' + '${bindir}' / 'glib-mkenums',
    'glib_valgrind_suppressions=' + '${datadir}' /
      valgrind_suppression_file_install_subdir /
      fs.name(valgrind_suppression_file),
  ],
  version : glib_version,
  install_dir : glib_pkgconfigreldir,
  filebase : 'glib-2.0',
  name : 'GLib',
  description : 'C Utility Library',
)
meson.override_dependency('glib-2.0', libglib_dep)

# On Windows, glib needs a spawn helper for g_spawn* API
if host_system == 'windows'
  if host_machine.cpu_family() == 'x86'
    executable('gspawn-win32-helper', 'gspawn-win32-helper.c',
      install : true,
      win_subsystem : 'windows',
      include_directories : configinc,
      dependencies : [libglib_dep])
    executable('gspawn-win32-helper-console', 'gspawn-win32-helper.c',
      install : true,
      c_args : ['-DHELPER_CONSOLE'],
      include_directories : configinc,
      dependencies : [libglib_dep])
  else
    executable('gspawn-win64-helper', 'gspawn-win32-helper.c',
      install : true,
      win_subsystem : 'windows',
      include_directories : configinc,
      dependencies : [libglib_dep])
    executable('gspawn-win64-helper-console', 'gspawn-win32-helper.c',
      install : true,
      c_args : ['-DHELPER_CONSOLE'],
      include_directories : configinc,
      dependencies : [libglib_dep])
  endif
else
  gtester = executable('gtester', 'gtester.c',
    install : true,
    install_tag : 'bin-devel',
    c_args : ['-UG_DISABLE_ASSERT'],
    include_directories : configinc,
    dependencies : [libglib_dep])
endif

report_conf = configuration_data()
report_conf.set('GLIB_VERSION', glib_version)
report_conf.set('PYTHON', python_name)
configure_file(
  input: 'gtester-report.in',
  output: 'gtester-report',
  install_dir: get_option('bindir'),
  install_tag : 'bin-devel',
  configuration: report_conf,
  install_mode: 'rwxr-xr-x'
)

install_data('glib_gdb.py',
  install_dir : glib_pkgdatadir / 'gdb',
  install_tag : 'devel',
)

# This is needed to make gdb find glib_gdb.py
env = environment()
env.prepend('PYTHONPATH', meson.current_source_dir())
meson.add_devenv(env)

gdb_conf = configuration_data()
gdb_conf.set('datadir', glib_datadir)
# This is also used in gobject/meson.build
if host_system != 'windows'
  gdb_install = true
else
  # FIXME: Cannot install on Windows because the path will contain a drive
  # letter and colons are not allowed in paths.
  gdb_install = false
endif

# XXX: We add a leading './' because glib_libdir is an absolute path and we
# need it to be a relative path so that join_paths appends it to the end.
gdb_install_dir = join_paths(glib_datadir, 'gdb', 'auto-load', './' + glib_libdir)

configure_file(
  input: 'libglib-gdb.py.in',
  output: 'libglib-2.0.so.@0@-gdb.py'.format(library_version),
  configuration: gdb_conf,
  install_dir: gdb_install_dir,
  install_tag: 'devel',
  install: gdb_install,
)

if enable_systemtap
  glib_stp = configure_file(input : 'glib.stp.in',
    output : '@0@.stp'.format(libglib.full_path().split('/').get(-1)),
    configuration : stp_cdata,
    install_dir : tapset_install_dir,
    install_tag : 'systemtap',
  )
endif

if build_tests
  subdir('tests')
endif