New subproject macos-bison-binary to provide bison on macOS
[platform/upstream/gstreamer.git] / meson.build
1 project('All GStreamer modules', 'c',
2   version : '1.19.1.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 # Ordered list of subprojects (dict has no ordering guarantees)
63 subprojects = [
64   ['gstreamer', {'build-hotdoc': true}],
65   ['gst-plugins-base', {'option': get_option('base'), 'build-hotdoc': true}],
66   ['gst-plugins-good', {'option': get_option('good'), 'build-hotdoc': true}],
67   ['libnice', { 'option': get_option('libnice'), 'match_gst_version': false}],
68   ['gst-plugins-bad', { 'option': get_option('bad'), 'build-hotdoc': true}],
69   ['gst-plugins-ugly', { 'option': get_option('ugly'), 'build-hotdoc': true}],
70   ['gst-libav', { 'option': get_option('libav'), 'build-hotdoc': true}],
71   ['gst-rtsp-server', { 'option': get_option('rtsp_server'), 'build-hotdoc': true}],
72   ['gst-devtools', { 'option': get_option('devtools'), 'build-hotdoc': true }],
73   ['gst-integration-testsuites', { 'option': get_option('devtools') }],
74   ['gst-editing-services', { 'option': get_option('ges'), 'build-hotdoc': true}],
75   ['gstreamer-vaapi', { 'option': get_option('vaapi'), 'build-hotdoc': true}],
76   ['gst-omx', { 'option': get_option('omx'), 'build-hotdoc': true}],
77   ['gstreamer-sharp', { 'option': get_option('sharp') }],
78   ['pygobject', { 'option': get_option('python'), 'match_gst_version': false }],
79   ['gst-python', { 'option': get_option('python')}],
80   ['gst-examples', { 'option': get_option('gst-examples'), 'match_gst_versions': false}],
81   ['gst-plugins-rs', { 'option': get_option('rs'), 'match_gst_version': false}],
82 ]
83
84 symlink = '''
85 import os
86
87 os.symlink(os.path.join('@1@', 'subprojects', '@0@'),
88   os.path.join('@1@', '@0@'))
89 '''
90
91 if build_system == 'windows'
92   subproject('win-flex-bison-binaries')
93   subproject('win-nasm')
94 elif build_system == 'darwin'
95   subproject('macos-bison-binary')
96 endif
97
98 orc_subproject = subproject('orc', required: get_option('orc'))
99
100 subprojects_names = []
101 plugins_doc_caches = []
102 orc_update_targets = []
103 all_plugins = []
104 foreach sp : subprojects
105   project_name = sp[0]
106   build_infos = sp[1]
107   is_required = build_infos.get('option', true)
108   match_gst_version = build_infos.get('match_gst_version', true)
109
110   if match_gst_version
111     subproj = subproject(project_name, version: gst_version, required: is_required)
112   else
113     subproj = subproject(project_name, required: is_required)
114   endif
115
116   if subproj.found()
117     plugins = subproj.get_variable('plugins', [])
118     all_plugins += plugins
119
120     orc_update_targets += subproj.get_variable('orc_update_targets', [])
121
122     subprojects_names += [project_name]
123     cmdres = run_command(python3, '-c', symlink.format(project_name, meson.current_source_dir()))
124     if cmdres.returncode() == 0
125       message('Created symlink to ' + project_name)
126     endif
127
128     if not meson.is_cross_build() and build_infos.get('build-hotdoc', false)
129       if plugins.length() > 0
130         plugins_doc_caches += [subproj.get_variable('plugins_doc_dep')]
131       endif
132       if documented_projects != ''
133         documented_projects += ','
134       endif
135       documented_projects  += project_name
136     endif
137   endif
138 endforeach
139
140 # Check if we need to also build glib-networking for TLS modules
141 glib_dep = dependency('glib-2.0')
142 if glib_dep.type_name() == 'internal'
143   subproject('glib-networking', required : get_option('tls'),
144              default_options: ['gnutls=auto', 'openssl=auto'])
145 endif
146
147 plugins_doc_dep = custom_target('plugins-doc-cache',
148   command: [python3, '-c', 'print("Built all doc caches")'],
149   input: plugins_doc_caches,
150   output: 'plugins_doc_caches',
151   capture: true,
152 )
153
154 if meson.is_cross_build() or build_machine.system() == 'windows'
155     if get_option('doc').enabled()
156         error('Documentation enabled but building the doc while cross building or building on windows is not supported yet.')
157     endif
158
159     documented_projects = ''
160     message('Documentation not built as building the documentation while cross building or building on windows is not supported yet.')
161 else
162   hotdoc_p = find_program('hotdoc', required : get_option('doc'))
163   if not hotdoc_p.found()
164     documented_projects = ''
165     message('Not building documentation as hotdoc was not found')
166   endif
167 endif
168
169 write_file_contents = '''
170 import os
171 import sys
172
173 assert len(sys.argv) >= 3
174 fname = sys.argv[1]
175 contents = sys.argv[2]
176
177 with open(fname, 'w') as f:
178     f.write(contents)
179 '''
180
181 configure_file(
182   output : 'GstDocumentedSubprojects',
183   command : [python3,
184              '-c', write_file_contents,
185              '@OUTPUT@',
186              documented_projects]
187 )
188
189 if documented_projects != ''
190   subproject('gst-docs', required: get_option('doc').enabled())
191   message('Gst docs subprojects: ' + documented_projects)
192 endif
193
194 all_plugins_paths = []
195 foreach plugin: all_plugins
196   all_plugins_paths += plugin.full_path()
197 endforeach
198 # Work around meson bug: https://github.com/mesonbuild/meson/pull/6770
199 pathsep = host_machine.system() == 'windows' ? ';' : ':'
200 all_plugins_paths = pathsep.join(all_plugins_paths)
201
202 generate_plugins_paths = find_program('scripts/generate_plugins_path.py')
203 configure_file(
204   output : 'GstPluginsPath.json',
205   command : [generate_plugins_paths,
206              '@OUTPUT@',
207              all_plugins_paths]
208 )
209
210 # FIXME: Create a 'libraries' list in each subproject like we do for 'plugins'
211 libraries_map = {
212   # name: [subproject_name, variable_name]
213   'gstreamer': ['gstreamer', 'libgst'],
214   'base': ['gstreamer', 'gst_base'],
215   'check': ['gstreamer', 'gst_check'],
216   'controller': ['gstreamer', 'gst_controller'],
217   'net': ['gstreamer', 'gst_net'],
218
219   'allocators': ['gst-plugins-base', 'gstallocators'],
220   'app': ['gst-plugins-base', 'gstapp'],
221   'audio': ['gst-plugins-base', 'gstaudio'],
222   'fft': ['gst-plugins-base', 'gstfft'],
223   'pbutils': ['gst-plugins-base', 'pbutils'],
224   'riff': ['gst-plugins-base', 'gstriff'],
225   'rtp': ['gst-plugins-base', 'gst_rtp'],
226   'rtsp': ['gst-plugins-base', 'gst_rtsp'],
227   'sdp': ['gst-plugins-base', 'gstsdp'],
228   'tag': ['gst-plugins-base', 'gsttag'],
229   'video': ['gst-plugins-base', 'gstvideo'],
230   'gl': ['gst-plugins-base', 'gstgl'],
231
232   'bad-audio': ['gst-plugins-bad', 'gstbadaudio'],
233   'bad-transcoder': ['gst-plugins-bad', 'gst_transcoder'],
234   'codecparsers': ['gst-plugins-bad', 'gstcodecparsers'],
235   'insertbin': ['gst-plugins-bad', 'gstinsertbin'],
236   'mpegts': ['gst-plugins-bad', 'gstmpegts'],
237   'player': ['gst-plugins-bad', 'gstplayer'],
238   'sctp': ['gst-plugins-bad', 'libgstsctp'],
239   'webrtc': ['gst-plugins-bad', 'gstwebrtc'],
240   'vulkan': ['gst-plugins-bad', 'gstvulkan'],
241
242   'rtsp-server': ['gst-rtsp-server', 'gst_rtsp_server'],
243 }
244
245 if get_option('default_library') == 'static'
246   if not get_option('introspection').disabled()
247     error('GObject Introspection is not supported in static builds. Please use -Dintrospection=disabled')
248   endif
249   # Generate a .c file which declare and register all built plugins
250   plugins_names = []
251   foreach plugin: all_plugins
252     plugins_names += plugin.full_path()
253   endforeach
254   all_plugin_names = ';'.join(plugins_names)
255
256   static_plugins = get_option('gst-full-plugins')
257   if static_plugins == '*'
258     static_plugins = all_plugin_names
259   endif
260   generate_init_static_plugins = find_program('scripts/generate_init_static_plugins.py')
261   init_static_plugins_c = configure_file(
262     output: 'gstinitstaticplugins.c',
263     command : [generate_init_static_plugins,
264                '-o ' + '@OUTPUT@',
265                '-p ' + static_plugins,
266                '-e ' + get_option('gst-full-elements'),
267                '-t ' + get_option('gst-full-typefind-functions'),
268                '-d ' + get_option('gst-full-device-providers'),
269                '-T ' + get_option('gst-full-dynamic-types')
270                ]
271   )
272
273   gstfull_link_args = cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions'])
274
275   # Get a list of libraries that needs to be exposed in the ABI.
276   exposed_libs = []
277   incdir_deps = []
278   foreach name : get_option('gst-full-libraries') + ['gstreamer']
279     info = libraries_map[name]
280     exposed_libs += subproject(info[0]).get_variable(info[1])
281     depname = name == 'gstreamer' ? 'gstreamer-1.0' : 'gstreamer-@0@-1.0'.format(name)
282     incdir_deps += dependency(depname).partial_dependency(includes: true, sources: true)
283   endforeach
284
285   # glib and gobject are part of our public API. If we are using glib from the
286   # system then our pkg-config file must require it. If we built it as
287   # subproject then we need to link_whole it.
288   glib_deps = []
289   glib_dep = dependency('glib-2.0')
290   gobject_dep = dependency('gobject-2.0')
291   if gobject_dep.type_name() == 'internal'
292     glib_subproject = subproject('glib')
293     exposed_libs += glib_subproject.get_variable('libglib')
294     exposed_libs += glib_subproject.get_variable('libgobject')
295     incdir_deps += [
296       glib_dep.partial_dependency(includes: true),
297       gobject_dep.partial_dependency(includes: true),
298     ]
299   else
300     glib_deps = [glib_dep, gobject_dep]
301   endif
302
303   link_deps = []
304   if get_option('gst-full-version-script') != ''
305     symbol_map = meson.current_source_dir() / get_option('gst-full-version-script')
306     link_arg = '-Wl,--version-script=' + symbol_map
307     if cc.has_link_argument(link_arg)
308       gstfull_link_args += link_arg
309       link_deps += symbol_map
310     elif cc.get_id() == 'msvc'
311       warning('FIXME: Provide a def file to publish the public symbols')
312     else
313       error('Failed to link with version script (' + symbol_map + '), check logs for details')
314     endif
315   endif
316
317   # Build both shared and static library
318   gstfull = both_libraries('gstreamer-full-1.0',
319     init_static_plugins_c,
320     link_with : all_plugins,
321     link_args: gstfull_link_args,
322     link_whole : exposed_libs,
323     dependencies : incdir_deps + glib_deps,
324     link_depends : link_deps,
325     install : true,
326   )
327
328   gst_full_dep = declare_dependency(link_with: gstfull.get_shared_lib(),
329     dependencies : incdir_deps + glib_deps,
330     include_directories: include_directories('.')
331   )
332   gst_full_libs_private = cc.get_supported_link_arguments(['-Wl,--undefined=gst_init_static_plugins'])
333   if gst_full_libs_private == []
334     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.')
335   endif
336   pkgconfig.generate(gstfull,
337     requires: glib_deps,
338     libraries_private: gst_full_libs_private,
339     subdirs : 'gstreamer-1.0')
340   meson.override_dependency('gstreamer-full-1.0', gst_full_dep)
341 endif
342
343 foreach custom_subproj: get_option('custom_subprojects').split(',')
344     if custom_subproj != ''
345         message ('Adding custom subproject ' + custom_subproj)
346         subproject(custom_subproj)
347         subprojects_names += [custom_subproj]
348     endif
349 endforeach
350
351 message('Building subprojects: ' + ', '.join(subprojects_names))
352
353 subdir('tests')
354
355 setenv = find_program('gst-env.py')
356
357 devenv_cmd = [setenv, '--builddir=@0@'.format(meson.build_root()),
358               '--gstbuilddir=@0@'.format(meson.current_build_dir()),
359               '--srcdir=@0@'.format(meson.source_root())]
360
361 if meson.has_exe_wrapper() and build_machine.system() == 'linux' and host_machine.system() == 'windows'
362   # FIXME: Ideally we could get the wrapper directly from meson
363   devenv_cmd += ['--wine', host_machine.cpu_family() == 'x86_64' ? 'wine64' : 'wine32']
364   sysroot = meson.get_cross_property('sys_root')
365   if sysroot != ''
366     # Logic from meson
367     devenv_cmd += ['--winepath', 'Z:' + join_paths(sysroot, 'bin')]
368   endif
369 endif
370
371 run_target('uninstalled', command : devenv_cmd)
372 run_target('devenv', command : devenv_cmd)
373
374 update = find_program('git-update')
375 run_target('git-update', command : [update])
376 run_target('update', command : [update,
377     '--builddir=@0@'.format(meson.current_build_dir())])
378
379 if orc_subproject.found() and orc_update_targets.length() > 0
380   alias_target('update-orc-dist', orc_update_targets)
381 endif