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