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