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