Release 1.19.1
[platform/upstream/gstreamer.git] / meson.build
1 project('All GStreamer modules', 'c',
2   version : '1.19.1',
3   meson_version : '>= 0.54.0',
4   default_options : ['buildtype=debugoptimized'])
5
6 gst_version = '>= @0@'.format(meson.project_version())
7 gst_branch = 'master'
8
9 build_system = build_machine.system()
10 cc = meson.get_compiler('c')
11
12 pkgconfig = import('pkgconfig')
13 python3 = import('python').find_installation()
14 # Ensure that we're not being run from inside the gst-uninstalled env
15 # because that will confuse meson, and it might find the already-built
16 # gstreamer. It's fine if people run `ninja` as long as it doesn't run
17 # reconfigure because ninja doesn't care about the env.
18 ensure_not_uninstalled = '''
19 import os
20 assert('GST_ENV' not in os.environ)
21 '''
22 cmdres = run_command(python3, '-c', ensure_not_uninstalled)
23 if cmdres.returncode() != 0
24   error('Do not run `ninja` or `meson` for gst-build inside the uninstalled environment, you will run into problems')
25 endif
26
27 # Ensure that the user does not have Strawberry Perl in PATH, since it ships
28 # with a pkg-config.bat and broken pkgconfig files for libffi and zlib. Will
29 # cause a build error, such as in
30 # https://gitlab.freedesktop.org/gstreamer/gst-build/-/issues/41
31 ensure_no_strawberry_perl = '''
32 import os
33 assert(r'Strawberry\perl\bin' not in os.environ['PATH'])
34 '''
35 if build_system == 'windows'
36   cmdres = run_command(python3, '-c', ensure_no_strawberry_perl)
37   if cmdres.returncode() != 0
38     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.')
39   endif
40 endif
41
42 documented_projects = ''
43 # Make it possible to use msys2 built zlib which fails
44 # when not using the mingw toolchain as it uses unistd.h
45 if not meson.is_subproject() and cc.get_id() == 'msvc'
46   uname = find_program('uname', required: false)
47   if uname.found()
48     ret = run_command(uname, '-o')
49     if ret.returncode() == 0 and ret.stdout().to_lower() == 'msys'
50       ret = run_command(uname, '-r')
51       # The kernel version returned by uname is actually the msys version
52       if ret.returncode() == 0 and ret.stdout().startswith('2')
53         # If a system zlib is found, disable UNIX features in zlib.h and zconf.h
54         if cc.find_library('z').found()
55           add_global_arguments('-DZ_SOLO', language: 'c')
56         endif
57       endif
58     endif
59   endif
60 endif
61
62 # Ensure that MSVC interprets all source code as UTF-8
63 if cc.get_id() == 'msvc'
64   add_global_arguments(
65       cc.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8
66       language: ['c', 'cpp'])
67 endif
68
69 # Ordered list of subprojects (dict has no ordering guarantees)
70 subprojects = [
71   ['gstreamer', {'build-hotdoc': true}],
72   ['gst-plugins-base', {'option': get_option('base'), 'build-hotdoc': true}],
73   ['gst-plugins-good', {'option': get_option('good'), 'build-hotdoc': true}],
74   ['libnice', { 'option': get_option('libnice'), 'match_gst_version': false}],
75   ['gst-plugins-bad', { 'option': get_option('bad'), 'build-hotdoc': true}],
76   ['gst-plugins-ugly', { 'option': get_option('ugly'), 'build-hotdoc': true}],
77   ['gst-libav', { 'option': get_option('libav'), 'build-hotdoc': true}],
78   ['gst-rtsp-server', { 'option': get_option('rtsp_server'), 'build-hotdoc': true}],
79   ['gst-devtools', { 'option': get_option('devtools'), 'build-hotdoc': true }],
80   ['gst-integration-testsuites', { 'option': get_option('devtools') }],
81   ['gst-editing-services', { 'option': get_option('ges'), 'build-hotdoc': true}],
82   ['gstreamer-vaapi', { 'option': get_option('vaapi'), 'build-hotdoc': true}],
83   ['gst-omx', { 'option': get_option('omx'), 'build-hotdoc': true}],
84   ['gstreamer-sharp', { 'option': get_option('sharp') }],
85   ['pygobject', { 'option': get_option('python'), 'match_gst_version': false }],
86   ['gst-python', { 'option': get_option('python')}],
87   ['gst-examples', { 'option': get_option('gst-examples'), 'match_gst_versions': false}],
88   ['gst-plugins-rs', { 'option': get_option('rs'), 'match_gst_version': false}],
89 ]
90
91 symlink = '''
92 import os
93
94 os.symlink(os.path.join('@1@', 'subprojects', '@0@'),
95   os.path.join('@1@', '@0@'))
96 '''
97
98 if build_system == 'windows'
99   subproject('win-flex-bison-binaries')
100   subproject('win-nasm')
101 endif
102
103 orc_subproject = subproject('orc', required: get_option('orc'))
104
105 subprojects_names = []
106 plugins_doc_caches = []
107 orc_update_targets = []
108 all_plugins = []
109 foreach sp : subprojects
110   project_name = sp[0]
111   build_infos = sp[1]
112   is_required = build_infos.get('option', true)
113   match_gst_version = build_infos.get('match_gst_version', true)
114
115   if match_gst_version
116     subproj = subproject(project_name, version: gst_version, required: is_required)
117   else
118     subproj = subproject(project_name, required: is_required)
119   endif
120
121   if subproj.found()
122     plugins = subproj.get_variable('plugins', [])
123     all_plugins += plugins
124
125     orc_update_targets += subproj.get_variable('orc_update_targets', [])
126
127     subprojects_names += [project_name]
128     cmdres = run_command(python3, '-c', symlink.format(project_name, meson.current_source_dir()))
129     if cmdres.returncode() == 0
130       message('Created symlink to ' + project_name)
131     endif
132
133     if not meson.is_cross_build() and build_infos.get('build-hotdoc', false)
134       if plugins.length() > 0
135         plugins_doc_caches += [subproj.get_variable('plugins_doc_dep')]
136       endif
137       if documented_projects != ''
138         documented_projects += ','
139       endif
140       documented_projects  += project_name
141     endif
142   endif
143 endforeach
144
145 # Check if we need to also build glib-networking for TLS modules
146 glib_dep = dependency('glib-2.0')
147 if glib_dep.type_name() == 'internal'
148   subproject('glib-networking', required : get_option('tls'),
149              default_options: ['gnutls=auto', 'openssl=auto'])
150 endif
151
152 plugins_doc_dep = custom_target('plugins-doc-cache',
153   command: [python3, '-c', 'print("Built all doc caches")'],
154   input: plugins_doc_caches,
155   output: 'plugins_doc_caches',
156   capture: true,
157 )
158
159 if meson.is_cross_build() or build_machine.system() == 'windows'
160     if get_option('doc').enabled()
161         error('Documentation enabled but building the doc while cross building or building on windows is not supported yet.')
162     endif
163
164     documented_projects = ''
165     message('Documentation not built as building the documentation while cross building or building on windows is not supported yet.')
166 else
167   hotdoc_p = find_program('hotdoc', required : get_option('doc'))
168   if not hotdoc_p.found()
169     documented_projects = ''
170     message('Not building documentation as hotdoc was not found')
171   endif
172 endif
173
174 write_file_contents = '''
175 import os
176 import sys
177
178 assert len(sys.argv) >= 3
179 fname = sys.argv[1]
180 contents = sys.argv[2]
181
182 with open(fname, 'w') as f:
183     f.write(contents)
184 '''
185
186 configure_file(
187   output : 'GstDocumentedSubprojects',
188   command : [python3,
189              '-c', write_file_contents,
190              '@OUTPUT@',
191              documented_projects]
192 )
193
194 if documented_projects != ''
195   subproject('gst-docs', required: get_option('doc').enabled())
196   message('Gst docs subprojects: ' + documented_projects)
197 endif
198
199 all_plugins_paths = []
200 foreach plugin: all_plugins
201   all_plugins_paths += plugin.full_path()
202 endforeach
203 # Work around meson bug: https://github.com/mesonbuild/meson/pull/6770
204 pathsep = host_machine.system() == 'windows' ? ';' : ':'
205 all_plugins_paths = pathsep.join(all_plugins_paths)
206
207 generate_plugins_paths = find_program('scripts/generate_plugins_path.py')
208 configure_file(
209   output : 'GstPluginsPath.json',
210   command : [generate_plugins_paths,
211              '@OUTPUT@',
212              all_plugins_paths]
213 )
214
215 # FIXME: Create a 'libraries' list in each subproject like we do for 'plugins'
216 libraries_map = {
217   # name: [subproject_name, variable_name]
218   'gstreamer': ['gstreamer', 'libgst'],
219   'base': ['gstreamer', 'gst_base'],
220   'check': ['gstreamer', 'gst_check'],
221   'controller': ['gstreamer', 'gst_controller'],
222   'net': ['gstreamer', 'gst_net'],
223
224   'allocators': ['gst-plugins-base', 'gstallocators'],
225   'app': ['gst-plugins-base', 'gstapp'],
226   'audio': ['gst-plugins-base', 'gstaudio'],
227   'fft': ['gst-plugins-base', 'gstfft'],
228   'pbutils': ['gst-plugins-base', 'pbutils'],
229   'riff': ['gst-plugins-base', 'gstriff'],
230   'rtp': ['gst-plugins-base', 'gst_rtp'],
231   'rtsp': ['gst-plugins-base', 'gst_rtsp'],
232   'sdp': ['gst-plugins-base', 'gstsdp'],
233   'tag': ['gst-plugins-base', 'gsttag'],
234   'video': ['gst-plugins-base', 'gstvideo'],
235   'gl': ['gst-plugins-base', 'gstgl'],
236
237   'bad-audio': ['gst-plugins-bad', 'gstbadaudio'],
238   'bad-transcoder': ['gst-plugins-bad', 'gst_transcoder'],
239   'codecparsers': ['gst-plugins-bad', 'gstcodecparsers'],
240   'insertbin': ['gst-plugins-bad', 'gstinsertbin'],
241   'mpegts': ['gst-plugins-bad', 'gstmpegts'],
242   'player': ['gst-plugins-bad', 'gstplayer'],
243   'sctp': ['gst-plugins-bad', 'libgstsctp'],
244   'webrtc': ['gst-plugins-bad', 'gstwebrtc'],
245   'vulkan': ['gst-plugins-bad', 'gstvulkan'],
246
247   'rtsp-server': ['gst-rtsp-server', 'gst_rtsp_server'],
248 }
249
250 if get_option('default_library') == 'static'
251   if not get_option('introspection').disabled()
252     error('GObject Introspection is not supported in static builds. Please use -Dintrospection=disabled')
253   endif
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   incdir_deps = []
283   foreach name : get_option('gst-full-libraries') + ['gstreamer']
284     info = libraries_map[name]
285     exposed_libs += subproject(info[0]).get_variable(info[1])
286     depname = name == 'gstreamer' ? 'gstreamer-1.0' : 'gstreamer-@0@-1.0'.format(name)
287     incdir_deps += dependency(depname).partial_dependency(includes: true, sources: true)
288   endforeach
289
290   # glib and gobject are part of our public API. If we are using glib from the
291   # system then our pkg-config file must require it. If we built it as
292   # subproject then we need to link_whole it.
293   glib_deps = []
294   glib_dep = dependency('glib-2.0')
295   gobject_dep = dependency('gobject-2.0')
296   if gobject_dep.type_name() == 'internal'
297     glib_subproject = subproject('glib')
298     exposed_libs += glib_subproject.get_variable('libglib')
299     exposed_libs += glib_subproject.get_variable('libgobject')
300     incdir_deps += [
301       glib_dep.partial_dependency(includes: true),
302       gobject_dep.partial_dependency(includes: true),
303     ]
304   else
305     glib_deps = [glib_dep, gobject_dep]
306   endif
307
308   link_deps = []
309   if get_option('gst-full-version-script') != ''
310     symbol_map = meson.current_source_dir() / get_option('gst-full-version-script')
311     link_arg = '-Wl,--version-script=' + symbol_map
312     if cc.has_link_argument(link_arg)
313       gstfull_link_args += link_arg
314       link_deps += symbol_map
315     elif cc.get_id() == 'msvc'
316       warning('FIXME: Provide a def file to publish the public symbols')
317     else
318       error('Failed to link with version script (' + symbol_map + '), check logs for details')
319     endif
320   endif
321
322   # Build both shared and static library
323   gstfull = both_libraries('gstreamer-full-1.0',
324     init_static_plugins_c,
325     link_with : all_plugins,
326     link_args: gstfull_link_args,
327     link_whole : exposed_libs,
328     dependencies : incdir_deps + glib_deps,
329     link_depends : link_deps,
330     install : true,
331   )
332
333   gst_full_dep = declare_dependency(link_with: gstfull.get_shared_lib(),
334     dependencies : incdir_deps + glib_deps,
335     include_directories: include_directories('.')
336   )
337   gst_full_libs_private = cc.get_supported_link_arguments(['-Wl,--undefined=gst_init_static_plugins'])
338   if gst_full_libs_private == []
339     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.')
340   endif
341   pkgconfig.generate(gstfull,
342     requires: glib_deps,
343     libraries_private: gst_full_libs_private,
344     subdirs : 'gstreamer-1.0')
345   meson.override_dependency('gstreamer-full-1.0', gst_full_dep)
346 endif
347
348 foreach custom_subproj: get_option('custom_subprojects').split(',')
349     if custom_subproj != ''
350         message ('Adding custom subproject ' + custom_subproj)
351         subproject(custom_subproj)
352         subprojects_names += [custom_subproj]
353     endif
354 endforeach
355
356 message('Building subprojects: ' + ', '.join(subprojects_names))
357
358 subdir('tests')
359
360 setenv = find_program('gst-env.py')
361
362 devenv_cmd = [setenv, '--builddir=@0@'.format(meson.build_root()),
363               '--srcdir=@0@'.format(meson.source_root())]
364
365 if meson.has_exe_wrapper() and build_machine.system() == 'linux' and host_machine.system() == 'windows'
366   # FIXME: Ideally we could get the wrapper directly from meson
367   devenv_cmd += ['--wine', host_machine.cpu_family() == 'x86_64' ? 'wine64' : 'wine32']
368   sysroot = meson.get_cross_property('sys_root')
369   if sysroot != ''
370     # Logic from meson
371     devenv_cmd += ['--winepath', 'Z:' + join_paths(sysroot, 'bin')]
372   endif
373 endif
374
375 run_target('uninstalled', command : devenv_cmd)
376 run_target('devenv', command : devenv_cmd)
377
378 update = find_program('git-update')
379 run_target('git-update', command : [update])
380 run_target('update', command : [update,
381     '--builddir=@0@'.format(meson.current_build_dir())])
382
383 if orc_subproject.found() and orc_update_targets.length() > 0
384   alias_target('update-orc-dist', orc_update_targets)
385 endif