meson: Specify encoding to UTF-8 when building with MSVC
[platform/upstream/gstreamer.git] / meson.build
1 project('gstreamer', 'c',
2   version : '1.15.0.1',
3   meson_version : '>= 0.47',
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_major = version_arr[0].to_int()
10 gst_version_minor = version_arr[1].to_int()
11 gst_version_micro = version_arr[2].to_int()
12 if version_arr.length() == 4
13   gst_version_nano = version_arr[3].to_int()
14 else
15   gst_version_nano = 0
16 endif
17 gst_version_is_dev = gst_version_minor % 2 == 1 and gst_version_micro < 90
18
19 host_system = host_machine.system()
20
21 apiversion = '1.0'
22 soversion = 0
23 # maintaining compatibility with the previous libtool versioning
24 # current = minor * 100 + micro
25 curversion = gst_version_minor * 100 + gst_version_micro
26 libversion = '@0@.@1@.0'.format(soversion, curversion)
27 osxversion = curversion + 1
28
29 prefix = get_option('prefix')
30
31 libexecdir = get_option('libexecdir')
32 helpers_install_dir = join_paths(libexecdir, 'gstreamer-1.0')
33
34 cc = meson.get_compiler('c')
35
36 # Ignore several spurious warnings for things gstreamer does very commonly
37 # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
38 # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
39 # NOTE: Only add warnings here if you are sure they're spurious
40 if cc.get_id() == 'msvc'
41   add_project_arguments(
42       '/wd4018', # implicit signed/unsigned conversion
43       '/wd4146', # unary minus on unsigned (beware INT_MIN)
44       '/wd4244', # lossy type conversion (e.g. double -> int)
45       '/wd4305', # truncating type conversion (e.g. double -> float)
46       cc.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8
47       language : 'c')
48 elif cc.has_link_argument('-Wl,-Bsymbolic-functions')
49   # FIXME: Add an option for this if people ask for it
50   add_project_link_arguments('-Wl,-Bsymbolic-functions', language : 'c')
51 endif
52
53 # Symbol visibility
54 have_visibility_hidden = cc.has_argument('-fvisibility=hidden')
55 if have_visibility_hidden
56   add_project_arguments('-fvisibility=hidden', language: 'c')
57 endif
58
59 # Disable strict aliasing
60 if cc.has_argument('-fno-strict-aliasing')
61   add_project_arguments('-fno-strict-aliasing', language: 'c')
62 endif
63
64 # Define G_DISABLE_DEPRECATED for development versions
65 if gst_version_is_dev
66   message('Disabling deprecated GLib API')
67   add_project_arguments('-DG_DISABLE_DEPRECATED', language: 'c')
68 endif
69
70 cast_checks = get_option('gobject-cast-checks')
71 if cast_checks.disabled() or (cast_checks.auto() and not gst_version_is_dev)
72   message('Disabling GLib cast checks')
73   add_project_arguments('-DG_DISABLE_CAST_CHECKS', language: 'c')
74 endif
75
76 glib_asserts = get_option('glib-asserts')
77 if glib_asserts.disabled() or (glib_asserts.auto() and not gst_version_is_dev)
78   message('Disabling GLib asserts')
79   add_project_arguments('-DG_DISABLE_ASSERT', language: 'c')
80 endif
81
82 glib_checks = get_option('glib-checks')
83 if glib_checks.disabled() or (glib_checks.auto() and not gst_version_is_dev)
84   message('Disabling GLib checks')
85   add_project_arguments('-DG_DISABLE_CHECKS', language: 'c')
86 endif
87
88 cdata = configuration_data()
89 cdata.set_quoted('GST_API_VERSION', apiversion)
90 cdata.set_quoted('GST_DATADIR', join_paths(prefix, get_option('datadir')))
91 cdata.set_quoted('LOCALEDIR', join_paths(prefix, get_option('localedir')))
92 cdata.set_quoted('LIBDIR', join_paths(prefix, get_option('libdir')))
93 cdata.set_quoted('GST_API_VERSION', '1.0')
94 cdata.set_quoted('GETTEXT_PACKAGE', 'gstreamer-1.0')
95 cdata.set_quoted('GST_LICENSE', 'LGPL')
96 cdata.set_quoted('PACKAGE', 'gstreamer')
97 cdata.set_quoted('PACKAGE_NAME', 'GStreamer')
98 cdata.set_quoted('PACKAGE_STRING', 'GStreamer @0@'.format(gst_version))
99 cdata.set_quoted('PACKAGE_TARNAME', 'gstreamer')
100 cdata.set_quoted('PACKAGE_BUGREPORT', 'http://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer')
101 cdata.set_quoted('PACKAGE_URL', '')
102 cdata.set_quoted('PACKAGE_VERSION', gst_version)
103 cdata.set_quoted('PLUGINDIR', join_paths(get_option('prefix'), get_option('libdir'), 'gstreamer-1.0'))
104 cdata.set_quoted('VERSION', gst_version)
105 cdata.set_quoted('GST_PLUGIN_SCANNER_INSTALLED', join_paths(prefix, helpers_install_dir, 'gst-plugin-scanner'))
106 cdata.set_quoted('GST_PTP_HELPER_INSTALLED', join_paths(prefix, helpers_install_dir, 'gst-ptp-helper'))
107 cdata.set_quoted('GST_PLUGIN_SCANNER_SUBDIR', libexecdir,
108   description: 'libexecdir path component, used to find plugin-scanner on relocatable builds on windows')
109 cdata.set('GST_DISABLE_OPTION_PARSING', not get_option('option-parsing'))
110
111 mem_align_opt = get_option('memory-alignment')
112 if mem_align_opt == 'malloc'
113   cdata.set('MEMORY_ALIGNMENT_MALLOC', 1)
114 elif mem_align_opt == 'pagesize'
115   cdata.set('MEMORY_ALIGNMENT_PAGESIZE', 1)
116 else
117   cdata.set('MEMORY_ALIGNMENT', mem_align_opt.to_int())
118 endif
119
120 if ['darwin', 'ios'].contains(host_system)
121   cdata.set_quoted('GST_EXTRA_MODULE_SUFFIX', '.dylib')
122 endif
123
124 if gst_version_nano > 0
125     # Have GST_ERROR message printed when running from git
126     cdata.set('GST_LEVEL_DEFAULT', 'GST_LEVEL_ERROR')
127 else
128     cdata.set('GST_LEVEL_DEFAULT', 'GST_LEVEL_NONE')
129 endif
130
131 # GStreamer package name and origin url
132 gst_package_name = get_option('package-name')
133 if gst_package_name == ''
134   if gst_version_nano == 0
135     gst_package_name = 'GStreamer source release'
136   elif gst_version_nano == 1
137     gst_package_name = 'GStreamer git'
138   else
139     gst_package_name = 'GStreamer prerelease'
140   endif
141 endif
142 cdata.set_quoted('GST_PACKAGE_NAME', gst_package_name)
143 cdata.set_quoted('GST_PACKAGE_ORIGIN', get_option('package-origin'))
144
145 # These are only needed/used by the ABI tests
146 host_defines = [
147   [ 'x86', 'HAVE_CPU_I386' ],
148   [ 'x86_64', 'HAVE_CPU_X86_64' ],
149   [ 'arm', 'HAVE_CPU_ARM' ],
150   [ 'aarch64', 'HAVE_CPU_AARCH64' ],
151   [ 'mips', 'HAVE_CPU_MIPS' ],
152   [ 'powerpc', 'HAVE_CPU_PPC' ],
153   [ 'powerpc64', 'HAVE_CPU_PPC64' ],
154   [ 'alpha', 'HAVE_CPU_ALPHA' ],
155   [ 'sparc', 'HAVE_CPU_SPARC' ],
156   [ 'ia64', 'HAVE_CPU_IA64' ],
157   [ 'hppa', 'HAVE_CPU_HPPA' ],
158   [ 'm68k', 'HAVE_CPU_M68K' ],
159   [ 's390', 'HAVE_CPU_S390' ],
160 ]
161 foreach h : host_defines
162   if h.get(0) == host_machine.cpu()
163     cdata.set(h.get(1), 1)
164   endif
165 endforeach
166 # FIXME: should really be called HOST_CPU or such
167 cdata.set_quoted('TARGET_CPU', host_machine.cpu())
168
169 check_headers = [
170   'dlfcn.h',
171   'inttypes.h',
172   'memory.h',
173   'poll.h',
174   'stdint.h',
175   'stdio_ext.h',
176   'strings.h',
177   'string.h',
178   'sys/param.h',
179   'sys/poll.h',
180   'sys/prctl.h',
181   'sys/socket.h',
182   'sys/stat.h',
183   'sys/times.h',
184   'sys/time.h',
185   'sys/types.h',
186   'sys/utsname.h',
187   'sys/wait.h',
188   'ucontext.h',
189   'unistd.h',
190   'valgrind/valgrind.h',
191   'sys/resource.h',
192 ]
193
194 if host_system == 'windows'
195   check_headers += ['winsock2.h']
196 endif
197
198 foreach h : check_headers
199   if cc.has_header(h)
200     define = 'HAVE_' + h.underscorify().to_upper()
201     cdata.set(define, 1)
202   endif
203 endforeach
204
205 if cc.has_member('struct tm', 'tm_gmtoff', prefix : '#include <time.h>')
206   cdata.set('HAVE_TM_GMTOFF', 1)
207 endif
208
209 check_functions = [
210   'gmtime_r',
211   'sigaction',
212   'getrusage',
213   'fseeko',
214   'ftello',
215   'poll',
216   'ppoll',
217   'pselect',
218   'getpagesize',
219   'clock_gettime',
220   # These are needed by libcheck
221   'getline',
222   'mkstemp',
223   'alarm',
224   'gettimeofday',
225 ]
226
227 foreach f : check_functions
228   if cc.has_function(f)
229     define = 'HAVE_' + f.underscorify().to_upper()
230     cdata.set(define, 1)
231   endif
232 endforeach
233
234 if cc.has_function('localtime_r', prefix : '#include<time.h>')
235   cdata.set('HAVE_LOCALTIME_R', 1)
236   # Needed by libcheck
237   cdata.set('HAVE_DECL_LOCALTIME_R', 1)
238 endif
239
240 if cc.links('''#include <pthread.h>
241                int main() {
242                  pthread_setname_np("example"); return 0;
243                }''', name : 'pthread_setname_np(const char*)')
244   cdata.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
245 endif
246
247 # Check for posix timers and the monotonic clock
248 time_prefix = '#include <time.h>\n'
249 if cdata.has('HAVE_UNISTD_H')
250   time_prefix += '#include <unistd.h>'
251 endif
252
253 posix_timers_src = time_prefix + '''
254 #if !defined(_POSIX_TIMERS) || _POSIX_TIMERS < 0 || !defined(CLOCK_REALTIME)
255 #error Either _POSIX_TIMERS or CLOCK_REALTIME not defined
256 #endif
257 '''
258 if cc.compiles(posix_timers_src, name : 'posix timers from time.h')
259   cdata.set('HAVE_POSIX_TIMERS', 1)
260 endif
261
262 monotonic_clock_src = time_prefix + '''
263 #if !defined(_POSIX_MONOTONIC_CLOCK) || _POSIX_MONOTONIC_CLOCK < 0 || !defined(CLOCK_MONOTONIC)
264 #error Either _POSIX_MONOTONIC_CLOCK or CLOCK_MONOTONIC not defined
265 #endif
266 '''
267 if cc.compiles(monotonic_clock_src, name : 'monotonic clock from time.h')
268   cdata.set('HAVE_MONOTONIC_CLOCK', 1)
269 endif
270
271 # Check for __uint128_t (gcc) by checking for 128-bit division
272 uint128_t_src = '''int main() {
273 static __uint128_t v1 = 100;
274 static __uint128_t v2 = 10;
275 static __uint128_t u;
276 u = v1 / v2;
277 }'''
278 if cc.compiles(uint128_t_src, name : '__uint128_t available')
279   cdata.set('HAVE_UINT128_T', 1)
280 endif
281
282 # All supported platforms have long long now
283 cdata.set('HAVE_LONG_LONG', 1)
284
285 # We only want to use the __declspec(dllexport/import) dance in GST_EXPORT when
286 # building with MSVC
287 if cc.get_id() == 'msvc'
288   cdata.set('GSTCONFIG_BUILT_WITH_MSVC', 1)
289 else
290   cdata.set('GSTCONFIG_BUILT_WITH_MSVC', 0)
291 endif
292
293 # -------------------------------------------------------------------------------------
294 # config.h things needed by libcheck
295 # -------------------------------------------------------------------------------------
296 if cc.has_function('getpid')
297   cdata.set('HAVE_GETPID', 1)
298 elif host_system == 'windows' and cc.has_function('_getpid')
299   cdata.set('HAVE_PROCESS_H', 1) # Used by gstreamer too
300   cdata.set('HAVE__GETPID', 1)
301 endif
302 if cc.has_function('strdup')
303   cdata.set('HAVE_DECL_STRDUP', 1)
304 elif host_system == 'windows' and cc.has_function('_strdup')
305   cdata.set('HAVE__STRDUP', 1) # Windows (MSVC)
306 endif
307 if host_system != 'windows'
308   cdata.set('HAVE_FORK', 1)
309 else
310   # libcheck requires HAVE_FORK to be 0 when fork() is not available
311   cdata.set('HAVE_FORK', 0)
312 endif
313 if cc.has_function('strsignal')
314   cdata.set('HAVE_DECL_STRSIGNAL', 1)
315 endif
316 # Check for availability of types
317 if not cc.has_type('clockid_t', prefix : '#include <time.h>')
318   cdata.set('clockid_t', 'int')
319 endif
320 if not cc.has_type('timer_t', prefix : '#include <time.h>')
321   cdata.set('timer_t', 'int')
322 endif
323 if not cc.has_members('struct timespec', 'tv_sec', 'tv_nsec',
324                       prefix : '#include <time.h>')
325   cdata.set('STRUCT_TIMESPEC_DEFINITION_MISSING', 1)
326 endif
327 if not cc.has_members('struct itimerspec', 'it_interval', 'it_value',
328                       prefix : '#include <time.h>')
329   cdata.set('STRUCT_ITIMERSPEC_DEFINITION_MISSING', 1)
330 endif
331
332 # Platform deps; only ws2_32 and execinfo for now
333 platform_deps = []
334 if host_system == 'windows'
335   platform_deps = [cc.find_library('ws2_32')]
336 endif
337
338 backtrace_deps = []
339 unwind_dep = dependency('libunwind', required : get_option('libunwind'))
340 dw_dep = dependency('libdw', required: get_option('libunwind'))
341 backtrace_deps = [unwind_dep, dw_dep]
342 if unwind_dep.found()
343   cdata.set('HAVE_UNWIND', 1)
344   if dw_dep.found()
345     cdata.set('HAVE_DW', 1)
346   else
347     message('Support for backtraces is partial only.')
348   endif
349 else
350   if cc.has_function('backtrace')
351     cdata.set('HAVE_BACKTRACE', 1)
352   else
353       message('NO backtraces support.')
354   endif
355 endif
356
357 if cc.has_header('execinfo.h')
358   if cc.has_function('backtrace', prefix : '#include <execinfo.h>')
359     cdata.set('HAVE_BACKTRACE', 1)
360   else
361     execinfo_dep = cc.find_library('execinfo', required : false)
362     if execinfo_dep.found() and cc.has_function('backtrace', prefix : '#include <execinfo.h>', dependencies : execinfo_dep)
363       cdata.set('HAVE_BACKTRACE', 1)
364       platform_deps += execinfo_dep
365     endif
366   endif
367 endif
368
369 gst_debug = get_option('gst_debug')
370 if not gst_debug
371   add_project_arguments(['-Wno-unused'], language: 'c')
372 endif
373
374 warning_flags = [
375   '-Wmissing-declarations',
376   '-Wmissing-prototypes',
377   '-Wredundant-decls',
378   '-Wundef',
379   '-Wwrite-strings',
380   '-Wformat',
381   '-Wformat-nonliteral',
382   '-Wformat-security',
383   '-Wold-style-definition',
384   '-Winit-self',
385   '-Wmissing-include-dirs',
386   '-Waddress',
387   '-Waggregate-return',
388   '-Wno-multichar',
389   '-Wnested-externs',
390   '-Wdeclaration-after-statement',
391   '-Wvla',
392   '-Wpointer-arith',
393 ]
394
395 foreach extra_arg : warning_flags
396   if cc.has_argument (extra_arg)
397     add_project_arguments([extra_arg], language: 'c')
398   endif
399 endforeach
400
401 # Used by the gstutils test
402 gmp_dep = cc.find_library('gmp', required : false)
403 cdata.set('HAVE_GMP', gmp_dep.found())
404 gsl_dep = cc.find_library('gsl', required : false)
405 gslcblas_dep = cc.find_library('gslcblas', required : false)
406 cdata.set('HAVE_GSL', gsl_dep.found() and gslcblas_dep.found())
407 test_deps = [gmp_dep, gsl_dep, gslcblas_dep]
408
409 # Used by gstinfo.c
410 dl_dep = cc.find_library('dl', required : false)
411 cdata.set('HAVE_DLADDR', cc.has_function('dladdr', dependencies : dl_dep))
412 cdata.set('GST_ENABLE_EXTRA_CHECKS', get_option('extra-checks'))
413 cdata.set('USE_POISONING', get_option('poisoning'))
414
415 configinc = include_directories('.')
416 libsinc = include_directories('libs')
417 privinc = include_directories('gst')
418
419 # Find dependencies
420 glib_dep = dependency('glib-2.0', version : '>=2.32.0',
421   fallback: ['glib', 'libglib_dep'])
422 gobject_dep = dependency('gobject-2.0',
423   fallback: ['glib', 'libgobject_dep'])
424 gmodule_dep = dependency('gmodule-2.0',
425   fallback: ['glib', 'libgmodule_dep'])
426 if host_system == 'windows'
427     gio_dep = dependency('gio-2.0',
428         fallback: ['glib', 'libgio_dep'])
429 else
430     gio_dep = [dependency('gio-2.0',
431                   fallback: ['glib', 'libgio_dep']),
432                dependency('gio-unix-2.0',
433                   fallback: ['glib', 'libgio_dep'])]
434 endif
435
436 mathlib = cc.find_library('m', required : false)
437 # Needed for timer_create/settime/delete
438 # Also provides clock_gettime in glibc < 2.17
439 rt_lib = cc.find_library('rt', required : false)
440
441 gir = find_program('g-ir-scanner', required : get_option('introspection'))
442 gnome = import('gnome')
443
444 build_gir = gir.found() and not meson.is_cross_build()
445
446 gir_init_section = [ '--add-init-section=extern void gst_init(gint*,gchar**);' + \
447     'g_setenv("GST_REGISTRY_DISABLE", "yes", TRUE);' + \
448     'g_setenv("GST_REGISTRY_1.0", "/no/way/this/exists.reg", TRUE);' + \
449     'g_setenv("GST_PLUGIN_PATH_1_0", "", TRUE);' + \
450     'g_setenv("GST_PLUGIN_SYSTEM_PATH_1_0", "", TRUE);' + \
451     'gst_init(NULL,NULL);' ]
452
453 gst_c_args = ['-DHAVE_CONFIG_H']
454
455 # FIXME: This is only needed on windows and probably breaks when
456 # default_library = 'both'. We should add this flag to static_c_args instead
457 # when Meson supports it: https://github.com/mesonbuild/meson/issues/3304
458 if get_option('default_library') == 'static'
459   gst_c_args += ['-DGST_STATIC_COMPILATION']
460 endif
461
462 # Used in gst/parse/meson.build and below
463 python3 = import('python3').find_python()
464
465 bashcomp_option = get_option('bash-completion')
466 bashcomp_dep = dependency('bash-completion', version : '>= 2.0', required : bashcomp_option)
467 bash_completions_dir = ''
468 bash_helpers_dir = ''
469
470 bashcomp_found = false
471 if bashcomp_dep.found()
472   bashcomp_found = true
473   bash_completions_dir = bashcomp_dep.get_pkgconfig_variable('completionsdir', define_variable: ['prefix', '.'])
474   if bash_completions_dir == ''
475     msg = 'Found bash-completion but the .pc file did not set \'completionsdir\'.'
476     if bashcomp_option.enabled()
477       error(msg)
478     else
479       message(msg)
480     endif
481     bashcomp_found = false
482   endif
483
484   bash_helpers_dir = bashcomp_dep.get_pkgconfig_variable('helpersdir', define_variable: ['prefix', '.'])
485   if bash_helpers_dir == ''
486     msg = 'Found bash-completion, but the .pc file did not set \'helpersdir\'.'
487     if bashcomp_option.enabled()
488       error(msg)
489     else
490       message(msg)
491     endif
492     bashcomp_found = false
493   endif
494 endif
495
496 subdir('gst')
497 subdir('libs')
498 subdir('plugins')
499 if not get_option('tools').disabled()
500   subdir('tools')
501 endif
502 subdir('pkgconfig')
503 subdir('tests')
504 subdir('data')
505
506 # xgettext is optional (on Windows for instance)
507 if find_program('xgettext', required : get_option('nls')).found()
508   cdata.set('ENABLE_NLS', 1)
509   subdir('po')
510 endif
511
512 configure_file(output : 'config.h', configuration : cdata)
513
514 if build_machine.system() == 'windows'
515   message('Disabling gtk-doc while building on Windows')
516 else
517   if find_program('gtkdoc-scan', required : get_option('gtk_doc')).found()
518     subdir('docs')
519   else
520     message('Not building documentation as gtk-doc was not found')
521   endif
522 endif
523
524 run_command(python3, '-c', 'import shutil; shutil.copy("hooks/pre-commit.hook", ".git/hooks/pre-commit")')
525
526 install_data('gst-element-check-1.0.m4', install_dir : join_paths(get_option('datadir'), 'aclocal'))