meson: Fix libav checks to use feature options correctly
[platform/upstream/gstreamer.git] / meson.build
1 project('All GStreamer modules', 'c',
2   version : '1.15.0.1',
3   meson_version : '>= 0.47.0',
4   default_options : ['buildtype=debugoptimized'])
5
6 gst_version = '>= @0@'.format(meson.project_version())
7 gst_branch = 'master'
8
9 glib_req = '>= 2.40.0'
10
11 build_system = build_machine.system()
12 cc = meson.get_compiler('c')
13
14 # Make it possible to use msys2 built zlib which fails
15 # when not using the mingw toolchain as it uses unistd.h
16 if not meson.is_subproject() and cc.get_id() == 'msvc'
17   uname = find_program('uname', required: false)
18   if uname.found()
19     ret = run_command(uname, '-o')
20     if ret.returncode() == 0 and ret.stdout().to_lower() == 'msys'
21       ret = run_command(uname, '-r')
22       # The kernel version returned by uname is actually the msys version
23       if ret.returncode() == 0 and ret.stdout().startswith('2')
24         # If a system zlib is found, disable UNIX features in zlib.h and zconf.h
25         if cc.find_library('z').found()
26           add_global_arguments('-DZ_SOLO', language: 'c')
27         endif
28       endif
29     endif
30   endif
31 endif
32
33 libav_opt = get_option('libav')
34 libav_deps = [dependency('libavfilter', version: '>= 7.16.100',
35               fallback: ['FFmpeg', 'libavfilter_dep'], required: libav_opt)]
36 if libav_deps[0].found() and libav_deps[0].type_name() != 'internal'
37   cc = meson.get_compiler('c')
38   check_ffmpeg_src = '''#include <libavcodec/avcodec.h>
39   #if LIBAVCODEC_VERSION_MICRO >= 100
40   /* FFmpeg uses 100+ as its micro version */
41   #else
42   #error libav provider should be FFmpeg
43   #endif'''
44   if not cc.compiles(check_ffmpeg_src, dependencies : libav_deps, name : 'whether libav is provided by FFmpeg')
45     message('WARNING: gst-libav not built as ffmpeg n3.1.2 not found on the system')
46     libav_deps += [disabler()]
47   endif
48 endif
49
50 if add_languages('cs', required : get_option('sharp'))
51   sharp_deps = []
52 else
53   sharp_deps = [disabler()]
54 endif
55
56 python_opt = get_option('python')
57 vaapi_opt = get_option('vaapi')
58 devtools_opt = get_option('devtools')
59 ges_opt = get_option('ges')
60 subprojects = {
61     'gstreamer': {},
62     'gst-plugins-base': {},
63     'gst-plugins-good': {},
64     'gst-plugins-bad': { 'option': get_option('bad') },
65     'gst-plugins-ugly': { 'option': get_option('ugly') },
66     'gst-python': { 'option': python_opt, 'dependencies': [dependency('pygobject-3.0', required : python_opt)] },
67     'gst-omx': { 'option': get_option('omx'), },
68     'gst-libav': { 'option': get_option('libav'), 'dependencies': libav_deps},
69     'gstreamer-vaapi': {
70       'option': vaapi_opt,
71       'dependencies': [dependency('libva', version: ['>= 0.30.4', '!= 0.99.0'], required : vaapi_opt)]
72     },
73     'gst-devtools': {
74       'option': devtools_opt,
75       'dependencies': [dependency('json-glib-1.0', required: devtools_opt)],
76     },
77     'gst-editing-services': { 'option': ges_opt, 'dependencies': [dependency('libxml-2.0', required : ges_opt)] },
78     'gst-rtsp-server': { 'option': get_option('rtsp_server') },
79     'gstreamer-sharp': { 'option': get_option('sharp'), 'dependencies': sharp_deps },
80 }
81
82 python3 = import('python3').find_python()
83 symlink = '''
84 import os
85
86 os.symlink(os.path.join('@1@', 'subprojects', '@0@'),
87   os.path.join('@1@', '@0@'))
88 '''
89
90 # On Windows, if flex/bison aren't found, we use a subproject to get them
91 flex = find_program('flex', 'win_flex', required : build_system != 'windows')
92 bison = find_program('bison', 'win_bison', required : build_system != 'windows')
93 if not flex.found() or not bison.found()
94   subproject('win-flex-bison-binaries')
95 endif
96
97 subprojects_names = []
98 foreach project_name, build_infos: subprojects
99     build = true
100     if build_infos.has_key('option')
101       build = not build_infos.get('option').disabled()
102       if build
103         foreach dep: build_infos.get('dependencies', [])
104           if dep.found() == false
105             warning('@0@ dependency @1@ not found - NOT BUILDING'.format(project_name, dep))
106             build = false
107           endif
108         endforeach
109       endif
110     endif
111
112     if build
113       subprojects_names += [project_name]
114       subproject(project_name, version: gst_version)
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     endif
120 endforeach
121
122 foreach custom_subproj: get_option('custom_subprojects').split(',')
123     if custom_subproj != ''
124         message ('Adding custom subproject ' + custom_subproj)
125         subproject(custom_subproj)
126         subprojects_names += [custom_subproj]
127     endif
128 endforeach
129
130 message('Building subprojects: ' + ', '.join(subprojects_names))
131
132 setenv = find_program('gst-uninstalled.py')
133 run_target('uninstalled', command : [setenv, '--builddir=@0@'.format(meson.build_root()),
134            '--srcdir=@0@'.format(meson.source_root())])
135
136 update = find_program('git-update')
137 run_target('git-update', command : [update])
138 run_target('update', command : [update,
139     '--builddir=@0@'.format(meson.current_build_dir())])