Merge branch 'upstream' into tizen
[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   'gvariant-vectors.c',
314   'gvarianttypeinfo.c',
315   'gvarianttype.c',
316   'gversion.c',
317   'gwakeup.c',
318   'gprintf.c',
319 )
320
321 if host_system == 'windows'
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   glib_sources += files('gwin32.c', 'gspawn-win32.c', 'giowin32.c')
330   platform_deps = [winsock2, cc.find_library('winmm')]
331   if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
332     glib_sources += files('dirent/wdirent.c')
333   endif
334 else
335   glib_sources += files('glib-unix.c', 'gspawn.c', 'giounix.c')
336   platform_deps = []
337 endif
338
339 if glib_have_cocoa
340   glib_sources += files('gosxutils.m')
341 endif
342
343 glib_sources += files('gthread-@0@.c'.format(threads_implementation))
344
345 if enable_dtrace
346   glib_dtrace_obj = dtrace_obj_gen.process('glib_probes.d')
347   glib_dtrace_hdr = dtrace_hdr_gen.process('glib_probes.d')
348 else
349   glib_dtrace_obj = []
350   glib_dtrace_hdr = []
351 endif
352
353 pcre_static_args = []
354
355 if use_pcre_static_flag
356   pcre_static_args = ['-DPCRE_STATIC']
357 endif
358
359 glib_c_args = ['-DG_LOG_DOMAIN="GLib"', '-DGLIB_COMPILATION'] + pcre_static_args + glib_hidden_visibility_args
360 libglib = library('glib-2.0',
361   glib_dtrace_obj, glib_dtrace_hdr,
362   sources : [deprecated_sources, glib_sources],
363   objects : [charset_lib.extract_all_objects()] + gnulib_objects,
364   version : library_version,
365   soversion : soversion,
366   darwin_versions : darwin_versions,
367   install : true,
368   # intl.lib is not compatible with SAFESEH
369   link_args : [noseh_link_args, glib_link_flags, win32_ldflags],
370   include_directories : configinc,
371   dependencies : [pcre, thread_dep, librt] + libintl_deps + libiconv + platform_deps + [gnulib_libm_dependency, libm] + [libsysprof_capture_dep],
372   c_args : glib_c_args,
373   objc_args : glib_c_args,
374 )
375
376 libglib_dep = declare_dependency(
377   link_with : libglib,
378   dependencies : libintl_deps,
379   # We sadly need to export configinc here because everyone includes <glib/*.h>
380   include_directories : [configinc, glibinc])
381
382 pkg.generate(libglib,
383   libraries : [libintl_deps],
384   libraries_private : [osx_ldflags, win32_ldflags],
385   subdirs : ['glib-2.0'],
386   extra_cflags : ['-I${libdir}/glib-2.0/include'] + win32_cflags,
387   variables : ['bindir=' + join_paths('${prefix}', get_option('bindir')),
388                'glib_genmarshal=' + join_paths('${bindir}', 'glib-genmarshal'),
389                'gobject_query=' + join_paths('${bindir}', 'gobject-query'),
390                'glib_mkenums=' + join_paths('${bindir}', 'glib-mkenums')],
391   version : glib_version,
392   install_dir : glib_pkgconfigreldir,
393   filebase : 'glib-2.0',
394   name : 'GLib',
395   description : 'C Utility Library',
396 )
397
398 if meson.version().version_compare('>=0.54.0')
399   meson.override_dependency('glib-2.0', libglib_dep)
400 endif
401
402 # On Windows, glib needs a spawn helper for g_spawn* API
403 if host_system == 'windows'
404   if host_machine.cpu_family() == 'x86'
405     executable('gspawn-win32-helper', 'gspawn-win32-helper.c',
406       install : true,
407       gui_app : true,
408       include_directories : configinc,
409       dependencies : [libglib_dep])
410     executable('gspawn-win32-helper-console', 'gspawn-win32-helper.c',
411       install : true,
412       c_args : ['-DHELPER_CONSOLE'],
413       include_directories : configinc,
414       dependencies : [libglib_dep])
415   else
416     executable('gspawn-win64-helper', 'gspawn-win32-helper.c',
417       install : true,
418       gui_app : true,
419       include_directories : configinc,
420       dependencies : [libglib_dep])
421     executable('gspawn-win64-helper-console', 'gspawn-win32-helper.c',
422       install : true,
423       c_args : ['-DHELPER_CONSOLE'],
424       include_directories : configinc,
425       dependencies : [libglib_dep])
426   endif
427 else
428   gtester = executable('gtester', 'gtester.c',
429     install : true,
430     c_args : ['-UG_DISABLE_ASSERT'],
431     include_directories : configinc,
432     dependencies : [libglib_dep])
433 endif
434
435 report_conf = configuration_data()
436 report_conf.set('GLIB_VERSION', glib_version)
437 report_conf.set('PYTHON', python_name)
438 configure_file(
439   input: 'gtester-report.in',
440   output: 'gtester-report',
441   install_dir: get_option('bindir'),
442   configuration: report_conf,
443   install_mode: 'rwxr-xr-x'
444 )
445
446 install_data('glib_gdb.py', install_dir : join_paths(glib_pkgdatadir, 'gdb'))
447
448 gdb_conf = configuration_data()
449 gdb_conf.set('datadir', glib_datadir)
450 # This is also used in gobject/meson.build
451 if host_system != 'windows'
452   # XXX: We add a leading './' because glib_libdir is an absolute path and we
453   # need it to be a relative path so that join_paths appends it to the end.
454   gdb_install_dir = join_paths(glib_datadir, 'gdb', 'auto-load', './' + glib_libdir)
455 else
456   # FIXME: Cannot install on Windows because the path will contain a drive
457   # letter and colons are not allowed in paths.
458   gdb_install_dir = false
459 endif
460 configure_file(
461   input: 'libglib-gdb.py.in',
462   output: 'libglib-2.0.so.@0@-gdb.py'.format(library_version),
463   configuration: gdb_conf,
464   install_dir: gdb_install_dir,
465 )
466
467 if enable_systemtap
468   glib_stp = configure_file(input : 'glib.stp.in',
469     output : '@0@.stp'.format(libglib.full_path().split('/').get(-1)),
470     configuration : stp_cdata,
471     install_dir : tapset_install_dir,
472   )
473 endif
474
475 if build_tests
476   subdir('tests')
477 endif