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