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