gstfull: Also include 'sources' from dependencies
[platform/upstream/gstreamer.git] / meson.build
1 project('All GStreamer modules', 'c',
2   version : '1.19.0.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
61   # Change some warning which belong to level 3 (production quality) or
62   # 4 (informational) to level 1 (severe)
63   add_global_arguments (
64       '/w14062', # enumerator 'identifier' in switch of enum 'enumeration' is not handled
65       '/w14101', # 'identifier' : unreferenced local variable
66       '/w14189', # 'identifier' : local variable is initialized but not referenced
67       cc.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8
68       language: ['c', 'cpp'])
69 endif
70
71 # Ordered list of subprojects (dict has no ordering guarantees)
72 subprojects = [
73   ['gstreamer', {'build-hotdoc': true}],
74   ['gst-plugins-base', {'option': get_option('base'), 'build-hotdoc': true}],
75   ['gst-plugins-good', {'option': get_option('good'), 'build-hotdoc': true}],
76   ['libnice', { 'option': get_option('libnice'), 'match_gst_version': false}],
77   ['gst-plugins-bad', { 'option': get_option('bad'), 'build-hotdoc': true}],
78   ['gst-plugins-ugly', { 'option': get_option('ugly'), 'build-hotdoc': true}],
79   ['gst-libav', { 'option': get_option('libav'), 'build-hotdoc': true}],
80   ['gst-rtsp-server', { 'option': get_option('rtsp_server'), 'build-hotdoc': true}],
81   ['gst-devtools', { 'option': get_option('devtools'), 'build-hotdoc': true }],
82   ['gst-integration-testsuites', { 'option': get_option('devtools') }],
83   ['gst-editing-services', { 'option': get_option('ges'), 'build-hotdoc': true}],
84   ['gstreamer-vaapi', { 'option': get_option('vaapi'), 'build-hotdoc': true}],
85   ['gst-omx', { 'option': get_option('omx'), 'build-hotdoc': true}],
86   ['gstreamer-sharp', { 'option': get_option('sharp') }],
87   ['pygobject', { 'option': get_option('python'), 'match_gst_version': false }],
88   ['gst-python', { 'option': get_option('python')}],
89   ['gst-examples', { 'option': get_option('gst-examples'), 'match_gst_versions': false}],
90   ['gst-plugins-rs', { 'option': get_option('rs'), 'match_gst_version': false}],
91 ]
92
93 symlink = '''
94 import os
95
96 os.symlink(os.path.join('@1@', 'subprojects', '@0@'),
97   os.path.join('@1@', '@0@'))
98 '''
99
100 if build_system == 'windows'
101   subproject('win-flex-bison-binaries')
102   subproject('win-nasm')
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   # Generate a .c file which declare and register all built plugins
254   generate_init_static_plugins = find_program('scripts/generate_init_static_plugins.py')
255   init_static_plugins_c = configure_file(
256     output: 'gstinitstaticplugins.c',
257     command : [generate_init_static_plugins,
258                '@OUTPUT@',
259                all_plugins_paths]
260   )
261
262   # Avoid a x264 link issue described here: https://gitlab.freedesktop.org/gstreamer/gst-build/-/issues/108
263   # Similar issue has been found with VLC: https://mailman.videolan.org/pipermail/vlc-devel/2009-March/057640.html
264   gstfull_link_args = []
265   if cc.has_link_argument('-Wl,-Bsymbolic')
266     gstfull_link_args += ['-Wl,-Bsymbolic']
267   endif
268
269
270   # Get a list of libraries that needs to be exposed in the ABI.
271   exposed_libs = []
272   incdir_deps = []
273   foreach name : get_option('gst-full-libraries') + ['gstreamer']
274     info = libraries_map[name]
275     exposed_libs += subproject(info[0]).get_variable(info[1])
276     depname = name == 'gstreamer' ? 'gstreamer-1.0' : 'gstreamer-@0@-1.0'.format(name)
277     incdir_deps += dependency(depname).partial_dependency(includes: true, sources: true)
278   endforeach
279
280   # glib and gobject are part of our public API. If we are using glib from the
281   # system then our pkg-config file must require it. If we built it as
282   # subproject then we need to link_whole it.
283   glib_deps = []
284   glib_dep = dependency('glib-2.0')
285   gobject_dep = dependency('gobject-2.0')
286   if gobject_dep.type_name() == 'internal'
287     glib_subproject = subproject('glib')
288     exposed_libs += glib_subproject.get_variable('libglib')
289     exposed_libs += glib_subproject.get_variable('libgobject')
290     incdir_deps += [
291       glib_dep.partial_dependency(includes: true),
292       gobject_dep.partial_dependency(includes: true),
293     ]
294   else
295     glib_deps = [glib_dep, gobject_dep]
296   endif
297
298   link_deps = []
299   if get_option('gst-full-version-script') != ''
300     symbol_map = meson.current_source_dir() / get_option('gst-full-version-script')
301     link_arg = '-Wl,--version-script=' + symbol_map
302     if cc.has_link_argument(link_arg)
303       gstfull_link_args += link_arg
304     else
305       error('Failed to link with version script (' + symbol_map + '), check logs for details')
306     endif
307     link_deps += symbol_map
308   endif
309
310   # Build both shared and static library
311   gstfull = both_libraries('gstreamer-full-1.0',
312     init_static_plugins_c,
313     link_with : all_plugins,
314     link_args: gstfull_link_args,
315     link_whole : exposed_libs,
316     dependencies : incdir_deps + glib_deps,
317     link_depends : link_deps,
318     install : true,
319   )
320
321   gst_full_dep = declare_dependency(link_with: gstfull.get_shared_lib(),
322     dependencies : incdir_deps + glib_deps,
323     include_directories: include_directories('.')
324   )
325   pkgconfig.generate(gstfull,
326     requires: glib_deps,
327     subdirs : 'gstreamer-1.0')
328   meson.override_dependency('gstreamer-full-1.0', gst_full_dep)
329 endif
330
331 foreach custom_subproj: get_option('custom_subprojects').split(',')
332     if custom_subproj != ''
333         message ('Adding custom subproject ' + custom_subproj)
334         subproject(custom_subproj)
335         subprojects_names += [custom_subproj]
336     endif
337 endforeach
338
339 message('Building subprojects: ' + ', '.join(subprojects_names))
340 setenv = find_program('gst-env.py')
341
342 devenv_cmd = [setenv, '--builddir=@0@'.format(meson.build_root()),
343               '--srcdir=@0@'.format(meson.source_root())]
344
345 if meson.has_exe_wrapper() and build_machine.system() == 'linux' and host_machine.system() == 'windows'
346   # FIXME: Ideally we could get the wrapper directly from meson
347   devenv_cmd += ['--wine', host_machine.cpu_family() == 'x86_64' ? 'wine64' : 'wine32']
348   sysroot = meson.get_cross_property('sys_root')
349   if sysroot != ''
350     # Logic from meson
351     devenv_cmd += ['--winepath', 'Z:' + join_paths(sysroot, 'bin')]
352   endif
353 endif
354
355 run_target('uninstalled', command : devenv_cmd)
356 run_target('devenv', command : devenv_cmd)
357
358 update = find_program('git-update')
359 run_target('git-update', command : [update])
360 run_target('update', command : [update,
361     '--builddir=@0@'.format(meson.current_build_dir())])
362
363 if orc_subproject.found() and orc_update_targets.length() > 0
364   alias_target('update-orc-dist', orc_update_targets)
365 endif