subprojects: add libdrm wrap
[platform/upstream/gstreamer.git] / meson.build
1 project('All GStreamer modules', 'c',
2   version : '1.17.0.1',
3   meson_version : '>= 0.48.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, 'has-plugins': true}],
59   ['gst-plugins-base', {'build-hotdoc': true, 'has-plugins': true}],
60   ['gst-plugins-good', {'build-hotdoc': true, 'has-plugins': true}],
61   ['libnice', { 'option': get_option('libnice'), 'match_gst_version': false}],
62   ['gst-plugins-bad', { 'option': get_option('bad'), 'build-hotdoc': true, 'has-plugins': true}],
63   ['gst-plugins-ugly', { 'option': get_option('ugly'), 'build-hotdoc': true, 'has-plugins': true}],
64   ['gst-libav', { 'option': get_option('libav'), 'build-hotdoc': true, 'has-plugins': 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, 'has-plugins': true}],
69   ['gstreamer-vaapi', { 'option': get_option('vaapi'), 'build-hotdoc': true, 'has-plugins': true}],
70   ['gst-omx', { 'option': get_option('omx'), 'build-hotdoc': true, 'has-plugins': 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'), 'has-plugins': true}],
74   ['gst-examples', { 'option': get_option('gst-examples'), 'match_gst_versions': false}],
75   ['gst-plugins-rs', { 'option': get_option('rs'), 'has-plugins': true, '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 subproject('orc', required: get_option('orc'))
91
92 subprojects_names = []
93 plugins_doc_caches = []
94 all_plugins = []
95 foreach sp : subprojects
96   project_name = sp[0]
97   build_infos = sp[1]
98   is_required = build_infos.get('option', true)
99   match_gst_version = build_infos.get('match_gst_version', true)
100
101   if match_gst_version
102     subproj = subproject(project_name, version: gst_version, required: is_required)
103   else
104     subproj = subproject(project_name, required: is_required)
105   endif
106
107   if subproj.found()
108     # Replace by using subproject.get_variable('plugins', [])
109     # when https://github.com/mesonbuild/meson/pull/5426/files
110     # is merged and released
111     if build_infos.get('has-plugins', false)
112       plugins = subproj.get_variable('plugins')
113     else
114       plugins = []
115     endif
116     all_plugins += plugins
117
118     subprojects_names += [project_name]
119     cmdres = run_command(python3, '-c', symlink.format(project_name, meson.current_source_dir()))
120     if cmdres.returncode() == 0
121       message('Created symlink to ' + project_name)
122     endif
123
124     if not meson.is_cross_build() and build_infos.get('build-hotdoc', false)
125       if plugins.length() > 0
126         plugins_doc_caches += [subproj.get_variable('plugins_doc_dep')]
127       endif
128       if documented_projects != ''
129         documented_projects += ','
130       endif
131       documented_projects  += project_name
132     endif
133   endif
134 endforeach
135
136 plugins_doc_dep = custom_target('plugins-doc-cache',
137   command: [python3, '-c', 'print("Built all doc caches")'],
138   input: plugins_doc_caches,
139   output: 'plugins_doc_caches',
140   capture: true,
141 )
142
143 foreach custom_subproj: get_option('custom_subprojects').split(',')
144     if custom_subproj != ''
145         message ('Adding custom subproject ' + custom_subproj)
146         subproject(custom_subproj)
147         subprojects_names += [custom_subproj]
148     endif
149 endforeach
150
151 if meson.is_cross_build() or build_machine.system() == 'windows'
152     if get_option('doc').enabled()
153         error('Documentation enabled but building the doc while cross building or building on windows is not supported yet.')
154     endif
155
156     message('Documentation not built as building the documentation while cross building or building on windows is not supported yet.')
157 else
158   hotdoc_p = find_program('hotdoc', required : get_option('doc'))
159   if hotdoc_p.found()
160     if documented_projects != ''
161         subproject('gst-docs', default_options: 'built_subprojects=' + documented_projects)
162       message('Gst docs subprojects: ' + documented_projects)
163     endif
164   else
165     message('Not building documentation as hotdoc was not found')
166   endif
167 endif
168
169 all_plugins_paths = []
170 foreach plugin: all_plugins
171   all_plugins_paths += plugin.full_path()
172 endforeach
173 # Work around meson bug: https://github.com/mesonbuild/meson/pull/6770
174 pathsep = host_machine.system() == 'windows' ? ';' : ':'
175 all_plugins_paths = pathsep.join(all_plugins_paths)
176
177 generate_plugins_paths = find_program('scripts/generate_plugins_path.py')
178 configure_file(
179   output : 'GstPluginsPath.json',
180   command : [generate_plugins_paths,
181              '@OUTPUT@',
182              all_plugins_paths]
183 )
184
185 # FIXME: Create a 'libraries' list in each subproject like we do for 'plugins'
186 libraries_map = {
187   # name: [subproject_name, variable_name]
188   'gstreamer': ['gstreamer', 'libgst'],
189   'base': ['gstreamer', 'gst_base'],
190   'check': ['gstreamer', 'gst_check'],
191   'controller': ['gstreamer', 'gst_controller'],
192   'net': ['gstreamer', 'gst_net'],
193
194   'allocators': ['gst-plugins-base', 'gstallocators'],
195   'app': ['gst-plugins-base', 'gstapp'],
196   'audio': ['gst-plugins-base', 'gstaudio'],
197   'fft': ['gst-plugins-base', 'gstfft'],
198   'pbutils': ['gst-plugins-base', 'pbutils'],
199   'riff': ['gst-plugins-base', 'gstriff'],
200   'rtp': ['gst-plugins-base', 'gst_rtp'],
201   'rtsp': ['gst-plugins-base', 'gst_rtsp'],
202   'sdp': ['gst-plugins-base', 'gstsdp'],
203   'tag': ['gst-plugins-base', 'gsttag'],
204   'video': ['gst-plugins-base', 'gstvideo'],
205   'gl': ['gst-plugins-base', 'gstgl'],
206
207   'bad-audio': ['gst-plugins-bad', 'gstbadaudio'],
208   'bad-transcoder': ['gst-plugins-bad', 'gst_transcoder'],
209   'codecparsers': ['gst-plugins-bad', 'gstcodecparsers'],
210   'insertbin': ['gst-plugins-bad', 'gstinsertbin'],
211   'mpegts': ['gst-plugins-bad', 'gstmpegts'],
212   'player': ['gst-plugins-bad', 'gstplayer'],
213   'sctp': ['gst-plugins-bad', 'libgstsctp'],
214   'webrtc': ['gst-plugins-bad', 'gstwebrtc'],
215   'vulkan': ['gst-plugins-bad', 'gstvulkan'],
216
217   'rtsp-server': ['gst-rtsp-server', 'gst_rtsp_server'],
218 }
219
220 if get_option('default_library') == 'static'
221   # Generate a .c file which declare and register all built plugins
222   generate_init_static_plugins = find_program('scripts/generate_init_static_plugins.py')
223   init_static_plugins_c = configure_file(
224     output: 'gstinitstaticplugins.c',
225     command : [generate_init_static_plugins,
226                '@OUTPUT@',
227                all_plugins_paths]
228   )
229   install_headers('gstinitstaticplugins.h', subdir : 'gstreamer-1.0/gst')
230
231   gst_dep = subproject('gstreamer').get_variable('gst_dep')
232
233   # Get a list of libraries that needs to be exposed in the ABI.
234   exposed_libs = []
235   foreach name : get_option('gst-full-libraries') + ['gstreamer']
236     info = libraries_map[name]
237     exposed_libs += subproject(info[0]).get_variable(info[1])
238   endforeach
239
240   # glib and gobject are part of our public API. If we are using glib from the
241   # system then our pkg-config file must require it. If we built it as
242   # subproject then we need to link_whole it.
243   requires = []
244   gobject_dep = dependency('gobject-2.0', fallback: ['glib', 'libgobject_dep'])
245   if gobject_dep.type_name() == 'internal'
246       glib_subproject = subproject('glib')
247       exposed_libs += glib_subproject.get_variable('libglib')
248       exposed_libs += glib_subproject.get_variable('libgobject')
249   else
250       requires = ['glib-2.0', 'gobject-2.0']
251   endif
252
253   # Build both shared and static library
254   gstfull = both_libraries('gstreamer-full-1.0',
255     init_static_plugins_c,
256     link_with : all_plugins,
257     link_whole : exposed_libs,
258     dependencies : gst_dep,
259     install : true,
260   )
261   pkgconfig.generate(gstfull,
262     requires: requires,
263     subdirs : 'gstreamer-1.0')
264 endif
265
266 message('Building subprojects: ' + ', '.join(subprojects_names))
267 setenv = find_program('gst-env.py')
268
269 devenv_cmd = [setenv, '--builddir=@0@'.format(meson.build_root()),
270               '--srcdir=@0@'.format(meson.source_root())]
271
272 if meson.has_exe_wrapper() and build_machine.system() == 'linux' and host_machine.system() == 'windows'
273   # FIXME: Ideally we could get the wrapper directly from meson
274   devenv_cmd += ['--wine', host_machine.cpu_family() == 'x86_64' ? 'wine64' : 'wine32']
275   sysroot = meson.get_cross_property('sys_root')
276   if sysroot != ''
277     # Logic from meson
278     devenv_cmd += ['--winepath', 'Z:' + join_paths(sysroot, 'bin')]
279   endif
280 endif
281
282 run_target('uninstalled', command : devenv_cmd)
283 run_target('devenv', command : devenv_cmd)
284
285 update = find_program('git-update')
286 run_target('git-update', command : [update])
287 run_target('update', command : [update,
288     '--builddir=@0@'.format(meson.current_build_dir())])