Release 1.18.0
[platform/upstream/gst-editing-services.git] / meson.build
1 project('gst-editing-services', 'c',
2   version : '1.18.0',
3   meson_version : '>= 0.49',
4   default_options : [ 'warning_level=1',
5                       'buildtype=debugoptimized' ])
6
7 gst_version = meson.project_version()
8 version_arr = gst_version.split('.')
9 gst_version = meson.project_version()
10 version_arr = gst_version.split('.')
11 gst_version_major = version_arr[0].to_int()
12 gst_version_minor = version_arr[1].to_int()
13 gst_version_micro = version_arr[2].to_int()
14  if version_arr.length() == 4
15   gst_version_nano = version_arr[3].to_int()
16 else
17   gst_version_nano = 0
18 endif
19
20 apiversion = '1.0'
21 soversion = 0
22 # maintaining compatibility with the previous libtool versioning
23 # current = minor * 100 + micro
24 curversion = gst_version_minor * 100 + gst_version_micro
25 libversion = '@0@.@1@.0'.format(soversion, curversion)
26 osxversion = curversion + 1
27
28 glib_req = '>= 2.44.0'
29 gst_req = '>= @0@.@1@.0'.format(gst_version_major, gst_version_minor)
30
31 cc = meson.get_compiler('c')
32 mathlib = cc.find_library('m', required : false)
33
34 cdata = configuration_data()
35
36 prefix = get_option('prefix')
37 datadir = prefix / get_option('datadir')
38
39 # Ignore several spurious warnings for things gstreamer does very commonly
40 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
41 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
42 # NOTE: Only add warnings here if you are sure they're spurious
43 if cc.get_id() == 'msvc'
44   add_project_arguments(
45       '/wd4018', # implicit signed/unsigned conversion
46       '/wd4146', # unary minus on unsigned (beware INT_MIN)
47       '/wd4244', # lossy type conversion (e.g. double -> int)
48       '/wd4305', # truncating type conversion (e.g. double -> float)
49       language : 'c')
50 endif
51
52 if cc.has_link_argument('-Wl,-Bsymbolic-functions')
53   add_project_link_arguments('-Wl,-Bsymbolic-functions', language : 'c')
54 endif
55
56 # Symbol visibility
57 if cc.get_id() == 'msvc'
58   export_define = '__declspec(dllexport) extern'
59 elif cc.has_argument('-fvisibility=hidden')
60   add_project_arguments('-fvisibility=hidden', language: 'c')
61   export_define = 'extern __attribute__ ((visibility ("default")))'
62 else
63   export_define = 'extern'
64 endif
65
66 # Passing this through the command line would be too messy
67 cdata.set('GST_API_EXPORT', export_define)
68
69 # Disable strict aliasing
70 if cc.has_argument('-fno-strict-aliasing')
71   add_project_arguments('-fno-strict-aliasing', language: 'c')
72 endif
73
74 cdata.set('VERSION', '"@0@"'.format(gst_version))
75 cdata.set('PACKAGE', '"gst-editing-services"')
76 cdata.set('PACKAGE_VERSION', '"@0@"'.format(gst_version))
77 cdata.set('PACKAGE_BUGREPORT', '"https://gitlab.freedesktop.org/gstreamer/gst-editing-services/issues/new"')
78 cdata.set('PACKAGE_NAME', '"GStreamer Editing Services"')
79 cdata.set('GST_PACKAGE_NAME', '"GStreamer Editing Services"')
80 cdata.set('GST_PACKAGE_ORIGIN', '"Unknown package origin"')
81 cdata.set('GST_LICENSE', '"LGPL"')
82
83 # Mandatory GST deps
84 gst_dep = dependency('gstreamer-' + apiversion, version : gst_req,
85     fallback : ['gstreamer', 'gst_dep'])
86 gstpbutils_dep = dependency('gstreamer-pbutils-' + apiversion, version : gst_req,
87     fallback : ['gst-plugins-base', 'pbutils_dep'])
88 gstvideo_dep = dependency('gstreamer-video-' + apiversion, version : gst_req,
89     fallback : ['gst-plugins-base', 'video_dep'])
90 gstaudio_dep = dependency('gstreamer-audio-' + apiversion, version : gst_req,
91     fallback : ['gst-plugins-base', 'audio_dep'])
92 gstbase_dep = dependency('gstreamer-base-1.0', version : gst_req,
93     fallback : ['gstreamer', 'gst_base_dep'])
94 if host_machine.system() != 'windows'
95   gstcheck_dep = dependency('gstreamer-check-1.0', version : gst_req,
96     required : get_option('tests'),
97     fallback : ['gstreamer', 'gst_check_dep'])
98 endif
99 gstcontroller_dep = dependency('gstreamer-controller-1.0', version : gst_req,
100   fallback : ['gstreamer', 'gst_controller_dep'])
101 gstvalidate_dep = dependency('gst-validate-1.0', version : gst_req, required : get_option('validate'),
102   fallback : ['gst-devtools', 'validate_dep'])
103
104 gio_dep = dependency('gio-2.0', fallback: ['glib', 'libgio_dep'])
105 libxml_dep = dependency('libxml-2.0', required: get_option('xptv'))
106 cdata.set('DISABLE_XPTV', not libxml_dep.found())
107
108 # TODO Properly port to Gtk 3
109 # gtk_dep = dependency('gtk+-3.0', required : false)
110
111 libges_deps = [gst_dep, gstbase_dep, gstvideo_dep, gstpbutils_dep,
112                gstcontroller_dep, gio_dep, libxml_dep, mathlib]
113
114 if gstvalidate_dep.found()
115     libges_deps = libges_deps + [gstvalidate_dep]
116     cdata.set('HAVE_GST_VALIDATE', 1)
117 endif
118
119 gir = find_program('g-ir-scanner', required : get_option('introspection'))
120 gnome = import('gnome')
121
122 # Fixme, not very elegant.
123 build_gir = gir.found() and (not meson.is_cross_build() or get_option('introspection').enabled())
124 gir_init_section = [ '--add-init-section=' + \
125     'extern void gst_init(gint*,gchar**);' + \
126     'extern void ges_init(void);' + \
127     'g_setenv("GST_REGISTRY_1.0", "/no/way/this/exists.reg", TRUE);' + \
128     'g_setenv("GST_PLUGIN_PATH_1_0", "", TRUE);' + \
129     'g_setenv("GST_PLUGIN_SYSTEM_PATH_1_0", "", TRUE);' + \
130     'g_setenv("GST_DEBUG", "0", TRUE);' + \
131     'gst_init(NULL,NULL);' + \
132     'ges_init();', '--quiet']
133
134 has_python = false
135 if build_gir
136   pymod = import('python')
137   python = pymod.find_installation(required: get_option('python'))
138   if python.found()
139     # Workaround for https://github.com/mesonbuild/meson/issues/5629
140     pythonver = python.language_version()
141     python_dep = dependency('python-@0@-embed'.format(pythonver), version: '>=3', required: false)
142     if not python_dep.found()
143       python_dep = python.dependency(required : get_option('python'))
144     endif
145   else
146     python_dep = dependency('', required: false)
147   endif
148   if python_dep.found()
149     python_abi_flags = python.get_variable('ABIFLAGS', '')
150     pylib_loc = get_option('libpython-dir')
151
152     error_msg = ''
153     if not cc.compiles('#include <Python.h>', dependencies: [python_dep])
154       error_msg = 'Could not compile a simple program against python'
155     elif pylib_loc == ''
156       check_path_exists = 'import os, sys; assert(os.path.exists(sys.argv[1]))'
157       pylib_loc = python.get_variable('LIBPL', '')
158       if host_machine.system() != 'windows' and host_machine.system() != 'darwin'
159         pylib_ldlibrary = python.get_variable('LDLIBRARY', '')
160         if run_command(python, '-c', check_path_exists, join_paths(pylib_loc, pylib_ldlibrary)).returncode() != 0
161           # Workaround for Fedora
162           pylib_loc = python.get_variable('LIBDIR', '')
163           message('pylib_loc = @0@'.format(pylib_loc))
164         endif
165
166         res = run_command(python, '-c', check_path_exists, join_paths(pylib_loc, pylib_ldlibrary))
167         if res.returncode() != 0
168           error_msg = '@0@ doesn\' exist, can\'t use python'.format(join_paths(pylib_loc, pylib_ldlibrary))
169         endif
170       endif
171       if error_msg == ''
172         pylib_suffix = 'so'
173         if host_machine.system() == 'windows'
174           pylib_suffix = 'dll'
175         elif host_machine.system() == 'darwin'
176           pylib_suffix = 'dylib'
177         endif
178
179         gmodule_dep = dependency('gmodule-2.0')
180         libges_deps = libges_deps + [python_dep, gmodule_dep]
181         has_python = true
182         message('python_abi_flags = @0@'.format(python_abi_flags))
183         message('pylib_loc = @0@'.format(pylib_loc))
184         cdata.set('HAS_PYTHON', true)
185         cdata.set('PY_LIB_LOC', '"@0@"'.format(pylib_loc))
186         cdata.set('PY_ABI_FLAGS', '"@0@"'.format(python_abi_flags))
187         cdata.set('PY_LIB_SUFFIX', '"@0@"'.format(pylib_suffix))
188         cdata.set('PYTHON_VERSION', '"@0@"'.format(python_dep.version()))
189       else
190           if get_option('python').enabled()
191             error(error_msg)
192           else
193             message(error_msg)
194           endif
195       endif
196     endif
197   endif
198 endif
199
200 ges_c_args = ['-DHAVE_CONFIG_H', '-DG_LOG_DOMAIN="GES"']
201 plugins_install_dir = '@0@/gstreamer-1.0'.format(get_option('libdir'))
202
203 pkgconfig = import('pkgconfig')
204 plugins_pkgconfig_install_dir = join_paths(plugins_install_dir, 'pkgconfig')
205 if get_option('default_library') == 'shared'
206   # If we don't build static plugins there is no need to generate pc files
207   plugins_pkgconfig_install_dir = disabler()
208 endif
209
210 if gst_dep.type_name() == 'internal'
211   gst_debug_disabled = not subproject('gstreamer').get_variable('gst_debug')
212 else
213   # We can't check that in the case of subprojects as we won't
214   # be able to build against an internal dependency (which is not built yet)
215   gst_debug_disabled = cc.has_header_symbol('gst/gstconfig.h', 'GST_DISABLE_GST_DEBUG', dependencies: gst_dep)
216 endif
217
218 if gst_debug_disabled and cc.has_argument('-Wno-unused')
219   add_project_arguments('-Wno-unused', language: 'c')
220 endif
221
222 warning_flags = [
223   '-Wmissing-declarations',
224   '-Wmissing-prototypes',
225   '-Wredundant-decls',
226   '-Wundef',
227   '-Wwrite-strings',
228   '-Wformat',
229   '-Wformat-security',
230   '-Winit-self',
231   '-Wmissing-include-dirs',
232   '-Waddress',
233   '-Wno-multichar',
234   '-Wdeclaration-after-statement',
235   '-Wvla',
236   '-Wpointer-arith',
237 ]
238
239 foreach extra_arg : warning_flags
240   if cc.has_argument (extra_arg)
241     add_project_arguments([extra_arg], language: 'c')
242   endif
243 endforeach
244
245 python3 = import('python').find_installation()
246 configinc = include_directories('.')
247 subdir('ges')
248 subdir('plugins')
249 if not get_option('tools').disabled()
250   subdir('tools')
251 endif
252 subdir('pkgconfig')
253 subdir('tests')
254 if not get_option('examples').disabled()
255   subdir('examples')
256 endif
257 subdir('docs')
258
259 override_detector = '''
260 import sys
261 import os
262
263 prefix = sys.argv[1]
264 version = sys.version_info
265
266 # If we are installing in the same prefix as PyGobject
267 # make sure to install in the right place.
268 import gi.overrides
269
270 overrides_path = os.path.dirname(gi.overrides.__file__)
271 if os.path.commonprefix([overrides_path, prefix]) == prefix:
272     print(overrides_path)
273     exit(0)
274
275 # Otherwise follow python's way of install site packages inside
276 # the provided prefix
277 if os.name == 'posix':
278     print(os.path.join(
279         prefix, 'lib', 'python%d.%d' % (version.major, version.minor),
280         'site-packages', 'gi', 'overrides'))
281 else:
282     print(os.path.join(
283         prefix, 'Lib', 'Python%d%d' % (version.major, version.minor),
284         'site-packages', 'gi', 'overrides'))
285 '''
286 pygi_override_dir = get_option('pygi-overrides-dir')
287 if pygi_override_dir == ''
288     cres = run_command(python3, '-c', override_detector, get_option('prefix'))
289     if cres.returncode() == 0
290       pygi_override_dir = cres.stdout().strip()
291     endif
292     if cres.stderr() != ''
293         message(cres.stderr())
294     endif
295 endif
296
297 if pygi_override_dir != ''
298   message('pygobject overrides directory ' + pygi_override_dir)
299   subdir('bindings/python')
300 endif
301
302 # Set release date
303 if gst_version_nano == 0
304   extract_release_date = find_program('scripts/extract-release-date-from-doap-file.py')
305   run_result = run_command(extract_release_date, gst_version, files('gst-editing-services.doap'))
306   if run_result.returncode() == 0
307     release_date = run_result.stdout().strip()
308     cdata.set_quoted('GST_PACKAGE_RELEASE_DATETIME', release_date)
309     message('Package release date: ' + release_date)
310   else
311     # Error out if our release can't be found in the .doap file
312     error(run_result.stderr())
313   endif
314 endif
315
316 configure_file(output: 'config.h', configuration: cdata)
317
318 run_command(python3, '-c', 'import shutil; shutil.copy("hooks/pre-commit.hook", ".git/hooks/pre-commit")')