meson: Add qt5 feature
[platform/upstream/gstreamer.git] / meson.build
1 project('All GStreamer modules', 'c',
2   version : '1.19.0.1',
3   meson_version : '>= 0.52.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 documented_projects = ''
28 # Make it possible to use msys2 built zlib which fails
29 # when not using the mingw toolchain as it uses unistd.h
30 if not meson.is_subproject() and cc.get_id() == 'msvc'
31   uname = find_program('uname', required: false)
32   if uname.found()
33     ret = run_command(uname, '-o')
34     if ret.returncode() == 0 and ret.stdout().to_lower() == 'msys'
35       ret = run_command(uname, '-r')
36       # The kernel version returned by uname is actually the msys version
37       if ret.returncode() == 0 and ret.stdout().startswith('2')
38         # If a system zlib is found, disable UNIX features in zlib.h and zconf.h
39         if cc.find_library('z').found()
40           add_global_arguments('-DZ_SOLO', language: 'c')
41         endif
42       endif
43     endif
44   endif
45
46   # Change some warning which belong to level 3 (production quality) or
47   # 4 (informational) to level 1 (severe)
48   add_global_arguments (
49       '/w14062', # enumerator 'identifier' in switch of enum 'enumeration' is not handled
50       '/w14101', # 'identifier' : unreferenced local variable
51       '/w14189', # 'identifier' : local variable is initialized but not referenced
52       cc.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8
53       language: ['c', 'cpp'])
54 endif
55
56 # Ordered list of subprojects (dict has no ordering guarantees)
57 subprojects = [
58   ['gstreamer', {'build-hotdoc': true}],
59   ['gst-plugins-base', {'build-hotdoc': true}],
60   ['gst-plugins-good', {'build-hotdoc': true}],
61   ['libnice', { 'option': get_option('libnice'), 'match_gst_version': false}],
62   ['gst-plugins-bad', { 'option': get_option('bad'), 'build-hotdoc': true}],
63   ['gst-plugins-ugly', { 'option': get_option('ugly'), 'build-hotdoc': true}],
64   ['gst-libav', { 'option': get_option('libav'), 'build-hotdoc': true}],
65   ['gst-rtsp-server', { 'option': get_option('rtsp_server'), 'build-hotdoc': true}],
66   ['gst-devtools', { 'option': get_option('devtools'), 'build-hotdoc': true }],
67   ['gst-integration-testsuites', { 'option': get_option('devtools') }],
68   ['gst-editing-services', { 'option': get_option('ges'), 'build-hotdoc': true}],
69   ['gstreamer-vaapi', { 'option': get_option('vaapi'), 'build-hotdoc': true}],
70   ['gst-omx', { 'option': get_option('omx'), 'build-hotdoc': true}],
71   ['gstreamer-sharp', { 'option': get_option('sharp') }],
72   ['pygobject', { 'option': get_option('python'), 'match_gst_version': false }],
73   ['gst-python', { 'option': get_option('python')}],
74   ['gst-examples', { 'option': get_option('gst-examples'), 'match_gst_versions': false}],
75   ['gst-plugins-rs', { 'option': get_option('rs'), 'match_gst_version': false}],
76 ]
77
78 symlink = '''
79 import os
80
81 os.symlink(os.path.join('@1@', 'subprojects', '@0@'),
82   os.path.join('@1@', '@0@'))
83 '''
84
85 if build_system == 'windows'
86   subproject('win-flex-bison-binaries')
87   subproject('win-nasm')
88 endif
89
90 orc_subproject = subproject('orc', required: get_option('orc'))
91
92 subprojects_names = []
93 plugins_doc_caches = []
94 orc_update_targets = []
95 all_plugins = []
96 foreach sp : subprojects
97   project_name = sp[0]
98   build_infos = sp[1]
99   is_required = build_infos.get('option', true)
100   match_gst_version = build_infos.get('match_gst_version', true)
101
102   if match_gst_version
103     subproj = subproject(project_name, version: gst_version, required: is_required)
104   else
105     subproj = subproject(project_name, required: is_required)
106   endif
107
108   if subproj.found()
109     plugins = subproj.get_variable('plugins', [])
110     all_plugins += plugins
111
112     orc_update_targets += subproj.get_variable('orc_update_targets', [])
113
114     subprojects_names += [project_name]
115     cmdres = run_command(python3, '-c', symlink.format(project_name, meson.current_source_dir()))
116     if cmdres.returncode() == 0
117       message('Created symlink to ' + project_name)
118     endif
119
120     if not meson.is_cross_build() and build_infos.get('build-hotdoc', false)
121       if plugins.length() > 0
122         plugins_doc_caches += [subproj.get_variable('plugins_doc_dep')]
123       endif
124       if documented_projects != ''
125         documented_projects += ','
126       endif
127       documented_projects  += project_name
128     endif
129   endif
130 endforeach
131
132 # Check if we need to also build glib-networking for TLS modules
133 glib_dep = dependency('glib-2.0')
134 if glib_dep.type_name() == 'internal'
135   subproject('glib-networking', required : get_option('tls'),
136              default_options: ['gnutls=auto', 'openssl=auto'])
137 endif
138
139 plugins_doc_dep = custom_target('plugins-doc-cache',
140   command: [python3, '-c', 'print("Built all doc caches")'],
141   input: plugins_doc_caches,
142   output: 'plugins_doc_caches',
143   capture: true,
144 )
145
146 foreach custom_subproj: get_option('custom_subprojects').split(',')
147     if custom_subproj != ''
148         message ('Adding custom subproject ' + custom_subproj)
149         subproject(custom_subproj)
150         subprojects_names += [custom_subproj]
151     endif
152 endforeach
153
154 if meson.is_cross_build() or build_machine.system() == 'windows'
155     if get_option('doc').enabled()
156         error('Documentation enabled but building the doc while cross building or building on windows is not supported yet.')
157     endif
158
159     documented_projects = ''
160     message('Documentation not built as building the documentation while cross building or building on windows is not supported yet.')
161 else
162   hotdoc_p = find_program('hotdoc', required : get_option('doc'))
163   if not hotdoc_p.found()
164     documented_projects = ''
165     message('Not building documentation as hotdoc was not found')
166   endif
167 endif
168
169 write_file_contents = '''
170 import os
171 import sys
172
173 assert len(sys.argv) >= 3
174 fname = sys.argv[1]
175 contents = sys.argv[2]
176
177 with open(fname, 'w') as f:
178     f.write(contents)
179 '''
180
181 configure_file(
182   output : 'GstDocumentedSubprojects',
183   command : [python3,
184              '-c', write_file_contents,
185              '@OUTPUT@',
186              documented_projects]
187 )
188
189 if documented_projects != ''
190   subproject('gst-docs', required: get_option('doc').enabled())
191   message('Gst docs subprojects: ' + documented_projects)
192 endif
193
194 all_plugins_paths = []
195 foreach plugin: all_plugins
196   all_plugins_paths += plugin.full_path()
197 endforeach
198 # Work around meson bug: https://github.com/mesonbuild/meson/pull/6770
199 pathsep = host_machine.system() == 'windows' ? ';' : ':'
200 all_plugins_paths = pathsep.join(all_plugins_paths)
201
202 generate_plugins_paths = find_program('scripts/generate_plugins_path.py')
203 configure_file(
204   output : 'GstPluginsPath.json',
205   command : [generate_plugins_paths,
206              '@OUTPUT@',
207              all_plugins_paths]
208 )
209
210 # FIXME: Create a 'libraries' list in each subproject like we do for 'plugins'
211 libraries_map = {
212   # name: [subproject_name, variable_name]
213   'gstreamer': ['gstreamer', 'libgst'],
214   'base': ['gstreamer', 'gst_base'],
215   'check': ['gstreamer', 'gst_check'],
216   'controller': ['gstreamer', 'gst_controller'],
217   'net': ['gstreamer', 'gst_net'],
218
219   'allocators': ['gst-plugins-base', 'gstallocators'],
220   'app': ['gst-plugins-base', 'gstapp'],
221   'audio': ['gst-plugins-base', 'gstaudio'],
222   'fft': ['gst-plugins-base', 'gstfft'],
223   'pbutils': ['gst-plugins-base', 'pbutils'],
224   'riff': ['gst-plugins-base', 'gstriff'],
225   'rtp': ['gst-plugins-base', 'gst_rtp'],
226   'rtsp': ['gst-plugins-base', 'gst_rtsp'],
227   'sdp': ['gst-plugins-base', 'gstsdp'],
228   'tag': ['gst-plugins-base', 'gsttag'],
229   'video': ['gst-plugins-base', 'gstvideo'],
230   'gl': ['gst-plugins-base', 'gstgl'],
231
232   'bad-audio': ['gst-plugins-bad', 'gstbadaudio'],
233   'bad-transcoder': ['gst-plugins-bad', 'gst_transcoder'],
234   'codecparsers': ['gst-plugins-bad', 'gstcodecparsers'],
235   'insertbin': ['gst-plugins-bad', 'gstinsertbin'],
236   'mpegts': ['gst-plugins-bad', 'gstmpegts'],
237   'player': ['gst-plugins-bad', 'gstplayer'],
238   'sctp': ['gst-plugins-bad', 'libgstsctp'],
239   'webrtc': ['gst-plugins-bad', 'gstwebrtc'],
240   'vulkan': ['gst-plugins-bad', 'gstvulkan'],
241
242   'rtsp-server': ['gst-rtsp-server', 'gst_rtsp_server'],
243 }
244
245 if get_option('default_library') == 'static'
246   # Generate a .c file which declare and register all built plugins
247   generate_init_static_plugins = find_program('scripts/generate_init_static_plugins.py')
248   init_static_plugins_c = configure_file(
249     output: 'gstinitstaticplugins.c',
250     command : [generate_init_static_plugins,
251                '@OUTPUT@',
252                all_plugins_paths]
253   )
254   install_headers('gstinitstaticplugins.h', subdir : 'gstreamer-1.0/gst')
255
256   # Avoid a x264 link issue described here: https://gitlab.freedesktop.org/gstreamer/gst-build/-/issues/108
257   # Similar issue has been found with VLC: https://mailman.videolan.org/pipermail/vlc-devel/2009-March/057640.html
258   gstfull_link_args = []
259   if cc.has_link_argument('-Wl,-Bsymbolic')
260     gstfull_link_args += ['-Wl,-Bsymbolic']
261   endif
262
263
264   gst_dep = subproject('gstreamer').get_variable('gst_dep')
265
266   # Get a list of libraries that needs to be exposed in the ABI.
267   exposed_libs = []
268   foreach name : get_option('gst-full-libraries') + ['gstreamer']
269     info = libraries_map[name]
270     exposed_libs += subproject(info[0]).get_variable(info[1])
271   endforeach
272
273   # glib and gobject are part of our public API. If we are using glib from the
274   # system then our pkg-config file must require it. If we built it as
275   # subproject then we need to link_whole it.
276   requires = []
277   gobject_dep = dependency('gobject-2.0', fallback: ['glib', 'libgobject_dep'])
278   if gobject_dep.type_name() == 'internal'
279       glib_subproject = subproject('glib')
280       exposed_libs += glib_subproject.get_variable('libglib')
281       exposed_libs += glib_subproject.get_variable('libgobject')
282   else
283       requires = ['glib-2.0', 'gobject-2.0']
284   endif
285
286   # Build both shared and static library
287   gstfull = both_libraries('gstreamer-full-1.0',
288     init_static_plugins_c,
289     link_with : all_plugins,
290     link_args: gstfull_link_args,
291     link_whole : exposed_libs,
292     dependencies : gst_dep,
293     install : true,
294   )
295   pkgconfig.generate(gstfull,
296     requires: requires,
297     subdirs : 'gstreamer-1.0')
298 endif
299
300 message('Building subprojects: ' + ', '.join(subprojects_names))
301 setenv = find_program('gst-env.py')
302
303 devenv_cmd = [setenv, '--builddir=@0@'.format(meson.build_root()),
304               '--srcdir=@0@'.format(meson.source_root())]
305
306 if meson.has_exe_wrapper() and build_machine.system() == 'linux' and host_machine.system() == 'windows'
307   # FIXME: Ideally we could get the wrapper directly from meson
308   devenv_cmd += ['--wine', host_machine.cpu_family() == 'x86_64' ? 'wine64' : 'wine32']
309   sysroot = meson.get_cross_property('sys_root')
310   if sysroot != ''
311     # Logic from meson
312     devenv_cmd += ['--winepath', 'Z:' + join_paths(sysroot, 'bin')]
313   endif
314 endif
315
316 run_target('uninstalled', command : devenv_cmd)
317 run_target('devenv', command : devenv_cmd)
318
319 update = find_program('git-update')
320 run_target('git-update', command : [update])
321 run_target('update', command : [update,
322     '--builddir=@0@'.format(meson.current_build_dir())])
323
324 if orc_subproject.found() and orc_update_targets.length() > 0
325   alias_target('update-orc-dist', orc_update_targets)
326 endif