meson: Disable symlink to gst modules
[platform/upstream/gstreamer.git] / meson.build
1 project('gstreamer-full', 'c',
2   version : '1.19.3.1',
3   meson_version : '>= 0.59',
4   default_options : ['buildtype=debugoptimized',
5                      # Needed due to https://github.com/mesonbuild/meson/issues/1889,
6                      # but this can cause problems in the future. Remove it
7                      # when it's no longer necessary.
8                      'cpp_std=c++14'])
9
10 gst_version = '>= @0@'.format(meson.project_version())
11
12 build_system = build_machine.system()
13 cc = meson.get_compiler('c')
14
15 fs = import('fs')
16 gnome = import('gnome')
17 pkgconfig = import('pkgconfig')
18 python3 = import('python').find_installation()
19 # Ensure that we're not being run from inside the gst-uninstalled env
20 # because that will confuse meson, and it might find the already-built
21 # gstreamer. It's fine if people run `ninja` as long as it doesn't run
22 # reconfigure because ninja doesn't care about the env.
23 ensure_not_uninstalled = '''
24 import os
25 assert('GST_ENV' not in os.environ)
26 '''
27 cmdres = run_command(python3, '-c', ensure_not_uninstalled)
28 if cmdres.returncode() != 0
29   error('Do not run `ninja` or `meson` for gst-build inside the uninstalled environment, you will run into problems')
30 endif
31
32 # Install gst-indent pre-commit hook
33 run_command(python3, '-c', 'import shutil; shutil.copy("scripts/git-hooks/multi-pre-commit.hook", ".git/hooks/pre-commit")')
34
35 # Ensure that the user does not have Strawberry Perl in PATH, since it ships
36 # with a pkg-config.bat and broken pkgconfig files for libffi and zlib. Will
37 # cause a build error, such as in
38 # https://gitlab.freedesktop.org/gstreamer/gst-build/-/issues/41
39 ensure_no_strawberry_perl = '''
40 import os
41 assert(r'Strawberry\perl\bin' not in os.environ['PATH'])
42 '''
43 if build_system == 'windows' and meson.version().version_compare('<0.60.0')
44   cmdres = run_command(python3, '-c', ensure_no_strawberry_perl)
45   if cmdres.returncode() != 0
46     error('You have Strawberry Perl in PATH which is known to cause build issues with Meson < 0.60.0. Please remove it from PATH, uninstall it, or upgrade Meson.')
47   endif
48 endif
49
50 documented_projects = ''
51 # Make it possible to use msys2 built zlib which fails
52 # when not using the mingw toolchain as it uses unistd.h
53 if not meson.is_subproject() and cc.get_id() == 'msvc'
54   uname = find_program('uname', required: false)
55   if uname.found()
56     ret = run_command(uname, '-o')
57     if ret.returncode() == 0 and ret.stdout().to_lower() == 'msys'
58       ret = run_command(uname, '-r')
59       # The kernel version returned by uname is actually the msys version
60       if ret.returncode() == 0 and ret.stdout().startswith('2')
61         # If a system zlib is found, disable UNIX features in zlib.h and zconf.h
62         if cc.find_library('z').found()
63           add_global_arguments('-DZ_SOLO', language: 'c')
64         endif
65       endif
66     endif
67   endif
68 endif
69
70 # Ensure that MSVC interprets all source code as UTF-8. Only do this when we're
71 # not a subproject, because subprojects are not allowed to call
72 # add_global_arguments().
73 if not meson.is_subproject() and cc.get_id() == 'msvc'
74   add_global_arguments(
75       cc.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8
76       language: ['c', 'cpp'])
77 endif
78
79 # Ordered list of subprojects (dict has no ordering guarantees)
80 subprojects = [
81   ['gstreamer', {'build-hotdoc': true}],
82   ['gst-plugins-base', {'option': get_option('base'), 'build-hotdoc': true}],
83   ['gst-plugins-good', {'option': get_option('good'), 'build-hotdoc': true}],
84   ['libnice', { 'option': get_option('libnice'), 'match_gst_version': false}],
85   ['gst-plugins-bad', { 'option': get_option('bad'), 'build-hotdoc': true}],
86   ['gst-plugins-ugly', { 'option': get_option('ugly'), 'build-hotdoc': true}],
87   ['gst-libav', { 'option': get_option('libav'), 'build-hotdoc': true}],
88   ['gst-rtsp-server', { 'option': get_option('rtsp_server'), 'build-hotdoc': true}],
89   ['gst-devtools', { 'option': get_option('devtools'), 'build-hotdoc': true }],
90   ['gst-integration-testsuites', { 'option': get_option('devtools') }],
91   ['gst-editing-services', { 'option': get_option('ges'), 'build-hotdoc': true}],
92   ['gstreamer-vaapi', { 'option': get_option('vaapi'), 'build-hotdoc': true}],
93   ['gst-omx', { 'option': get_option('omx'), 'build-hotdoc': true}],
94   ['gstreamer-sharp', { 'option': get_option('sharp') }],
95   ['pygobject', { 'option': get_option('python'), 'match_gst_version': false, 'sysdep': 'pygobject-3.0', 'sysdep_version': '>= 3.38.1' }],
96   ['gst-python', { 'option': get_option('python')}],
97   ['gst-examples', { 'option': get_option('gst-examples'), 'match_gst_versions': false}],
98   ['gst-plugins-rs', { 'option': get_option('rs'), 'match_gst_version': false}],
99 ]
100
101 symlink = '''
102 import os
103
104 os.symlink(os.path.join('@1@', 'subprojects', '@0@'),
105   os.path.join('@1@', '@0@'))
106 '''
107
108 if build_system == 'windows'
109   subproject('win-flex-bison-binaries')
110   subproject('win-nasm')
111 elif build_system == 'darwin'
112   subproject('macos-bison-binary')
113 endif
114
115 orc_subproject = subproject('orc', required: get_option('orc'))
116
117 subprojects_names = []
118 plugins_doc_caches = []
119 orc_update_targets = []
120 all_plugins = []
121 # Using a list and not a dict to keep the ordering to build the chain of `gir`
122 # dependencies
123 all_libraries = []
124 foreach sp : subprojects
125   project_name = sp[0]
126   build_infos = sp[1]
127   is_required = build_infos.get('option', true)
128   sysdep = build_infos.get('sysdep', '')
129   sysdep_version = build_infos.get('sysdep_version', '')
130   match_gst_version = build_infos.get('match_gst_version', true)
131
132   if match_gst_version
133     subproj = subproject(project_name, version: gst_version, required: is_required)
134   elif sysdep != ''
135       sysdep_dep = dependency(sysdep, version: sysdep_version, required: false)
136       if not sysdep_dep.found()
137         subproj = subproject(project_name, required: is_required)
138       endif
139   else
140     subproj = subproject(project_name, required: is_required)
141   endif
142
143   if subproj.found()
144     plugins = subproj.get_variable('plugins', [])
145     all_plugins += plugins
146     all_libraries += subproj.get_variable('libraries', [])
147
148     orc_update_targets += subproj.get_variable('orc_update_targets', [])
149
150     subprojects_names += [project_name]
151
152     if not meson.is_cross_build() and build_infos.get('build-hotdoc', false)
153       if plugins.length() > 0
154         plugins_doc_caches += [subproj.get_variable('plugins_doc_dep', [])]
155       endif
156       if documented_projects != ''
157         documented_projects += ','
158       endif
159       documented_projects  += project_name
160     endif
161   endif
162 endforeach
163
164 # Check if we need to also build glib-networking for TLS modules
165 glib_dep = dependency('glib-2.0')
166 if glib_dep.type_name() == 'internal'
167   subproject('glib-networking', required : get_option('tls'),
168              default_options: ['gnutls=auto', 'openssl=auto'])
169 endif
170
171 plugins_doc_dep = custom_target('plugins-doc-cache',
172   command: [python3, '-c', 'print("Built all doc caches")'],
173   input: plugins_doc_caches,
174   output: 'plugins_doc_caches',
175   capture: true,
176 )
177
178 if meson.is_cross_build() or build_machine.system() == 'windows'
179     if get_option('doc').enabled()
180         error('Documentation enabled but building the doc while cross building or building on windows is not supported yet.')
181     endif
182
183     documented_projects = ''
184     message('Documentation not built as building the documentation while cross building or building on windows is not supported yet.')
185 else
186   hotdoc_p = find_program('hotdoc', required : get_option('doc'))
187   if not hotdoc_p.found()
188     documented_projects = ''
189     message('Not building documentation as hotdoc was not found')
190   endif
191 endif
192
193 write_file_contents = '''
194 import os
195 import sys
196
197 assert len(sys.argv) >= 3
198 fname = sys.argv[1]
199 contents = sys.argv[2]
200
201 with open(fname, 'w') as f:
202     f.write(contents)
203 '''
204
205 configure_file(
206   output : 'GstDocumentedSubprojects',
207   command : [python3,
208              '-c', write_file_contents,
209              '@OUTPUT@',
210              documented_projects]
211 )
212
213 if documented_projects != ''
214   subproject('gst-docs', required: get_option('doc').enabled())
215   message('Gst docs subprojects: ' + documented_projects)
216 endif
217
218 all_plugins_paths = []
219 all_plugins_dirs = []
220 foreach plugin: all_plugins
221   all_plugins_paths += plugin.full_path()
222   all_plugins_dirs += fs.parent(plugin.full_path())
223 endforeach
224 # Work around meson bug: https://github.com/mesonbuild/meson/pull/6770
225 pathsep = host_machine.system() == 'windows' ? ';' : ':'
226 all_plugins_paths = pathsep.join(all_plugins_paths)
227
228 devenv = environment()
229 devenv.set('GST_PLUGIN_PATH', all_plugins_dirs)
230 devenv.set('CURRENT_GST', meson.current_source_dir())
231 devenv.set('GST_VERSION', meson.project_version())
232 devenv.set('GST_ENV', 'gst-' + meson.project_version())
233 devenv.set('GST_REGISTRY', meson.current_build_dir() / 'registry.dat')
234 devenv.set('GST_PLUGIN_SYSTEM_PATH', '')
235 meson.add_devenv(devenv)
236
237 generate_plugins_paths = find_program('scripts/generate_plugins_path.py')
238 configure_file(
239   output : 'GstPluginsPath.json',
240   command : [generate_plugins_paths,
241              '@OUTPUT@',
242              all_plugins_paths]
243 )
244
245 if get_option('default_library') == 'static'
246   # Generate a .c file which declare and register all built plugins
247   plugins_names = []
248   foreach plugin: all_plugins
249     plugins_names += plugin.full_path()
250   endforeach
251   all_plugin_names = ';'.join(plugins_names)
252
253   static_plugins = get_option('gst-full-plugins')
254   if static_plugins == '*'
255     static_plugins = all_plugin_names
256   endif
257   generate_init_static_plugins = find_program('scripts/generate_init_static_plugins.py')
258   init_static_plugins_c = configure_file(
259     output: 'gstinitstaticplugins.c',
260     command : [generate_init_static_plugins,
261                '-o ' + '@OUTPUT@',
262                '-p ' + static_plugins,
263                '-e ' + get_option('gst-full-elements'),
264                '-t ' + get_option('gst-full-typefind-functions'),
265                '-d ' + get_option('gst-full-device-providers'),
266                '-T ' + get_option('gst-full-dynamic-types')
267                ]
268   )
269
270   gstfull_link_args = cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions'])
271
272   # Get a list of libraries that needs to be exposed in the ABI.
273   exposed_libs = []
274   exposed_girs = []
275   incdir_deps = []
276   wanted_libs = ['gstreamer-1.0'] + get_option('gst-full-libraries')
277   all_libs = '*' in wanted_libs
278
279   foreach pkgname_library : all_libraries
280     pkg_name = pkgname_library[0]
281     lib_def = pkgname_library[1]
282
283     if pkg_name in wanted_libs or all_libs
284       if lib_def.has_key('lib')
285         incdir_deps += dependency(pkg_name).partial_dependency(includes: true, sources: true)
286         exposed_libs += [lib_def['lib']]
287       endif
288
289       if lib_def.has_key('gir')
290         exposed_girs += lib_def['gir']
291       endif
292     endif
293   endforeach
294
295   # glib and gobject are part of our public API. If we are using glib from the
296   # system then our pkg-config file must require it. If we built it as
297   # subproject then we need to link_whole it.
298   glib_deps = []
299   glib_dep = dependency('glib-2.0')
300   gobject_dep = dependency('gobject-2.0')
301   if gobject_dep.type_name() == 'internal'
302     glib_subproject = subproject('glib')
303     exposed_libs += glib_subproject.get_variable('libglib')
304     exposed_libs += glib_subproject.get_variable('libgobject')
305     incdir_deps += [
306       glib_dep.partial_dependency(includes: true),
307       gobject_dep.partial_dependency(includes: true),
308     ]
309   else
310     glib_deps = [glib_dep, gobject_dep]
311   endif
312
313   link_deps = []
314   if get_option('gst-full-version-script') != ''
315     symbol_map = meson.current_source_dir() / get_option('gst-full-version-script')
316     link_arg = '-Wl,--version-script=' + symbol_map
317     if cc.has_link_argument(link_arg)
318       gstfull_link_args += link_arg
319       link_deps += symbol_map
320     elif cc.get_id() == 'msvc'
321       warning('FIXME: Provide a def file to publish the public symbols')
322     else
323       error('Failed to link with version script (' + symbol_map + '), check logs for details')
324     endif
325   endif
326
327   # Build both shared and static library
328   gstfull = both_libraries('gstreamer-full-1.0',
329     init_static_plugins_c,
330     link_with : all_plugins,
331     link_args: gstfull_link_args,
332     link_whole : exposed_libs,
333     dependencies : incdir_deps + glib_deps,
334     link_depends : link_deps,
335     install : true,
336   )
337
338   gst_full_dep = declare_dependency(link_with: gstfull.get_shared_lib(),
339     dependencies : incdir_deps + glib_deps,
340     include_directories: include_directories('.')
341   )
342
343   gst_full_libs_private = cc.get_supported_link_arguments(['-Wl,--undefined=gst_init_static_plugins'])
344   if gst_full_libs_private == []
345     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.')
346   endif
347
348   if not get_option('introspection').disabled()
349     built_girs = {}
350     foreach gir: exposed_girs
351       includes = []
352       foreach include: gir.get('includes', [])
353         includes += [built_girs.get(include, include)]
354       endforeach
355
356       gir += {
357         'includes': includes,
358         'extra_args': gir.get('extra_args', []) + ['--add-include-path=' + meson.current_build_dir()],
359         'install': true,
360       }
361       built_girs += {gir.get('namespace') + '-' + gir.get('nsversion'): gnome.generate_gir(gstfull, kwargs: gir)[0]}
362     endforeach
363   endif
364
365   pkgconfig.generate(gstfull,
366     requires: glib_deps,
367     libraries_private: gst_full_libs_private,
368     subdirs : 'gstreamer-1.0')
369   meson.override_dependency('gstreamer-full-1.0', gst_full_dep)
370 endif
371
372 foreach custom_subproj: get_option('custom_subprojects').split(',')
373     if custom_subproj != ''
374         message ('Adding custom subproject ' + custom_subproj)
375         subproject(custom_subproj)
376         subprojects_names += [custom_subproj]
377     endif
378 endforeach
379
380 message('Building subprojects: ' + ', '.join(subprojects_names))
381
382 setenv = find_program('gst-env.py')
383 devenv_cmd = [setenv, '--builddir=@0@'.format(meson.project_build_root()),
384               '--gstbuilddir=@0@'.format(meson.current_build_dir()),
385               '--srcdir=@0@'.format(meson.project_source_root())]
386
387 subdir('tests')
388 if meson.can_run_host_binaries() and build_machine.system() == 'linux' and host_machine.system() == 'windows'
389   # FIXME: Ideally we could get the wrapper directly from meson
390   devenv_cmd += ['--wine', host_machine.cpu_family() == 'x86_64' ? 'wine64' : 'wine32']
391   sysroot = meson.get_cross_property('sys_root')
392   if sysroot != ''
393     # Logic from meson
394     devenv_cmd += ['--winepath', 'Z:' + join_paths(sysroot, 'bin')]
395   endif
396 endif
397
398 run_target('uninstalled', command : devenv_cmd)
399 run_target('devenv', command : devenv_cmd)
400
401 if orc_subproject.found() and orc_update_targets.length() > 0
402   alias_target('update-orc-dist', orc_update_targets)
403 endif
404
405 summary({
406   'gstreamer-full': get_option('default_library') == 'static',
407 }, section: 'Build options', bool_yn: true, list_sep: '  ')