meson: Fix warning building GstGLEGL
[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 gnome = import('gnome')
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 # Install gst-indent pre-commit hook
28 run_command(python3, '-c', 'import shutil; shutil.copy("scripts/git-hooks/multi-pre-commit.hook", ".git/hooks/pre-commit")')
29
30 # Ensure that the user does not have Strawberry Perl in PATH, since it ships
31 # with a pkg-config.bat and broken pkgconfig files for libffi and zlib. Will
32 # cause a build error, such as in
33 # https://gitlab.freedesktop.org/gstreamer/gst-build/-/issues/41
34 ensure_no_strawberry_perl = '''
35 import os
36 assert(r'Strawberry\perl\bin' not in os.environ['PATH'])
37 '''
38 if build_system == 'windows'
39   cmdres = run_command(python3, '-c', ensure_no_strawberry_perl)
40   if cmdres.returncode() != 0
41     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.')
42   endif
43 endif
44
45 documented_projects = ''
46 # Make it possible to use msys2 built zlib which fails
47 # when not using the mingw toolchain as it uses unistd.h
48 if not meson.is_subproject() and cc.get_id() == 'msvc'
49   uname = find_program('uname', required: false)
50   if uname.found()
51     ret = run_command(uname, '-o')
52     if ret.returncode() == 0 and ret.stdout().to_lower() == 'msys'
53       ret = run_command(uname, '-r')
54       # The kernel version returned by uname is actually the msys version
55       if ret.returncode() == 0 and ret.stdout().startswith('2')
56         # If a system zlib is found, disable UNIX features in zlib.h and zconf.h
57         if cc.find_library('z').found()
58           add_global_arguments('-DZ_SOLO', language: 'c')
59         endif
60       endif
61     endif
62   endif
63 endif
64
65 # Ensure that MSVC interprets all source code as UTF-8. Only do this when we're
66 # not a subproject, because subprojects are not allowed to call
67 # add_global_arguments().
68 if not meson.is_subproject() and cc.get_id() == 'msvc'
69   add_global_arguments(
70       cc.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8
71       language: ['c', 'cpp'])
72 endif
73
74 # Ordered list of subprojects (dict has no ordering guarantees)
75 subprojects = [
76   ['gstreamer', {'build-hotdoc': true}],
77   ['gst-plugins-base', {'option': get_option('base'), 'build-hotdoc': true}],
78   ['gst-plugins-good', {'option': get_option('good'), 'build-hotdoc': true}],
79   ['libnice', { 'option': get_option('libnice'), 'match_gst_version': false}],
80   ['gst-plugins-bad', { 'option': get_option('bad'), 'build-hotdoc': true}],
81   ['gst-plugins-ugly', { 'option': get_option('ugly'), 'build-hotdoc': true}],
82   ['gst-libav', { 'option': get_option('libav'), 'build-hotdoc': true}],
83   ['gst-rtsp-server', { 'option': get_option('rtsp_server'), 'build-hotdoc': true}],
84   ['gst-devtools', { 'option': get_option('devtools'), 'build-hotdoc': true }],
85   ['gst-integration-testsuites', { 'option': get_option('devtools') }],
86   ['gst-editing-services', { 'option': get_option('ges'), 'build-hotdoc': true}],
87   ['gstreamer-vaapi', { 'option': get_option('vaapi'), 'build-hotdoc': true}],
88   ['gst-omx', { 'option': get_option('omx'), 'build-hotdoc': true}],
89   ['gstreamer-sharp', { 'option': get_option('sharp') }],
90   ['pygobject', { 'option': get_option('python'), 'match_gst_version': false, 'sysdep': 'pygobject-3.0', 'sysdep_version': '>= 3.38.1' }],
91   ['gst-python', { 'option': get_option('python')}],
92   ['gst-examples', { 'option': get_option('gst-examples'), 'match_gst_versions': false}],
93   ['gst-plugins-rs', { 'option': get_option('rs'), 'match_gst_version': false}],
94 ]
95
96 symlink = '''
97 import os
98
99 os.symlink(os.path.join('@1@', 'subprojects', '@0@'),
100   os.path.join('@1@', '@0@'))
101 '''
102
103 if build_system == 'windows'
104   subproject('win-flex-bison-binaries')
105   subproject('win-nasm')
106 elif build_system == 'darwin'
107   subproject('macos-bison-binary')
108 endif
109
110 orc_subproject = subproject('orc', required: get_option('orc'))
111
112 subprojects_names = []
113 plugins_doc_caches = []
114 orc_update_targets = []
115 all_plugins = []
116 # Using a list and not a dict to keep the ordering to build the chain of `gir`
117 # dependencies
118 all_libraries = []
119 foreach sp : subprojects
120   project_name = sp[0]
121   build_infos = sp[1]
122   is_required = build_infos.get('option', true)
123   sysdep = build_infos.get('sysdep', '')
124   sysdep_version = build_infos.get('sysdep_version', '')
125   match_gst_version = build_infos.get('match_gst_version', true)
126
127   if match_gst_version
128     subproj = subproject(project_name, version: gst_version, required: is_required)
129   elif sysdep != ''
130       sysdep_dep = dependency(sysdep, version: sysdep_version, required: false)
131       if not sysdep_dep.found()
132         subproj = subproject(project_name, required: is_required)
133       endif
134   else
135     subproj = subproject(project_name, required: is_required)
136   endif
137
138   if subproj.found()
139     plugins = subproj.get_variable('plugins', [])
140     all_plugins += plugins
141     all_libraries += subproj.get_variable('libraries', [])
142
143     orc_update_targets += subproj.get_variable('orc_update_targets', [])
144
145     subprojects_names += [project_name]
146     cmdres = run_command(python3, '-c', symlink.format(project_name, meson.current_source_dir()))
147     if cmdres.returncode() == 0
148       message('Created symlink to ' + project_name)
149     endif
150
151     if not meson.is_cross_build() and build_infos.get('build-hotdoc', false)
152       if plugins.length() > 0
153         plugins_doc_caches += [subproj.get_variable('plugins_doc_dep', [])]
154       endif
155       if documented_projects != ''
156         documented_projects += ','
157       endif
158       documented_projects  += project_name
159     endif
160   endif
161 endforeach
162
163 # Check if we need to also build glib-networking for TLS modules
164 glib_dep = dependency('glib-2.0')
165 if glib_dep.type_name() == 'internal'
166   subproject('glib-networking', required : get_option('tls'),
167              default_options: ['gnutls=auto', 'openssl=auto'])
168 endif
169
170 plugins_doc_dep = custom_target('plugins-doc-cache',
171   command: [python3, '-c', 'print("Built all doc caches")'],
172   input: plugins_doc_caches,
173   output: 'plugins_doc_caches',
174   capture: true,
175 )
176
177 if meson.is_cross_build() or build_machine.system() == 'windows'
178     if get_option('doc').enabled()
179         error('Documentation enabled but building the doc while cross building or building on windows is not supported yet.')
180     endif
181
182     documented_projects = ''
183     message('Documentation not built as building the documentation while cross building or building on windows is not supported yet.')
184 else
185   hotdoc_p = find_program('hotdoc', required : get_option('doc'))
186   if not hotdoc_p.found()
187     documented_projects = ''
188     message('Not building documentation as hotdoc was not found')
189   endif
190 endif
191
192 write_file_contents = '''
193 import os
194 import sys
195
196 assert len(sys.argv) >= 3
197 fname = sys.argv[1]
198 contents = sys.argv[2]
199
200 with open(fname, 'w') as f:
201     f.write(contents)
202 '''
203
204 configure_file(
205   output : 'GstDocumentedSubprojects',
206   command : [python3,
207              '-c', write_file_contents,
208              '@OUTPUT@',
209              documented_projects]
210 )
211
212 if documented_projects != ''
213   subproject('gst-docs', required: get_option('doc').enabled())
214   message('Gst docs subprojects: ' + documented_projects)
215 endif
216
217 all_plugins_paths = []
218 foreach plugin: all_plugins
219   all_plugins_paths += plugin.full_path()
220 endforeach
221 # Work around meson bug: https://github.com/mesonbuild/meson/pull/6770
222 pathsep = host_machine.system() == 'windows' ? ';' : ':'
223 all_plugins_paths = pathsep.join(all_plugins_paths)
224
225 generate_plugins_paths = find_program('scripts/generate_plugins_path.py')
226 configure_file(
227   output : 'GstPluginsPath.json',
228   command : [generate_plugins_paths,
229              '@OUTPUT@',
230              all_plugins_paths]
231 )
232
233 if get_option('default_library') == 'static'
234   # Generate a .c file which declare and register all built plugins
235   plugins_names = []
236   foreach plugin: all_plugins
237     plugins_names += plugin.full_path()
238   endforeach
239   all_plugin_names = ';'.join(plugins_names)
240
241   static_plugins = get_option('gst-full-plugins')
242   if static_plugins == '*'
243     static_plugins = all_plugin_names
244   endif
245   generate_init_static_plugins = find_program('scripts/generate_init_static_plugins.py')
246   init_static_plugins_c = configure_file(
247     output: 'gstinitstaticplugins.c',
248     command : [generate_init_static_plugins,
249                '-o ' + '@OUTPUT@',
250                '-p ' + static_plugins,
251                '-e ' + get_option('gst-full-elements'),
252                '-t ' + get_option('gst-full-typefind-functions'),
253                '-d ' + get_option('gst-full-device-providers'),
254                '-T ' + get_option('gst-full-dynamic-types')
255                ]
256   )
257
258   gstfull_link_args = cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions'])
259
260   # Get a list of libraries that needs to be exposed in the ABI.
261   exposed_libs = []
262   exposed_girs = []
263   incdir_deps = []
264   wanted_libs = ['gstreamer-1.0'] + get_option('gst-full-libraries')
265   all_libs = '*' in wanted_libs
266
267   foreach pkgname_library : all_libraries
268     pkg_name = pkgname_library[0]
269     lib_def = pkgname_library[1]
270
271     if pkg_name in wanted_libs or all_libs
272       if lib_def.has_key('lib')
273         incdir_deps += dependency(pkg_name).partial_dependency(includes: true, sources: true)
274         exposed_libs += [lib_def['lib']]
275       endif
276
277       if lib_def.has_key('gir')
278         exposed_girs += lib_def['gir']
279       endif
280     endif
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
331   gst_full_libs_private = cc.get_supported_link_arguments(['-Wl,--undefined=gst_init_static_plugins'])
332   if gst_full_libs_private == []
333     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.')
334   endif
335
336   if not get_option('introspection').disabled()
337     built_girs = {}
338     foreach gir: exposed_girs
339       includes = []
340       foreach include: gir.get('includes', [])
341         includes += [built_girs.get(include, include)]
342       endforeach
343
344       gir += {
345         'includes': includes,
346         'extra_args': gir.get('extra_args', []) + ['--add-include-path=' + meson.current_build_dir()],
347         'install': true,
348       }
349       built_girs += {gir.get('namespace') + '-' + gir.get('nsversion'): gnome.generate_gir(gstfull, kwargs: gir)[0]}
350     endforeach
351   endif
352
353   pkgconfig.generate(gstfull,
354     requires: glib_deps,
355     libraries_private: gst_full_libs_private,
356     subdirs : 'gstreamer-1.0')
357   meson.override_dependency('gstreamer-full-1.0', gst_full_dep)
358 endif
359
360 foreach custom_subproj: get_option('custom_subprojects').split(',')
361     if custom_subproj != ''
362         message ('Adding custom subproject ' + custom_subproj)
363         subproject(custom_subproj)
364         subprojects_names += [custom_subproj]
365     endif
366 endforeach
367
368 message('Building subprojects: ' + ', '.join(subprojects_names))
369
370 setenv = find_program('gst-env.py')
371 devenv_cmd = [setenv, '--builddir=@0@'.format(meson.build_root()),
372               '--gstbuilddir=@0@'.format(meson.current_build_dir()),
373               '--srcdir=@0@'.format(meson.source_root())]
374
375 subdir('tests')
376 if meson.has_exe_wrapper() and build_machine.system() == 'linux' and host_machine.system() == 'windows'
377   # FIXME: Ideally we could get the wrapper directly from meson
378   devenv_cmd += ['--wine', host_machine.cpu_family() == 'x86_64' ? 'wine64' : 'wine32']
379   sysroot = meson.get_cross_property('sys_root')
380   if sysroot != ''
381     # Logic from meson
382     devenv_cmd += ['--winepath', 'Z:' + join_paths(sysroot, 'bin')]
383   endif
384 endif
385
386 run_target('uninstalled', command : devenv_cmd)
387 run_target('devenv', command : devenv_cmd)
388
389 if orc_subproject.found() and orc_update_targets.length() > 0
390   alias_target('update-orc-dist', orc_update_targets)
391 endif
392
393 summary({
394   'gstreamer-full': get_option('default_library') == 'static',
395 }, section: 'Build options', bool_yn: true, list_sep: '  ')