rtphdrext-clientaudiolevel: Rename RFC 6464 element
[platform/upstream/gstreamer.git] / meson.build
1 project('All GStreamer modules', 'c',
2   version : '1.19.2.1',
3   meson_version : '>= 0.59',
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 gst-uninstalled env
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_uninstalled = '''
24 import os
25 assert('GST_ENV' not in os.environ)
26 '''
27 cmdres = run_command(python3, '-c', ensure_not_uninstalled)
28 if cmdres.returncode() != 0
29   error('Do not run `ninja` or `meson` for gst-build inside the uninstalled 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")')
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'
44   cmdres = run_command(python3, '-c', ensure_no_strawberry_perl)
45   if cmdres.returncode() != 0
46     error('You have Strawberry Perl in PATH which is known to cause build issues with gst-build. Please remove it from PATH or uninstall it.')
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')
57     if ret.returncode() == 0 and ret.stdout().to_lower() == 'msys'
58       ret = run_command(uname, '-r')
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.38.1' }],
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 subprojects_names = []
118 plugins_doc_caches = []
119 orc_update_targets = []
120 all_plugins = []
121 # Using a list and not a dict to keep the ordering to build the chain of `gir`
122 # dependencies
123 all_libraries = []
124 foreach sp : subprojects
125   project_name = sp[0]
126   build_infos = sp[1]
127   is_required = build_infos.get('option', true)
128   sysdep = build_infos.get('sysdep', '')
129   sysdep_version = build_infos.get('sysdep_version', '')
130   match_gst_version = build_infos.get('match_gst_version', true)
131
132   if match_gst_version
133     subproj = subproject(project_name, version: gst_version, required: is_required)
134   elif sysdep != ''
135       sysdep_dep = dependency(sysdep, version: sysdep_version, required: false)
136       if not sysdep_dep.found()
137         subproj = subproject(project_name, required: is_required)
138       endif
139   else
140     subproj = subproject(project_name, required: is_required)
141   endif
142
143   if subproj.found()
144     plugins = subproj.get_variable('plugins', [])
145     all_plugins += plugins
146     all_libraries += subproj.get_variable('libraries', [])
147
148     orc_update_targets += subproj.get_variable('orc_update_targets', [])
149
150     subprojects_names += [project_name]
151     cmdres = run_command(python3, '-c', symlink.format(project_name, meson.current_source_dir()))
152     if cmdres.returncode() == 0
153       message('Created symlink to ' + project_name)
154     endif
155
156     if not meson.is_cross_build() and build_infos.get('build-hotdoc', false)
157       if plugins.length() > 0
158         plugins_doc_caches += [subproj.get_variable('plugins_doc_dep', [])]
159       endif
160       if documented_projects != ''
161         documented_projects += ','
162       endif
163       documented_projects  += project_name
164     endif
165   endif
166 endforeach
167
168 # Check if we need to also build glib-networking for TLS modules
169 glib_dep = dependency('glib-2.0')
170 if glib_dep.type_name() == 'internal'
171   subproject('glib-networking', required : get_option('tls'),
172              default_options: ['gnutls=auto', 'openssl=auto'])
173 endif
174
175 plugins_doc_dep = custom_target('plugins-doc-cache',
176   command: [python3, '-c', 'print("Built all doc caches")'],
177   input: plugins_doc_caches,
178   output: 'plugins_doc_caches',
179   capture: true,
180 )
181
182 if meson.is_cross_build() or build_machine.system() == 'windows'
183     if get_option('doc').enabled()
184         error('Documentation enabled but building the doc while cross building or building on windows is not supported yet.')
185     endif
186
187     documented_projects = ''
188     message('Documentation not built as building the documentation while cross building or building on windows is not supported yet.')
189 else
190   hotdoc_p = find_program('hotdoc', required : get_option('doc'))
191   if not hotdoc_p.found()
192     documented_projects = ''
193     message('Not building documentation as hotdoc was not found')
194   endif
195 endif
196
197 write_file_contents = '''
198 import os
199 import sys
200
201 assert len(sys.argv) >= 3
202 fname = sys.argv[1]
203 contents = sys.argv[2]
204
205 with open(fname, 'w') as f:
206     f.write(contents)
207 '''
208
209 configure_file(
210   output : 'GstDocumentedSubprojects',
211   command : [python3,
212              '-c', write_file_contents,
213              '@OUTPUT@',
214              documented_projects]
215 )
216
217 if documented_projects != ''
218   subproject('gst-docs', required: get_option('doc').enabled())
219   message('Gst docs subprojects: ' + documented_projects)
220 endif
221
222 all_plugins_paths = []
223 all_plugins_dirs = []
224 foreach plugin: all_plugins
225   all_plugins_paths += plugin.full_path()
226   all_plugins_dirs += fs.parent(plugin.full_path())
227 endforeach
228 # Work around meson bug: https://github.com/mesonbuild/meson/pull/6770
229 pathsep = host_machine.system() == 'windows' ? ';' : ':'
230 all_plugins_paths = pathsep.join(all_plugins_paths)
231
232 devenv = environment()
233 devenv.set('GST_PLUGIN_PATH', all_plugins_dirs)
234 devenv.set('CURRENT_GST', meson.current_source_dir())
235 devenv.set('GST_VERSION', meson.project_version())
236 devenv.set('GST_ENV', 'gst-' + meson.project_version())
237 devenv.set('GST_REGISTRY', meson.current_build_dir() / 'registry.dat')
238 devenv.set('GST_PLUGIN_SYSTEM_PATH', '')
239 meson.add_devenv(devenv)
240
241 generate_plugins_paths = find_program('scripts/generate_plugins_path.py')
242 configure_file(
243   output : 'GstPluginsPath.json',
244   command : [generate_plugins_paths,
245              '@OUTPUT@',
246              all_plugins_paths]
247 )
248
249 if get_option('default_library') == 'static'
250   # Generate a .c file which declare and register all built plugins
251   plugins_names = []
252   foreach plugin: all_plugins
253     plugins_names += plugin.full_path()
254   endforeach
255   all_plugin_names = ';'.join(plugins_names)
256
257   static_plugins = get_option('gst-full-plugins')
258   if static_plugins == '*'
259     static_plugins = all_plugin_names
260   endif
261   generate_init_static_plugins = find_program('scripts/generate_init_static_plugins.py')
262   init_static_plugins_c = configure_file(
263     output: 'gstinitstaticplugins.c',
264     command : [generate_init_static_plugins,
265                '-o ' + '@OUTPUT@',
266                '-p ' + static_plugins,
267                '-e ' + get_option('gst-full-elements'),
268                '-t ' + get_option('gst-full-typefind-functions'),
269                '-d ' + get_option('gst-full-device-providers'),
270                '-T ' + get_option('gst-full-dynamic-types')
271                ]
272   )
273
274   gstfull_link_args = cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions'])
275
276   # Get a list of libraries that needs to be exposed in the ABI.
277   exposed_libs = []
278   exposed_girs = []
279   incdir_deps = []
280   wanted_libs = ['gstreamer-1.0'] + get_option('gst-full-libraries')
281   all_libs = '*' in wanted_libs
282
283   foreach pkgname_library : all_libraries
284     pkg_name = pkgname_library[0]
285     lib_def = pkgname_library[1]
286
287     if pkg_name in wanted_libs or all_libs
288       if lib_def.has_key('lib')
289         incdir_deps += dependency(pkg_name).partial_dependency(includes: true, sources: true)
290         exposed_libs += [lib_def['lib']]
291       endif
292
293       if lib_def.has_key('gir')
294         exposed_girs += lib_def['gir']
295       endif
296     endif
297   endforeach
298
299   # glib and gobject are part of our public API. If we are using glib from the
300   # system then our pkg-config file must require it. If we built it as
301   # subproject then we need to link_whole it.
302   glib_deps = []
303   glib_dep = dependency('glib-2.0')
304   gobject_dep = dependency('gobject-2.0')
305   if gobject_dep.type_name() == 'internal'
306     glib_subproject = subproject('glib')
307     exposed_libs += glib_subproject.get_variable('libglib')
308     exposed_libs += glib_subproject.get_variable('libgobject')
309     incdir_deps += [
310       glib_dep.partial_dependency(includes: true),
311       gobject_dep.partial_dependency(includes: true),
312     ]
313   else
314     glib_deps = [glib_dep, gobject_dep]
315   endif
316
317   link_deps = []
318   if get_option('gst-full-version-script') != ''
319     symbol_map = meson.current_source_dir() / get_option('gst-full-version-script')
320     link_arg = '-Wl,--version-script=' + symbol_map
321     if cc.has_link_argument(link_arg)
322       gstfull_link_args += link_arg
323       link_deps += symbol_map
324     elif cc.get_id() == 'msvc'
325       warning('FIXME: Provide a def file to publish the public symbols')
326     else
327       error('Failed to link with version script (' + symbol_map + '), check logs for details')
328     endif
329   endif
330
331   # Build both shared and static library
332   gstfull = both_libraries('gstreamer-full-1.0',
333     init_static_plugins_c,
334     link_with : all_plugins,
335     link_args: gstfull_link_args,
336     link_whole : exposed_libs,
337     dependencies : incdir_deps + glib_deps,
338     link_depends : link_deps,
339     install : true,
340   )
341
342   gst_full_dep = declare_dependency(link_with: gstfull.get_shared_lib(),
343     dependencies : incdir_deps + glib_deps,
344     include_directories: include_directories('.')
345   )
346
347   gst_full_libs_private = cc.get_supported_link_arguments(['-Wl,--undefined=gst_init_static_plugins'])
348   if gst_full_libs_private == []
349     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.')
350   endif
351
352   if not get_option('introspection').disabled()
353     built_girs = {}
354     foreach gir: exposed_girs
355       includes = []
356       foreach include: gir.get('includes', [])
357         includes += [built_girs.get(include, include)]
358       endforeach
359
360       gir += {
361         'includes': includes,
362         'extra_args': gir.get('extra_args', []) + ['--add-include-path=' + meson.current_build_dir()],
363         'install': true,
364       }
365       built_girs += {gir.get('namespace') + '-' + gir.get('nsversion'): gnome.generate_gir(gstfull, kwargs: gir)[0]}
366     endforeach
367   endif
368
369   pkgconfig.generate(gstfull,
370     requires: glib_deps,
371     libraries_private: gst_full_libs_private,
372     subdirs : 'gstreamer-1.0')
373   meson.override_dependency('gstreamer-full-1.0', gst_full_dep)
374 endif
375
376 foreach custom_subproj: get_option('custom_subprojects').split(',')
377     if custom_subproj != ''
378         message ('Adding custom subproject ' + custom_subproj)
379         subproject(custom_subproj)
380         subprojects_names += [custom_subproj]
381     endif
382 endforeach
383
384 message('Building subprojects: ' + ', '.join(subprojects_names))
385
386 setenv = find_program('gst-env.py')
387 devenv_cmd = [setenv, '--builddir=@0@'.format(meson.build_root()),
388               '--gstbuilddir=@0@'.format(meson.current_build_dir()),
389               '--srcdir=@0@'.format(meson.source_root())]
390
391 subdir('tests')
392 if meson.has_exe_wrapper() and build_machine.system() == 'linux' and host_machine.system() == 'windows'
393   # FIXME: Ideally we could get the wrapper directly from meson
394   devenv_cmd += ['--wine', host_machine.cpu_family() == 'x86_64' ? 'wine64' : 'wine32']
395   sysroot = meson.get_cross_property('sys_root')
396   if sysroot != ''
397     # Logic from meson
398     devenv_cmd += ['--winepath', 'Z:' + join_paths(sysroot, 'bin')]
399   endif
400 endif
401
402 run_target('uninstalled', command : devenv_cmd)
403 run_target('devenv', command : devenv_cmd)
404
405 if orc_subproject.found() and orc_update_targets.length() > 0
406   alias_target('update-orc-dist', orc_update_targets)
407 endif
408
409 summary({
410   'gstreamer-full': get_option('default_library') == 'static',
411 }, section: 'Build options', bool_yn: true, list_sep: '  ')