meson: add options to disable gobject cast checks and glib asserts
[platform/upstream/gstreamer.git] / meson.build
1 project('gst-plugins-ugly', '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 have_cxx = add_languages('cpp', required : false)
20
21 glib_req = '>= 2.40.0'
22 gst_req = '>= @0@.@1@.0'.format(gst_version_major, gst_version_minor)
23
24 api_version = '1.0'
25
26 plugins_install_dir = '@0@/gstreamer-1.0'.format(get_option('libdir'))
27
28 cc = meson.get_compiler('c')
29 if have_cxx
30   cxx = meson.get_compiler('cpp')
31 endif
32
33 if cc.get_id() == 'msvc'
34   # Ignore several spurious warnings for things gstreamer does very commonly
35   # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
36   # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
37   # NOTE: Only add warnings here if you are sure they're spurious
38   add_project_arguments(
39       '/wd4018', # implicit signed/unsigned conversion
40       '/wd4146', # unary minus on unsigned (beware INT_MIN)
41       '/wd4244', # lossy type conversion (e.g. double -> int)
42       '/wd4305', # truncating type conversion (e.g. double -> float)
43       language : 'c')
44   # Disable SAFESEH with MSVC for plugins and libs that use external deps that
45   # are built with MinGW
46   noseh_link_args = ['/SAFESEH:NO']
47 else
48   noseh_link_args = []
49 endif
50
51 if cc.has_link_argument('-Wl,-Bsymbolic-functions')
52   add_project_link_arguments('-Wl,-Bsymbolic-functions', language : 'c')
53 endif
54 if have_cxx and cxx.has_link_argument('-Wl,-Bsymbolic-functions')
55   add_project_link_arguments('-Wl,-Bsymbolic-functions', language : 'cpp')
56 endif
57
58 cdata = configuration_data()
59 check_headers = [
60   ['HAVE_DLFCN_H', 'dlfcn.h'],
61   ['HAVE_INTTYPES_H', 'inttypes.h'],
62   ['HAVE_MALLOC_H', 'malloc.h'],
63   ['HAVE_MEMORY_H', 'memory.h'],
64   ['HAVE_STDINT_H', 'stdint.h'],
65   ['HAVE_STDLIB_H', 'stdlib.h'],
66   ['HAVE_STRINGS_H', 'strings.h'],
67   ['HAVE_STRING_H', 'string.h'],
68   ['HAVE_SYS_STAT_H', 'sys/stat.h'],
69   ['HAVE_SYS_TYPES_H', 'sys/types.h'],
70   ['HAVE_UNISTD_H', 'unistd.h'],
71   ['HAVE_WINSOCK2_H', 'winsock2.h'],
72 ]
73
74 foreach h : check_headers
75   if cc.has_header(h.get(1))
76     cdata.set(h.get(0), 1)
77   endif
78 endforeach
79
80 check_functions = [
81 # check token HAVE_CPU_ALPHA
82 # check token HAVE_CPU_ARM
83 # check token HAVE_CPU_CRIS
84 # check token HAVE_CPU_CRISV32
85 # check token HAVE_CPU_HPPA
86 # check token HAVE_CPU_I386
87 # check token HAVE_CPU_IA64
88 # check token HAVE_CPU_M68K
89 # check token HAVE_CPU_MIPS
90 # check token HAVE_CPU_PPC
91 # check token HAVE_CPU_PPC64
92 # check token HAVE_CPU_S390
93 # check token HAVE_CPU_SPARC
94 # check token HAVE_CPU_X86_64
95   ['HAVE_DCGETTEXT', 'dcgettext'],
96 # check token HAVE_EXPERIMENTAL
97 # check token HAVE_EXTERNAL
98 # check token HAVE_GETTEXT
99 # check token HAVE_VALGRIND
100 ]
101
102 foreach f : check_functions
103   if cc.has_function(f.get(1))
104     cdata.set(f.get(0), 1)
105   endif
106 endforeach
107
108 cdata.set('SIZEOF_CHAR', cc.sizeof('char'))
109 cdata.set('SIZEOF_INT', cc.sizeof('int'))
110 cdata.set('SIZEOF_LONG', cc.sizeof('long'))
111 cdata.set('SIZEOF_SHORT', cc.sizeof('short'))
112 cdata.set('SIZEOF_VOIDP', cc.sizeof('void*'))
113
114 cdata.set_quoted('VERSION', gst_version)
115 cdata.set_quoted('PACKAGE', 'gst-plugins-ugly')
116 cdata.set_quoted('GST_LICENSE', 'LGPL')
117 cdata.set_quoted('GETTEXT_PACKAGE', 'gst-plugins-ugly-1.0')
118 cdata.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
119
120 # GStreamer package name and origin url
121 gst_package_name = get_option('package-name')
122 if gst_package_name == ''
123   if gst_version_nano == 0
124     gst_package_name = 'GStreamer Ugly Plug-ins source release'
125   elif gst_version_nano == 1
126     gst_package_name = 'GStreamer Ugly Plug-ins git'
127   else
128     gst_package_name = 'GStreamer Ugly Plug-ins prerelease'
129   endif
130 endif
131 cdata.set_quoted('GST_PACKAGE_NAME', gst_package_name)
132 cdata.set_quoted('GST_PACKAGE_ORIGIN', get_option('package-origin'))
133
134 # Mandatory GST deps
135 gst_dep = dependency('gstreamer-1.0', version : gst_req,
136     fallback : ['gstreamer', 'gst_dep'])
137 gstapp_dep = dependency('gstreamer-app-1.0', version : gst_req,
138     fallback : ['gst-plugins-base', 'app_dep'])
139 gstvideo_dep = dependency('gstreamer-video-1.0', version : gst_req,
140     fallback : ['gst-plugins-base', 'video_dep'])
141 gstpbutils_dep = dependency('gstreamer-pbutils-1.0', version : gst_req,
142     fallback : ['gst-plugins-base', 'pbutils_dep'])
143 gsttag_dep = dependency('gstreamer-tag-1.0', version : gst_req,
144     fallback : ['gst-plugins-base', 'tag_dep'])
145 gstfft_dep = dependency('gstreamer-fft-1.0', version : gst_req,
146     fallback : ['gst-plugins-base', 'fft_dep'])
147 gstaudio_dep = dependency('gstreamer-audio-1.0', version : gst_req,
148     fallback : ['gst-plugins-base', 'audio_dep'])
149 gstbase_dep = dependency('gstreamer-base-1.0', version : gst_req,
150   fallback : ['gstreamer', 'gst_base_dep'])
151 gstriff_dep = dependency('gstreamer-riff-1.0', version : gst_req,
152     fallback : ['gst-plugins-base', 'riff_dep'])
153 gstrtp_dep = dependency('gstreamer-rtp-1.0', version : gst_req,
154     fallback : ['gst-plugins-base', 'rtp_dep'])
155 gstnet_dep = dependency('gstreamer-net-1.0', version : gst_req,
156   fallback : ['gstreamer', 'gst_net_dep'])
157 gstsdp_dep = dependency('gstreamer-sdp-1.0', version : gst_req,
158     fallback : ['gst-plugins-base', 'sdp_dep'])
159 gstrtsp_dep = dependency('gstreamer-rtsp-1.0', version : gst_req,
160     fallback : ['gst-plugins-base', 'rtsp_dep'])
161 if host_machine.system() != 'windows'
162   gstcheck_dep = dependency('gstreamer-check-1.0', version : gst_req,
163     fallback : ['gstreamer', 'gst_check_dep'])
164 endif
165 gstcontroller_dep = dependency('gstreamer-controller-1.0', version : gst_req,
166   fallback : ['gstreamer', 'gst_controller_dep'])
167
168 orc_dep = dependency('orc-0.4', version : '>= 0.4.16', required : get_option('orc'))
169 if orc_dep.found()
170   cdata.set('HAVE_ORC', 1) # used by a52dec for cpu detection
171 else
172   cdata.set('DISABLE_ORC', 1)
173 endif
174
175 ugly_args = ['-DHAVE_CONFIG_H']
176 configinc = include_directories('.')
177 libsinc = include_directories('gst-libs')
178
179 if gst_dep.type_name() == 'internal'
180   gst_debug_disabled = not subproject('gstreamer').get_variable('gst_debug')
181 else
182   # We can't check that in the case of subprojects as we won't
183   # be able to build against an internal dependency (which is not built yet)
184   gst_debug_disabled = cc.has_header_symbol('gst/gstconfig.h', 'GST_DISABLE_GST_DEBUG', dependencies: gst_dep)
185 endif
186
187 if gst_debug_disabled and cc.has_argument('-Wno-unused')
188   add_project_arguments('-Wno-unused', language: 'c')
189 endif
190
191 warning_flags = [
192   '-Wmissing-declarations',
193   '-Wredundant-decls',
194   '-Wwrite-strings',
195   '-Wformat',
196   '-Wformat-nonliteral',
197   '-Wformat-security',
198   '-Winit-self',
199   '-Wmissing-include-dirs',
200   '-Waddress',
201   '-Wno-multichar',
202   '-Wvla',
203   '-Wpointer-arith',
204   '-Waggregate-return',
205   '-fno-strict-aliasing',
206   # Symbol visibility
207   '-fvisibility=hidden',
208 ]
209
210 warning_c_flags = [
211   '-Wmissing-prototypes',
212   '-Wold-style-definition',
213   '-Wdeclaration-after-statement',
214   '-Wnested-externs'
215 ]
216
217 foreach extra_arg : warning_flags
218   if cc.has_argument (extra_arg)
219     add_project_arguments([extra_arg], language: 'c')
220   endif
221   if have_cxx and cxx.has_argument (extra_arg)
222     add_project_arguments([extra_arg], language: 'cpp')
223   endif
224 endforeach
225
226 foreach extra_arg : warning_c_flags
227   if cc.has_argument (extra_arg)
228     add_project_arguments([extra_arg], language: 'c')
229   endif
230 endforeach
231
232 # Define G_DISABLE_DEPRECATED for development versions
233 if gst_version_is_dev
234   message('Disabling deprecated GLib API')
235   add_project_arguments('-DG_DISABLE_DEPRECATED', language: 'c')
236 endif
237
238 cast_checks = get_option('gobject-cast-checks')
239 if cast_checks.disabled() or (cast_checks.auto() and not gst_version_is_dev)
240   message('Disabling GLib cast checks')
241   add_project_arguments('-DG_DISABLE_CAST_CHECKS', language: 'c')
242 endif
243
244 glib_asserts = get_option('glib-asserts')
245 if glib_asserts.disabled() or (glib_asserts.auto() and not gst_version_is_dev)
246   message('Disabling GLib asserts')
247   add_project_arguments('-DG_DISABLE_ASSERT', language: 'c')
248 endif
249
250 presetdir = join_paths(get_option('datadir'), 'gstreamer-' + api_version, 'presets')
251
252 pkgconfig = import('pkgconfig')
253 plugins_pkgconfig_install_dir = join_paths(plugins_install_dir, 'pkgconfig')
254 if get_option('default_library') == 'shared'
255   # If we don't build static plugins there is no need to generate pc files
256   plugins_pkgconfig_install_dir = disabler()
257 endif
258
259 subdir('gst')
260 subdir('ext')
261 subdir('tests')
262
263 # xgettext is optional (on Windows for instance)
264 if find_program('xgettext', required : get_option('nls')).found()
265   cdata.set('ENABLE_NLS', 1)
266   subdir('po')
267 endif
268
269 configure_file(output : 'config.h', configuration : cdata)
270
271 python3 = import('python3').find_python()
272 run_command(python3, '-c', 'import shutil; shutil.copy("hooks/pre-commit.hook", ".git/hooks/pre-commit")')