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