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