webrtc/transportstream: add debug category
[platform/upstream/gstreamer.git] / meson.build
1 project('gstreamer-full', 'c',
2   version : '1.21.0.1',
3   meson_version : '>= 0.60.0',
4   default_options : ['buildtype=debugoptimized',
5                      # Needed due to https://github.com/mesonbuild/meson/issues/1889,
6                      # but this can cause problems in the future. Remove it
7                      # when it's no longer necessary.
8                      'cpp_std=c++14'])
9
10 gst_version = '>= @0@'.format(meson.project_version())
11
12 build_system = build_machine.system()
13 cc = meson.get_compiler('c')
14
15 fs = import('fs')
16 gnome = import('gnome')
17 pkgconfig = import('pkgconfig')
18 python3 = import('python').find_installation()
19 # Ensure that we're not being run from inside the development environment
20 # because that will confuse meson, and it might find the already-built
21 # gstreamer. It's fine if people run `ninja` as long as it doesn't run
22 # reconfigure because ninja doesn't care about the env.
23 ensure_not_devenv = '''
24 import os
25 assert('GST_ENV' not in os.environ)
26 '''
27 cmdres = run_command(python3, '-c', ensure_not_devenv, check: false)
28 if cmdres.returncode() != 0
29   error('Do not run `ninja reconfigure` or `meson` for gst-build inside the development environment, you will run into problems')
30 endif
31
32 # Install gst-indent pre-commit hook
33 run_command(python3, '-c', 'import shutil; shutil.copy("scripts/git-hooks/multi-pre-commit.hook", ".git/hooks/pre-commit")', check: false)
34
35 # Ensure that the user does not have Strawberry Perl in PATH, since it ships
36 # with a pkg-config.bat and broken pkgconfig files for libffi and zlib. Will
37 # cause a build error, such as in
38 # https://gitlab.freedesktop.org/gstreamer/gst-build/-/issues/41
39 ensure_no_strawberry_perl = '''
40 import os
41 assert(r'Strawberry\perl\bin' not in os.environ['PATH'])
42 '''
43 if build_system == 'windows' and meson.version().version_compare('<0.60.0')
44   cmdres = run_command(python3, '-c', ensure_no_strawberry_perl, check: false)
45   if cmdres.returncode() != 0
46     error('You have Strawberry Perl in PATH which is known to cause build issues with Meson < 0.60.0. Please remove it from PATH, uninstall it, or upgrade Meson.')
47   endif
48 endif
49
50 documented_projects = ''
51 # Make it possible to use msys2 built zlib which fails
52 # when not using the mingw toolchain as it uses unistd.h
53 if not meson.is_subproject() and cc.get_id() == 'msvc'
54   uname = find_program('uname', required: false)
55   if uname.found()
56     ret = run_command(uname, '-o', check: false)
57     if ret.returncode() == 0 and ret.stdout().to_lower() == 'msys'
58       ret = run_command(uname, '-r', check: false)
59       # The kernel version returned by uname is actually the msys version
60       if ret.returncode() == 0 and ret.stdout().startswith('2')
61         # If a system zlib is found, disable UNIX features in zlib.h and zconf.h
62         if cc.find_library('z').found()
63           add_global_arguments('-DZ_SOLO', language: 'c')
64         endif
65       endif
66     endif
67   endif
68 endif
69
70 # Ensure that MSVC interprets all source code as UTF-8. Only do this when we're
71 # not a subproject, because subprojects are not allowed to call
72 # add_global_arguments().
73 if not meson.is_subproject() and cc.get_id() == 'msvc'
74   add_global_arguments(
75       cc.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8
76       language: ['c', 'cpp'])
77 endif
78
79 # Ordered list of subprojects (dict has no ordering guarantees)
80 subprojects = [
81   ['gstreamer', {'build-hotdoc': true}],
82   ['gst-plugins-base', {'option': get_option('base'), 'build-hotdoc': true}],
83   ['gst-plugins-good', {'option': get_option('good'), 'build-hotdoc': true}],
84   ['libnice', { 'option': get_option('libnice'), 'match_gst_version': false}],
85   ['gst-plugins-bad', { 'option': get_option('bad'), 'build-hotdoc': true}],
86   ['gst-plugins-ugly', { 'option': get_option('ugly'), 'build-hotdoc': true}],
87   ['gst-libav', { 'option': get_option('libav'), 'build-hotdoc': true}],
88   ['gst-rtsp-server', { 'option': get_option('rtsp_server'), 'build-hotdoc': true}],
89   ['gst-devtools', { 'option': get_option('devtools'), 'build-hotdoc': true }],
90   ['gst-integration-testsuites', { 'option': get_option('devtools') }],
91   ['gst-editing-services', { 'option': get_option('ges'), 'build-hotdoc': true}],
92   ['gstreamer-vaapi', { 'option': get_option('vaapi'), 'build-hotdoc': true}],
93   ['gst-omx', { 'option': get_option('omx'), 'build-hotdoc': true}],
94   ['gstreamer-sharp', { 'option': get_option('sharp') }],
95   ['pygobject', { 'option': get_option('python'), 'match_gst_version': false, 'sysdep': 'pygobject-3.0', 'sysdep_version': '>= 3.8' }],
96   ['gst-python', { 'option': get_option('python')}],
97   ['gst-examples', { 'option': get_option('gst-examples'), 'match_gst_versions': false}],
98   ['gst-plugins-rs', { 'option': get_option('rs'), 'match_gst_version': false}],
99 ]
100
101 symlink = '''
102 import os
103
104 os.symlink(os.path.join('@1@', 'subprojects', '@0@'),
105   os.path.join('@1@', '@0@'))
106 '''
107
108 if build_system == 'windows'
109   subproject('win-flex-bison-binaries')
110   subproject('win-nasm')
111 elif build_system == 'darwin'
112   subproject('macos-bison-binary')
113 endif
114
115 orc_subproject = subproject('orc', required: get_option('orc'))
116
117 foreach custom_subproj: get_option('custom_subprojects').split(',')
118     if custom_subproj != ''
119         message ('Adding custom subproject ' + custom_subproj)
120         subprojects += [[custom_subproj, {'match_gst_version': false}]]
121     endif
122 endforeach
123
124
125 subprojects_names = []
126 plugins_doc_caches = []
127 orc_update_targets = []
128 all_plugins = []
129 # Using a list and not a dict to keep the ordering to build the chain of `gir`
130 # dependencies
131 all_libraries = []
132 foreach sp : subprojects
133   project_name = sp[0]
134   build_infos = sp[1]
135   is_required = build_infos.get('option', true)
136   sysdep = build_infos.get('sysdep', '')
137   sysdep_version = build_infos.get('sysdep_version', '')
138   match_gst_version = build_infos.get('match_gst_version', true)
139
140   if match_gst_version
141     subproj = subproject(project_name, version: gst_version, required: is_required)
142   elif sysdep != ''
143       sysdep_dep = dependency(sysdep, version: sysdep_version, required: false)
144       if not sysdep_dep.found()
145         subproj = subproject(project_name, required: is_required)
146       endif
147   else
148     subproj = subproject(project_name, required: is_required)
149   endif
150
151   if subproj.found()
152     plugins = subproj.get_variable('plugins', [])
153     all_plugins += plugins
154     all_libraries += subproj.get_variable('libraries', [])
155
156     orc_update_targets += subproj.get_variable('orc_update_targets', [])
157
158     subprojects_names += [project_name]
159
160     if not meson.is_cross_build() and build_infos.get('build-hotdoc', false)
161       if plugins.length() > 0
162         plugins_doc_caches += [subproj.get_variable('plugins_doc_dep', [])]
163       endif
164       if documented_projects != ''
165         documented_projects += ','
166       endif
167       documented_projects  += project_name
168     endif
169   endif
170 endforeach
171
172 # Check if we need to also build glib-networking for TLS modules
173 glib_dep = dependency('glib-2.0')
174 if glib_dep.type_name() == 'internal'
175   subproject('glib-networking', required : get_option('tls'),
176              default_options: ['gnutls=auto', 'openssl=auto'])
177 endif
178
179 plugins_doc_dep = custom_target('plugins-doc-cache',
180   command: [python3, '-c', 'print("Built all doc caches")'],
181   input: plugins_doc_caches,
182   output: 'plugins_doc_caches',
183   capture: true,
184 )
185
186 if meson.is_cross_build() or build_machine.system() == 'windows'
187     if get_option('doc').enabled()
188         error('Documentation enabled but building the doc while cross building or building on windows is not supported yet.')
189     endif
190
191     documented_projects = ''
192     message('Documentation not built as building the documentation while cross building or building on windows is not supported yet.')
193 else
194   hotdoc_p = find_program('hotdoc', required : get_option('doc'))
195   if not hotdoc_p.found()
196     documented_projects = ''
197     message('Not building documentation as hotdoc was not found')
198   endif
199 endif
200
201 write_file_contents = '''
202 import os
203 import sys
204
205 assert len(sys.argv) >= 3
206 fname = sys.argv[1]
207 contents = sys.argv[2]
208
209 with open(fname, 'w') as f:
210     f.write(contents)
211 '''
212
213 configure_file(
214   output : 'GstDocumentedSubprojects',
215   command : [python3,
216              '-c', write_file_contents,
217              '@OUTPUT@',
218              documented_projects]
219 )
220
221 if documented_projects != ''
222   subproject('gst-docs', required: get_option('doc').enabled())
223   message('Gst docs subprojects: ' + documented_projects)
224 endif
225
226 all_plugins_paths = []
227 all_plugins_dirs = []
228 foreach plugin: all_plugins
229   all_plugins_paths += plugin.full_path()
230   all_plugins_dirs += fs.parent(plugin.full_path())
231 endforeach
232 # Work around meson bug: https://github.com/mesonbuild/meson/pull/6770
233 pathsep = host_machine.system() == 'windows' ? ';' : ':'
234 all_plugins_paths = pathsep.join(all_plugins_paths)
235
236 devenv = environment()
237 devenv.prepend('GST_PLUGIN_PATH', all_plugins_dirs)
238 devenv.set('CURRENT_GST', meson.current_source_dir())
239 devenv.set('GST_VERSION', meson.project_version())
240 devenv.set('GST_ENV', 'gst-' + meson.project_version())
241 devenv.set('GST_REGISTRY', meson.current_build_dir() / 'registry.dat')
242 devenv.set('GST_PLUGIN_SYSTEM_PATH', '')
243 meson.add_devenv(devenv)
244
245 generate_plugins_paths = find_program('scripts/generate_plugins_path.py')
246 configure_file(
247   output : 'GstPluginsPath.json',
248   command : [generate_plugins_paths,
249              '@OUTPUT@',
250              all_plugins_paths]
251 )
252
253 if get_option('default_library') == 'static'
254   # Generate a .c file which declare and register all built plugins
255   plugins_names = []
256   foreach plugin: all_plugins
257     plugins_names += plugin.full_path()
258   endforeach
259   all_plugin_names = ';'.join(plugins_names)
260
261   static_plugins = get_option('gst-full-plugins')
262   if static_plugins == '*'
263     static_plugins = all_plugin_names
264   endif
265   generate_init_static_plugins = find_program('scripts/generate_init_static_plugins.py')
266   init_static_plugins_c = configure_file(
267     output: 'gstinitstaticplugins.c',
268     command : [generate_init_static_plugins,
269                '-o ' + '@OUTPUT@',
270                '-p ' + static_plugins,
271                '-e ' + get_option('gst-full-elements'),
272                '-t ' + get_option('gst-full-typefind-functions'),
273                '-d ' + get_option('gst-full-device-providers'),
274                '-T ' + get_option('gst-full-dynamic-types')
275                ]
276   )
277
278   gstfull_link_args = cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions'])
279
280   # Get a list of libraries that needs to be exposed in the ABI.
281   exposed_libs = []
282   exposed_girs = []
283   incdir_deps = []
284   wanted_libs = ['gstreamer-1.0'] + get_option('gst-full-libraries')
285   all_libs = '*' in wanted_libs
286
287   foreach pkgname_library : all_libraries
288     pkg_name = pkgname_library[0]
289     lib_def = pkgname_library[1]
290
291     if pkg_name in wanted_libs or all_libs
292       if lib_def.has_key('lib')
293         incdir_deps += dependency(pkg_name).partial_dependency(includes: true, sources: true)
294         exposed_libs += [lib_def['lib']]
295       endif
296
297       if lib_def.has_key('gir')
298         exposed_girs += lib_def['gir']
299       endif
300     endif
301   endforeach
302
303   # glib and gobject are part of our public API. If we are using glib from the
304   # system then our pkg-config file must require it. If we built it as
305   # subproject then we need to link_whole it.
306   glib_deps = []
307   glib_dep = dependency('glib-2.0')
308   gobject_dep = dependency('gobject-2.0')
309   if gobject_dep.type_name() == 'internal'
310     glib_subproject = subproject('glib')
311     exposed_libs += glib_subproject.get_variable('libglib')
312     exposed_libs += glib_subproject.get_variable('libgobject')
313     incdir_deps += [
314       glib_dep.partial_dependency(includes: true),
315       gobject_dep.partial_dependency(includes: true),
316     ]
317   else
318     glib_deps = [glib_dep, gobject_dep]
319   endif
320
321   link_deps = []
322   if get_option('gst-full-version-script') != ''
323     symbol_map = meson.current_source_dir() / get_option('gst-full-version-script')
324     link_arg = '-Wl,--version-script=' + symbol_map
325     if cc.has_link_argument(link_arg)
326       gstfull_link_args += link_arg
327       link_deps += symbol_map
328     elif cc.get_id() == 'msvc'
329       warning('FIXME: Provide a def file to publish the public symbols')
330     else
331       warning('FIXME: Linker does not support the supplied version script (' + symbol_map + '), please disable the "gst-full-version-script" option')
332     endif
333   endif
334
335   # Build both shared and static library
336   gstfull = both_libraries('gstreamer-full-1.0',
337     init_static_plugins_c,
338     link_with : all_plugins,
339     link_args: gstfull_link_args,
340     link_whole : exposed_libs,
341     dependencies : incdir_deps + glib_deps,
342     link_depends : link_deps,
343     install : true,
344   )
345
346   gst_full_dep = declare_dependency(link_with: gstfull.get_shared_lib(),
347     dependencies : incdir_deps + glib_deps,
348     include_directories: include_directories('.')
349   )
350
351   gst_full_libs_private = cc.get_supported_link_arguments(['-Wl,--undefined=gst_init_static_plugins'])
352   if gst_full_libs_private == []
353     warning('The compiler does not support `-Wl,--undefined` linker flag. The method `gst_init_static_plugins` might be dropped during the link stage of an application using libgstreamer-full-1.0.a, preventing plugins registration.')
354   endif
355
356   if not get_option('introspection').disabled()
357     built_girs = {}
358     foreach gir: exposed_girs
359       includes = []
360       foreach include: gir.get('includes', [])
361         includes += [built_girs.get(include, include)]
362       endforeach
363
364       gir += {
365         'includes': includes,
366         'extra_args': gir.get('extra_args', []) + ['--add-include-path=' + meson.current_build_dir()],
367         'install': true,
368       }
369       built_girs += {gir.get('namespace') + '-' + gir.get('nsversion'): gnome.generate_gir(gstfull, kwargs: gir)[0]}
370     endforeach
371   endif
372
373   pkgconfig.generate(gstfull,
374     requires: glib_deps,
375     libraries_private: gst_full_libs_private,
376     subdirs : 'gstreamer-1.0')
377   meson.override_dependency('gstreamer-full-1.0', gst_full_dep)
378 endif
379
380 message('Building subprojects: ' + ', '.join(subprojects_names))
381
382 setenv = find_program('gst-env.py')
383
384 devenv_cmd = [setenv, '--builddir=@0@'.format(meson.global_build_root()),
385               '--srcdir=@0@'.format(meson.global_source_root())]
386
387 subdir('tests')
388 if meson.can_run_host_binaries() and build_machine.system() == 'linux' and host_machine.system() == 'windows'
389   # FIXME: Ideally we could get the wrapper directly from meson
390   devenv_cmd += ['--wine', host_machine.cpu_family() == 'x86_64' ? 'wine64' : 'wine32']
391   sysroot = meson.get_cross_property('sys_root')
392   if sysroot != ''
393     # Logic from meson
394     devenv_cmd += ['--winepath', 'Z:' + join_paths(sysroot, 'bin')]
395   endif
396 endif
397
398 run_target('devenv', command : devenv_cmd)
399
400 if orc_subproject.found() and orc_update_targets.length() > 0
401   alias_target('update-orc-dist', orc_update_targets)
402 endif
403
404 summary({
405   'gstreamer-full': get_option('default_library') == 'static',
406 }, section: 'Build options', bool_yn: true, list_sep: '  ')