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