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