meson: Generate ChangeLog files for release tarballs on dist
[platform/upstream/gstreamer.git] / meson.build
1 project('gstreamer-full', 'c',
2   version : '1.21.2.1',
3   meson_version : '>= 0.62.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 apiversion = '1.0'
11 gst_version = '>= @0@'.format(meson.project_version())
12
13 build_system = build_machine.system()
14 cc = meson.get_compiler('c')
15
16 fs = import('fs')
17 gnome = import('gnome')
18 pkgconfig = import('pkgconfig')
19 python3 = import('python').find_installation()
20 # Ensure that we're not being run from inside the development environment
21 # because that will confuse meson, and it might find the already-built
22 # gstreamer. It's fine if people run `ninja` as long as it doesn't run
23 # reconfigure because ninja doesn't care about the env.
24 ensure_not_devenv = '''
25 import os
26 assert('GST_ENV' not in os.environ)
27 '''
28 cmdres = run_command(python3, '-c', ensure_not_devenv, check: false)
29 if cmdres.returncode() != 0
30   error('Do not run `ninja reconfigure` or `meson` for gst-build inside the development environment, you will run into problems')
31 endif
32
33 # Install gst-indent pre-commit hook
34 run_command(python3, '-c', 'import shutil; shutil.copy("scripts/git-hooks/multi-pre-commit.hook", ".git/hooks/pre-commit")', check: false)
35
36 # On macOS, you have to run "Install Certificates.command" otherwise Python
37 # doesn't have access to the latest SSL CA Certificates, and Meson will fail to
38 # download wrap files from websites that use, for example, Let's Encrypt.
39 # We already recommend this in the README, but add a warning here as well.
40 # Can't make this an error because the user might be using XCode's Python
41 # 3 which doesn't have this script.
42 if build_system == 'darwin'
43   python3_cacert_file = python3.get_path('data') / 'etc/openssl/cert.pem'
44   install_cert_cmd = '/Applications/Python @0@/Install Certificates.command'.format(python3.language_version())
45   if not fs.is_symlink(python3_cacert_file) and fs.is_file(install_cert_cmd)
46     warning('Please run "@0@" so that Python has access to the latest SSL certificates. Meson might fail to download some wraps without it.'.format(install_cert_cmd))
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', check: false)
57     if ret.returncode() == 0 and ret.stdout().to_lower() == 'msys'
58       ret = run_command(uname, '-r', check: false)
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 building_full = get_option('default_library') == 'static'
80 tools_option = []
81 if building_full and not get_option('tools').disabled()
82   # Do not build subprojects tools when we build them against gst-full
83   tools_option = ['tools=disabled']
84 endif
85
86 # Ordered list of subprojects (dict has no ordering guarantees)
87 subprojects = [
88   ['gstreamer', {'build-hotdoc': true, 'subproject_options': tools_option}],
89   ['gst-plugins-base', {'option': get_option('base'), 'build-hotdoc': true}],
90   ['gst-plugins-good', {'option': get_option('good'), 'build-hotdoc': true}],
91   ['libnice', { 'option': get_option('libnice'), 'match_gst_version': false}],
92   ['gst-plugins-bad', { 'option': get_option('bad'), 'build-hotdoc': true}],
93   ['gst-plugins-ugly', { 'option': get_option('ugly'), 'build-hotdoc': true}],
94   ['gst-libav', { 'option': get_option('libav'), 'build-hotdoc': true}],
95   ['gst-rtsp-server', { 'option': get_option('rtsp_server'), 'build-hotdoc': true}],
96   ['gst-devtools', { 'option': get_option('devtools'), 'build-hotdoc': true, 'subproject_options': tools_option}],
97   ['gst-integration-testsuites', { 'option': get_option('devtools') }],
98   ['gst-editing-services', { 'option': get_option('ges'), 'build-hotdoc': true, 'subproject_options': tools_option}],
99   ['gstreamer-vaapi', { 'option': get_option('vaapi'), 'build-hotdoc': true}],
100   ['gst-omx', { 'option': get_option('omx'), 'build-hotdoc': true}],
101   ['gstreamer-sharp', { 'option': get_option('sharp') }],
102   ['pygobject', { 'option': get_option('python'), 'match_gst_version': false, 'sysdep': 'pygobject-3.0', 'sysdep_version': '>= 3.8' }],
103   ['gst-python', { 'option': get_option('python')}],
104   ['gst-examples', { 'option': get_option('gst-examples'), 'match_gst_versions': false}],
105   ['gst-plugins-rs', { 'option': get_option('rs'), 'build-hotdoc': true, 'match_gst_version': false}],
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_option = get_option('orc')
116 # There is a check below to keep this in sync with subprojects/gst-plugins-base/meson.build
117 orc_req = '>= 0.4.24'
118 orc_source_option = get_option('orc-source')
119 orc_subproject = disabler()
120 if orc_option.allowed()
121   if orc_source_option == 'subproject'
122     orc_subproject = subproject('orc', required: orc_option)
123   else
124     dependency('orc-0.4', version: orc_req, required: orc_option,
125                allow_fallback: orc_source_option == 'auto')
126   endif
127 endif
128
129 foreach custom_subproj: get_option('custom_subprojects').split(',')
130     if custom_subproj != ''
131         message ('Adding custom subproject ' + custom_subproj)
132         subprojects += [[custom_subproj, {'match_gst_version': false}]]
133     endif
134 endforeach
135
136
137 subprojects_names = []
138 plugins_doc_caches = []
139 orc_update_targets = []
140 all_plugins = []
141 all_tools = {}
142 # Using a list and not a dict to keep the ordering to build the chain of `gir`
143 # dependencies
144 all_libraries = []
145 foreach sp : subprojects
146   project_name = sp[0]
147   build_infos = sp[1]
148   is_required = build_infos.get('option', true)
149   sysdep = build_infos.get('sysdep', '')
150   sysdep_version = build_infos.get('sysdep_version', '')
151   match_gst_version = build_infos.get('match_gst_version', true)
152   default_options =  build_infos.get('subproject_options', [])
153
154   if match_gst_version
155     subproj = subproject(project_name, version: gst_version, required: is_required, default_options: default_options)
156   elif sysdep != ''
157       sysdep_dep = dependency(sysdep, version: sysdep_version, required: false, default_options: default_options)
158       if not sysdep_dep.found()
159         subproj = subproject(project_name, required: is_required, default_options: default_options)
160       endif
161   else
162     subproj = subproject(project_name, required: is_required, default_options: default_options)
163   endif
164
165   if project_name == 'gst-plugins-base'
166     gst_base_orc_req = subproj.get_variable('orc_req', '')
167     if gst_base_orc_req != orc_req
168       error('orc_req is "@0@" but it should be "@1@" from subprojects/gst-plugins-base/meson.build'
169             .format(orc_req, gst_base_orc_req))
170     endif
171   endif
172
173   if subproj.found()
174     plugins = subproj.get_variable('gst_plugins', [])
175     legacy_plugins = subproj.get_variable('plugins', [])
176     all_plugins += plugins
177     if plugins.length() == 0 and legacy_plugins.length() > 0
178       warning(f'DEPRECATED use of the `plugins` variable in @project_name@.')
179       warning('The variable should now be called `gst_plugins` and use:')
180       warning('`declare_dependency( link_with: <plugin_target>, variable: {\'full_path\': <plugin_target>.full_path()})` instead')
181       foreach plugin: legacy_plugins
182         all_plugins += [declare_dependency(link_with: plugin, variables: {'full_path': plugin.full_path()})]
183       endforeach
184     endif
185
186     all_libraries += subproj.get_variable('gst_libraries', [])
187     if not get_option('tools').disabled()
188       all_tools += subproj.get_variable('gst_tools', {})
189     endif
190
191     orc_update_targets += subproj.get_variable('orc_update_targets', [])
192
193     subprojects_names += [project_name]
194
195     if not meson.is_cross_build() and build_infos.get('build-hotdoc', false)
196       plugins_doc_caches += [subproj.get_variable('gst_plugins_doc_dep', [])]
197       if documented_projects != ''
198         documented_projects += ','
199       endif
200       documented_projects  += project_name
201     endif
202   endif
203 endforeach
204
205 # Check if we need to also build glib-networking for TLS modules
206 giomodules = []
207 glib_dep = dependency('glib-2.0')
208 if glib_dep.type_name() == 'internal'
209   subp = subproject('glib-networking', required : get_option('tls'),
210              default_options: ['gnutls=auto', 'openssl=auto'])
211   if subp.found()
212     giomodules += subp.get_variable('giomodules', [])
213   endif
214 endif
215
216 gst_plugins_doc_dep = custom_target('plugins-doc-cache',
217   command: [python3, '-c', 'print("Built all doc caches")'],
218   input: plugins_doc_caches,
219   output: 'plugins_doc_caches',
220   capture: true,
221 )
222
223 if meson.is_cross_build() or build_machine.system() == 'windows'
224     if get_option('doc').enabled()
225         error('Documentation enabled but building the doc while cross building or building on windows is not supported yet.')
226     endif
227
228     documented_projects = ''
229     message('Documentation not built as building the documentation while cross building or building on windows is not supported yet.')
230 else
231   hotdoc_p = find_program('hotdoc', required : get_option('doc'))
232   if not hotdoc_p.found()
233     documented_projects = ''
234     message('Not building documentation as hotdoc was not found')
235   endif
236 endif
237
238 write_file_contents = '''
239 import os
240 import sys
241
242 assert len(sys.argv) >= 3
243 fname = sys.argv[1]
244 contents = sys.argv[2]
245
246 with open(fname, 'w') as f:
247     f.write(contents)
248 '''
249
250 configure_file(
251   output : 'GstDocumentedSubprojects',
252   command : [python3,
253              '-c', write_file_contents,
254              '@OUTPUT@',
255              documented_projects]
256 )
257
258 if documented_projects != ''
259   gst_doc = subproject('gst-docs', required: get_option('doc').enabled())
260   if gst_doc.found()
261     gst_doc_target = gst_doc.get_variable('gstreamer_doc')
262     alias_target('gst-doc', gst_doc_target)
263   endif
264   message('Gst docs subprojects: ' + documented_projects)
265 endif
266
267 all_plugins_paths = []
268 all_plugins_dirs = []
269 plugins_names = []
270 foreach plugin: all_plugins
271   plugin_path = plugin.get_variable('full_path')
272   all_plugins_paths += plugin_path
273   all_plugins_dirs += fs.parent(plugin_path)
274   plugins_names += plugin_path
275 endforeach
276
277 # Work around meson bug: https://github.com/mesonbuild/meson/pull/6770
278 pathsep = host_machine.system() == 'windows' ? ';' : ':'
279 all_plugins_paths = pathsep.join(all_plugins_paths)
280
281 devenv = environment()
282 if not building_full
283   devenv.prepend('GST_PLUGIN_PATH', all_plugins_dirs)
284 else
285   # Make sure the current build directory is first in PATH so we prefer tools
286   # built here that links on gst-full instead instead of those built in
287   # subprojects.
288   devenv.prepend('PATH', meson.current_build_dir())
289 endif
290 devenv.set('CURRENT_GST', meson.current_source_dir())
291 devenv.set('GST_VERSION', meson.project_version())
292 devenv.set('GST_ENV', 'gst-' + meson.project_version())
293 devenv.set('GST_REGISTRY', meson.current_build_dir() / 'registry.dat')
294 devenv.set('GST_PLUGIN_SYSTEM_PATH', '')
295 meson.add_devenv(devenv)
296
297 generate_plugins_paths = find_program('scripts/generate_plugins_path.py')
298 configure_file(
299   output : 'GstPluginsPath.json',
300   command : [generate_plugins_paths,
301              '@OUTPUT@',
302              all_plugins_paths]
303 )
304
305 if building_full
306   cdata = configuration_data()
307   cdata.set_quoted('GST_API_VERSION', apiversion)
308   cdata.set_quoted('GETTEXT_PACKAGE', 'gstreamer-full-1.0')
309   cdata.set_quoted('PACKAGE_VERSION', gst_version)
310   cdata.set_quoted('GST_PACKAGE_ORIGIN', get_option('package-origin'))
311   configure_file(output : 'config.h', configuration : cdata)
312   configinc = include_directories('.')
313   gst_c_args = ['-DHAVE_CONFIG_H']
314
315   # Generate a .c file which declare and register all built plugins
316   all_plugin_names = ';'.join(plugins_names)
317
318   static_plugins = get_option('gst-full-plugins')
319   if static_plugins == '*'
320     static_plugins = all_plugin_names
321   endif
322   generate_init_static_plugins = find_program('scripts/generate_init_static_plugins.py')
323   init_static_plugins_c = configure_file(
324     output: 'gstinitstaticplugins.c',
325     command : [generate_init_static_plugins,
326                '-o ' + '@OUTPUT@',
327                '-p ' + static_plugins,
328                '-e ' + get_option('gst-full-elements'),
329                '-t ' + get_option('gst-full-typefind-functions'),
330                '-d ' + get_option('gst-full-device-providers'),
331                '-T ' + get_option('gst-full-dynamic-types'),
332                '--giomodules', ';'.join(giomodules),
333                ]
334   )
335
336   gstfull_link_args = cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions'])
337
338   # Get a list of libraries that needs to be exposed in the ABI.
339   exposed_libs = []
340   exposed_deps = []
341   exposed_girs = []
342   incdir_deps = []
343   wanted_libs = ['gstreamer-1.0'] + get_option('gst-full-libraries')
344   all_libs = '*' in wanted_libs
345
346   foreach pkgname_library : all_libraries
347     pkg_name = pkgname_library[0]
348     lib_def = pkgname_library[1]
349
350     if pkg_name in wanted_libs or all_libs
351       if lib_def.has_key('lib')
352         exposed_deps += dependency(pkg_name)
353         incdir_deps += dependency(pkg_name).partial_dependency(includes: true, sources: true)
354         exposed_libs += [lib_def['lib']]
355       endif
356
357       if lib_def.has_key('gir')
358         exposed_girs += lib_def['gir']
359       endif
360     endif
361   endforeach
362
363   # glib and gobject are part of our public API. If we are using glib from the
364   # system then our pkg-config file must require it. If we built it as
365   # subproject then we need to link_whole it.
366   glib_deps = []
367   glib_dep = dependency('glib-2.0')
368   gobject_dep = dependency('gobject-2.0')
369   if gobject_dep.type_name() == 'internal'
370     glib_subproject = subproject('glib')
371     exposed_libs += glib_subproject.get_variable('libglib')
372     exposed_libs += glib_subproject.get_variable('libgobject')
373     incdir_deps += [
374       glib_dep.partial_dependency(includes: true),
375       gobject_dep.partial_dependency(includes: true),
376     ]
377   else
378     glib_deps = [glib_dep, gobject_dep]
379   endif
380
381   link_deps = []
382   if get_option('gst-full-version-script') != ''
383     symbol_map = meson.current_source_dir() / get_option('gst-full-version-script')
384     link_arg = '-Wl,--version-script=' + symbol_map
385     if cc.has_link_argument(link_arg)
386       gstfull_link_args += link_arg
387       link_deps += symbol_map
388     elif cc.get_id() == 'msvc'
389       warning('FIXME: Provide a def file to publish the public symbols')
390     else
391       warning('FIXME: Linker does not support the supplied version script (' + symbol_map + '), please disable the "gst-full-version-script" option')
392     endif
393   endif
394
395   giomodules_deps = []
396   foreach module : giomodules
397     giomodules_deps += dependency(module)
398   endforeach
399
400   # Build both shared and static library
401   gstfull = both_libraries('gstreamer-full-1.0',
402     init_static_plugins_c,
403     link_args: gstfull_link_args,
404     link_whole : exposed_libs,
405     dependencies : [incdir_deps, glib_deps, all_plugins, giomodules_deps],
406     link_depends : link_deps,
407     install : true,
408   )
409
410   gst_full_dep = declare_dependency(link_with: gstfull.get_shared_lib(),
411     dependencies : incdir_deps + glib_deps,
412     include_directories: include_directories('.')
413   )
414
415   gst_full_libs_private = cc.get_supported_link_arguments(['-Wl,--undefined=gst_init_static_plugins'])
416   if gst_full_libs_private == []
417     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.')
418   endif
419
420   if not get_option('introspection').disabled()
421     built_girs = {}
422     foreach gir: exposed_girs
423       includes = []
424       foreach include: gir.get('includes', [])
425         includes += [built_girs.get(include, include)]
426       endforeach
427
428       gir += {
429         'includes': includes,
430         'extra_args': gir.get('extra_args', []) + ['--add-include-path=' + meson.current_build_dir()],
431         'install': true,
432       }
433       built_girs += {gir.get('namespace') + '-' + gir.get('nsversion'): gnome.generate_gir(gstfull, kwargs: gir)[0]}
434     endforeach
435   endif
436
437   pkgconfig.generate(gstfull,
438     requires: glib_deps,
439     libraries_private: gst_full_libs_private,
440     subdirs : 'gstreamer-1.0')
441   meson.override_dependency('gstreamer-full-1.0', gst_full_dep)
442
443   if not get_option('tools').disabled()
444     foreach tool, data: all_tools
445       exe_name = '@0@-@1@'.format(tool, apiversion)
446       extra_args = data.get('extra_c_args', [])
447       sources = data.get('files')
448       install_tag = data.get('install_tag', 'bin')
449       deps = []
450       foreach d : data.get('deps', [])
451         if d not in exposed_deps
452           deps += d
453         endif
454       endforeach
455
456       executable(exe_name,
457         sources,
458         install: true,
459         install_tag: install_tag,
460         include_directories : [configinc],
461         dependencies : [gst_full_dep] + deps,
462         c_args: extra_args + gst_c_args + ['-DG_LOG_DOMAIN="@0@"'.format(exe_name)],
463       )
464
465       if data.has_key('man_page')
466         install_man(data.get('man_page'))
467       endif
468
469     endforeach
470   endif
471 endif
472
473 message('Building subprojects: ' + ', '.join(subprojects_names))
474
475 setenv = find_program('gst-env.py')
476
477 devenv_cmd = [setenv, '--builddir=@0@'.format(meson.global_build_root()),
478               '--srcdir=@0@'.format(meson.global_source_root())]
479
480 subdir('tests')
481 subdir('ci/fuzzing')
482
483 if meson.can_run_host_binaries() and build_machine.system() == 'linux' and host_machine.system() == 'windows'
484   # FIXME: Ideally we could get the wrapper directly from meson
485   devenv_cmd += ['--wine', host_machine.cpu_family() == 'x86_64' ? 'wine64' : 'wine32']
486   sysroot = meson.get_cross_property('sys_root')
487   if sysroot != ''
488     # Logic from meson
489     devenv_cmd += ['--winepath', 'Z:' + join_paths(sysroot, 'bin')]
490   endif
491 endif
492
493 run_target('devenv', command : devenv_cmd)
494
495 if orc_subproject.found() and orc_update_targets.length() > 0
496   alias_target('update-orc-dist', orc_update_targets)
497 endif
498
499 subdir('scripts')
500
501 dotnet_format = find_program('dotnet-format', required: false)
502 if dotnet_format.found()
503     run_target('csharp_format_check',
504         command: [join_paths(meson.current_source_dir(), 'scripts', 'format-csharp'),
505             '--check'
506         ],
507     )
508     run_target('csharp_format_apply',
509         command: [join_paths(meson.current_source_dir(), 'scripts', 'format-csharp'),
510         ],
511     )
512 endif
513
514 summary({
515   'gstreamer-full library': building_full,
516 }, section: 'Build options', bool_yn: true, list_sep: '  ')
517
518 gst_tools = []
519 foreach tool, data: all_tools
520   gst_tools += tool
521 endforeach
522
523 summary({
524     'Tools': gst_tools,
525 }, section: 'Build options', list_sep: ', ')