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