Imported Upstream version 2.66.6
[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',
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   'gtestutils.h',
202   'gstring.h',
203   'gstringchunk.h',
204   'gthread.h',
205   'gthreadpool.h',
206   'gtimer.h',
207   'gtimezone.h',
208   'gtrashstack.h',
209   'gtree.h',
210   'gtypes.h',
211   'guuid.h',
212   'gunicode.h',
213   'guri.h',
214   'gutils.h',
215   'gvarianttype.h',
216   'gvariant.h',
217   'gversion.h',
218   'gversionmacros.h',
219   'gwin32.h',
220   'gprintf.h',
221 )
222 install_headers(glib_sub_headers, subdir : 'glib-2.0/glib')
223
224 deprecated_sources = files(
225   'deprecated/gallocator.c',
226   'deprecated/gcache.c',
227   'deprecated/gcompletion.c',
228   'deprecated/grel.c',
229   'deprecated/gthread-deprecated.c'
230 )
231
232 glib_sources = files(
233   'garcbox.c',
234   'garray.c',
235   'gasyncqueue.c',
236   'gatomic.c',
237   'gbacktrace.c',
238   'gbase64.c',
239   'gbitlock.c',
240   'gbookmarkfile.c',
241   'gbytes.c',
242   'gcharset.c',
243   'gchecksum.c',
244   'gconvert.c',
245   'gdataset.c',
246   'gdate.c',
247   'gdatetime.c',
248   'gdir.c',
249   'genviron.c',
250   'gerror.c',
251   'gfileutils.c',
252   'ggettext.c',
253   'ghash.c',
254   'ghmac.c',
255   'ghook.c',
256   'ghostutils.c',
257   'giochannel.c',
258   'gkeyfile.c',
259   'glib-init.c',
260   'glib-private.c',
261   'glist.c',
262   'gmain.c',
263   'gmappedfile.c',
264   'gmarkup.c',
265   'gmem.c',
266   'gmessages.c',
267   'gnode.c',
268   'goption.c',
269   'gpattern.c',
270   'gpoll.c',
271   'gprimes.c',
272   'gqsort.c',
273   'gquark.c',
274   'gqueue.c',
275   'grand.c',
276   'grcbox.c',
277   'grefcount.c',
278   'grefstring.c',
279   'gregex.c',
280   'gscanner.c',
281   'gsequence.c',
282   'gshell.c',
283   'gslice.c',
284   'gslist.c',
285   'gstdio.c',
286   'gstrfuncs.c',
287   'gstrfuncsprivate.h',
288   'gstring.c',
289   'gstringchunk.c',
290   'gtestutils.c',
291   'gthread.c',
292   'gthreadpool.c',
293   'gtimer.c',
294   'gtimezone.c',
295   'gtrace.c',
296   'gtrace-private.h',
297   'gtranslit.c',
298   'gtrashstack.c',
299   'gtree.c',
300   'guniprop.c',
301   'gutf8.c',
302   'gunibreak.c',
303   'gunicollate.c',
304   'gunidecomp.c',
305   'guri.c',
306   'guriprivate.h',
307   'gutils.c',
308   'gutilsprivate.h',
309   'guuid.c',
310   'gvariant.c',
311   'gvariant-core.c',
312   'gvariant-parser.c',
313   'gvariant-serialiser.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 if use_system_pcre
360   pcre_deps = [pcre]
361   pcre_objects = []
362 else
363   pcre_deps = []
364   pcre_objects = [libpcre.extract_all_objects()]
365 endif
366
367 glib_c_args = ['-DG_LOG_DOMAIN="GLib"', '-DGLIB_COMPILATION'] + pcre_static_args + glib_hidden_visibility_args
368 libglib = library('glib-2.0',
369   glib_dtrace_obj, glib_dtrace_hdr,
370   sources : [deprecated_sources, glib_sources],
371   objects : [charset_lib.extract_all_objects()] + gnulib_objects + pcre_objects,
372   version : library_version,
373   soversion : soversion,
374   darwin_versions : darwin_versions,
375   install : true,
376   # intl.lib is not compatible with SAFESEH
377   link_args : [noseh_link_args, glib_link_flags, win32_ldflags],
378   include_directories : configinc,
379   dependencies : pcre_deps + [thread_dep, librt] + libintl_deps + libiconv + platform_deps + gnulib_libm_dependency + [libsysprof_capture_dep],
380   c_args : glib_c_args,
381   objc_args : glib_c_args,
382 )
383
384 libglib_dep = declare_dependency(
385   link_with : libglib,
386   dependencies : libintl_deps,
387   # We sadly need to export configinc here because everyone includes <glib/*.h>
388   include_directories : [configinc, glibinc])
389
390 pkg.generate(libglib,
391   libraries : [libintl_deps],
392   libraries_private : [osx_ldflags, win32_ldflags],
393   subdirs : ['glib-2.0'],
394   extra_cflags : ['-I${libdir}/glib-2.0/include'] + win32_cflags,
395   variables : ['bindir=' + join_paths('${prefix}', get_option('bindir')),
396                'glib_genmarshal=' + join_paths('${bindir}', 'glib-genmarshal'),
397                'gobject_query=' + join_paths('${bindir}', 'gobject-query'),
398                'glib_mkenums=' + join_paths('${bindir}', 'glib-mkenums')],
399   version : glib_version,
400   install_dir : glib_pkgconfigreldir,
401   filebase : 'glib-2.0',
402   name : 'GLib',
403   description : 'C Utility Library',
404 )
405
406 if meson.version().version_compare('>=0.54.0')
407   meson.override_dependency('glib-2.0', libglib_dep)
408 endif
409
410 # On Windows, glib needs a spawn helper for g_spawn* API
411 if host_system == 'windows'
412   if host_machine.cpu_family() == 'x86'
413     executable('gspawn-win32-helper', 'gspawn-win32-helper.c',
414       install : true,
415       gui_app : true,
416       include_directories : configinc,
417       dependencies : [libglib_dep])
418     executable('gspawn-win32-helper-console', 'gspawn-win32-helper.c',
419       install : true,
420       c_args : ['-DHELPER_CONSOLE'],
421       include_directories : configinc,
422       dependencies : [libglib_dep])
423   else
424     executable('gspawn-win64-helper', 'gspawn-win32-helper.c',
425       install : true,
426       gui_app : true,
427       include_directories : configinc,
428       dependencies : [libglib_dep])
429     executable('gspawn-win64-helper-console', 'gspawn-win32-helper.c',
430       install : true,
431       c_args : ['-DHELPER_CONSOLE'],
432       include_directories : configinc,
433       dependencies : [libglib_dep])
434   endif
435 else
436   gtester = executable('gtester', 'gtester.c',
437     install : true,
438     c_args : ['-UG_DISABLE_ASSERT'],
439     include_directories : configinc,
440     dependencies : [libglib_dep])
441 endif
442
443 report_conf = configuration_data()
444 report_conf.set('GLIB_VERSION', glib_version)
445 report_conf.set('PYTHON', python_name)
446 configure_file(
447   input: 'gtester-report.in',
448   output: 'gtester-report',
449   install_dir: get_option('bindir'),
450   configuration: report_conf,
451   install_mode: 'rwxr-xr-x'
452 )
453
454 install_data('glib_gdb.py', install_dir : join_paths(glib_pkgdatadir, 'gdb'))
455
456 gdb_conf = configuration_data()
457 gdb_conf.set('datadir', glib_datadir)
458 # This is also used in gobject/meson.build
459 if host_system != 'windows'
460   # XXX: We add a leading './' because glib_libdir is an absolute path and we
461   # need it to be a relative path so that join_paths appends it to the end.
462   gdb_install_dir = join_paths(glib_datadir, 'gdb', 'auto-load', './' + glib_libdir)
463 else
464   # FIXME: Cannot install on Windows because the path will contain a drive
465   # letter and colons are not allowed in paths.
466   gdb_install_dir = false
467 endif
468 configure_file(
469   input: 'libglib-gdb.py.in',
470   output: 'libglib-2.0.so.@0@-gdb.py'.format(library_version),
471   configuration: gdb_conf,
472   install_dir: gdb_install_dir,
473 )
474
475 if enable_systemtap
476   glib_stp = configure_file(input : 'glib.stp.in',
477     output : '@0@.stp'.format(libglib.full_path().split('/').get(-1)),
478     configuration : stp_cdata,
479     install_dir : tapset_install_dir,
480   )
481 endif
482
483 if build_tests
484   subdir('tests')
485 endif