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