meson: Fix build with x11 dependency is disabled
[platform/upstream/gst-plugins-base.git] / meson.build
1 project('gst-plugins-base', '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
18 have_cxx = add_languages('cpp', required : false)
19
20 glib_req = '>= 2.40.0'
21 orc_req = '>= 0.4.24'
22 gst_req = '>= @0@.@1@.0'.format(gst_version_major, gst_version_minor)
23
24 api_version = '1.0'
25 soversion = 0
26 # maintaining compatibility with the previous libtool versioning
27 # current = minor * 100 + micro
28 # FIXME: should be able to convert string to int somehow so we can just do maths
29 libversion = '@0@.@1@.0'.format(soversion, gst_version_minor * 100 + gst_version_micro)
30
31 plugins_install_dir = '@0@/gstreamer-1.0'.format(get_option('libdir'))
32
33 cc = meson.get_compiler('c')
34 host_system = host_machine.system()
35
36 if cc.get_id() == 'msvc'
37   # Ignore several spurious warnings for things gstreamer does very commonly
38   # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
39   # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
40   # NOTE: Only add warnings here if you are sure they're spurious
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       language : 'c')
47   # Disable SAFESEH with MSVC for plugins and libs that use external deps that
48   # are built with MinGW
49   noseh_link_args = ['/SAFESEH:NO']
50 else
51   noseh_link_args = []
52 endif
53
54 if cc.has_link_argument('-Wl,-Bsymbolic-functions')
55   add_project_link_arguments('-Wl,-Bsymbolic-functions', language : 'c')
56 endif
57
58 # Symbol visibility
59 if cc.has_argument('-fvisibility=hidden')
60   add_project_arguments('-fvisibility=hidden', language: 'c')
61 endif
62
63 # Disable strict aliasing
64 if cc.has_argument('-fno-strict-aliasing')
65   add_project_arguments('-fno-strict-aliasing', language: 'c')
66 endif
67
68 core_conf = configuration_data()
69 check_headers = [
70   ['HAVE_DLFCN_H', 'dlfcn.h'],
71   ['HAVE_EMMINTRIN_H', 'emmintrin.h'],
72   ['HAVE_INTTYPES_H', 'inttypes.h'],
73   ['HAVE_MEMORY_H', 'memory.h'],
74   ['HAVE_PROCESS_H', 'process.h'],
75   ['HAVE_SMMINTRIN_H', 'smmintrin.h'],
76   ['HAVE_STDINT_H', 'stdint.h'],
77   ['HAVE_STDLIB_H', 'stdlib.h'],
78   ['HAVE_STRINGS_H', 'strings.h'],
79   ['HAVE_STRING_H', 'string.h'],
80   ['HAVE_SYS_SOCKET_H', 'sys/socket.h'],
81   ['HAVE_SYS_STAT_H', 'sys/stat.h'],
82   ['HAVE_SYS_TYPES_H', 'sys/types.h'],
83   ['HAVE_SYS_WAIT_H', 'sys/wait.h'],
84   ['HAVE_UNISTD_H', 'unistd.h'],
85   ['HAVE_WINSOCK2_H', 'winsock2.h'],
86   ['HAVE_XMMINTRIN_H', 'xmmintrin.h'],
87   ['HAVE_LINUX_DMA_BUF_H', 'linux/dma-buf.h'],
88 ]
89 foreach h : check_headers
90   if cc.has_header(h.get(1))
91     core_conf.set(h.get(0), 1)
92   endif
93 endforeach
94
95 check_functions = [
96   ['HAVE_DCGETTEXT', 'dcgettext', '#include<libintl.h>'],
97   ['HAVE_GMTIME_R', 'gmtime_r', '#include<time.h>'],
98   ['HAVE_LRINTF', 'lrintf', '#include<math.h>'],
99   ['HAVE_MMAP', 'mmap', '#include<sys/mman.h>'],
100   ['HAVE_LOG2', 'log2', '#include<math.h>'],
101 ]
102
103 libm = cc.find_library('m', required : false)
104 foreach f : check_functions
105   if cc.has_function(f.get(1), prefix : f.get(2), dependencies : libm)
106     core_conf.set(f.get(0), 1)
107   endif
108 endforeach
109
110 core_conf.set('SIZEOF_CHAR', cc.sizeof('char'))
111 core_conf.set('SIZEOF_INT', cc.sizeof('int'))
112 core_conf.set('SIZEOF_LONG', cc.sizeof('long'))
113 core_conf.set('SIZEOF_SHORT', cc.sizeof('short'))
114 core_conf.set('SIZEOF_VOIDP', cc.sizeof('void*'))
115
116 core_conf.set_quoted('GETTEXT_PACKAGE', 'gst-plugins-base-1.0')
117 core_conf.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
118 core_conf.set_quoted('PACKAGE', 'gst-plugins-base')
119 core_conf.set_quoted('VERSION', gst_version)
120 core_conf.set_quoted('PACKAGE_VERSION', gst_version)
121 core_conf.set_quoted('GST_API_VERSION', api_version)
122 core_conf.set_quoted('GST_DATADIR', join_paths(get_option('prefix'), get_option('datadir')))
123 core_conf.set_quoted('GST_LICENSE', 'LGPL')
124
125 install_plugins_helper = get_option('install_plugins_helper')
126 if install_plugins_helper == ''
127   install_plugins_helper = join_paths(get_option('prefix'),
128                                       get_option('libexecdir'),
129                                       'gst-install-plugins-helper')
130 endif
131 core_conf.set_quoted('GST_INSTALL_PLUGINS_HELPER', install_plugins_helper)
132
133 warning_flags = [
134   '-Wmissing-declarations',
135   '-Wredundant-decls',
136   '-Wundef',
137   '-Wwrite-strings',
138   '-Wformat',
139   '-Wformat-nonliteral',
140   '-Wformat-security',
141   '-Winit-self',
142   '-Wmissing-include-dirs',
143   '-Waddress',
144   '-Wno-multichar',
145   '-Wvla',
146   '-Wpointer-arith',
147 ]
148
149 warning_c_flags = [
150   '-Wmissing-prototypes',
151   '-Wdeclaration-after-statement',
152 ]
153
154 warning_cxx_flags = [
155   '-Waggregate-return',
156 ]
157
158 if have_cxx
159   cxx = meson.get_compiler('cpp')
160   foreach extra_arg : warning_cxx_flags
161     if cxx.has_argument (extra_arg)
162       add_project_arguments([extra_arg], language: 'cpp')
163     endif
164   endforeach
165 endif
166
167 foreach extra_arg : warning_flags
168   if cc.has_argument (extra_arg)
169     add_project_arguments([extra_arg], language: 'c')
170   endif
171   if have_cxx and cxx.has_argument (extra_arg)
172     add_project_arguments([extra_arg], language: 'cpp')
173   endif
174 endforeach
175
176 foreach extra_arg : warning_c_flags
177   if cc.has_argument (extra_arg)
178     add_project_arguments([extra_arg], language: 'c')
179   endif
180 endforeach
181
182 # GStreamer package name and origin url
183 gst_package_name = get_option('package-name')
184 if gst_package_name == ''
185   if gst_version_nano == 0
186     gst_package_name = 'GStreamer Base Plug-ins source release'
187   elif gst_version_nano == 1
188     gst_package_name = 'GStreamer Base Plug-ins git'
189   else
190     gst_package_name = 'GStreamer Base Plug-ins prerelease'
191   endif
192 endif
193 core_conf.set_quoted('GST_PACKAGE_NAME', gst_package_name)
194 core_conf.set_quoted('GST_PACKAGE_ORIGIN', get_option('package-origin'))
195
196 # FIXME: These should be configure options
197 core_conf.set_quoted('DEFAULT_VIDEOSINK', 'autovideosink')
198 core_conf.set_quoted('DEFAULT_AUDIOSINK', 'autoaudiosink')
199
200 # Set whether the audioresampling method should be detected at runtime
201 core_conf.set('AUDIORESAMPLE_FORMAT_' + get_option('audioresample_format').to_upper(), true)
202
203 gst_plugins_base_args = ['-DHAVE_CONFIG_H']
204 if get_option('default_library') == 'static'
205   gst_plugins_base_args += ['-DGST_STATIC_COMPILATION']
206 endif
207
208 # X11 checks are for sys/ and tests/
209 x11_dep = dependency('x11', required : get_option('x11'))
210 # GLib checks are for the entire project
211 # Almost everything that uses glib also uses gobject
212 glib_deps = [dependency('glib-2.0', version : glib_req, fallback: ['glib', 'libglib_dep']),
213              dependency('gobject-2.0', fallback: ['glib', 'libgobject_dep'])]
214 # GIO is used by the GIO plugin, and by the TCP, SDP, and RTSP plugins
215 gio_dep = dependency('gio-2.0', fallback: ['glib', 'libgio_dep'])
216 giounix_dep = dependency('gio-unix-2.0', version : glib_req, required : host_system != 'windows',
217                          fallback: ['glib', 'libgiounix_dep'])
218
219 # some of the examples can use gdk-pixbuf and GTK+3
220 gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', required : get_option('examples'))
221 gtk_dep = dependency('gtk+-3.0', version : '>= 3.10', required : get_option('examples'))
222 # TODO: https://github.com/mesonbuild/meson/issues/3941
223 if not get_option('x11').disabled()
224   gtk_x11_dep = dependency('gtk+-x11-3.0', version : '>= 3.10', required : get_option('examples'))
225 else
226   gtk_x11_dep = dependency('', required : false)
227 endif
228 # gtk+ quartz backend is only available on macOS
229 if host_system == 'darwin'
230   gtk_quartz_dep = dependency('gtk+-quartz-3.0', version : '>= 3.10', required : get_option('examples'))
231 else
232   gtk_quartz_dep = dependency('', required : false)
233 endif
234
235 core_conf.set('HAVE_X', x11_dep.found())
236 core_conf.set('HAVE_GIO_UNIX_2_0', giounix_dep.found())
237
238 if gio_dep.type_name() == 'pkgconfig'
239     core_conf.set_quoted('GIO_MODULE_DIR',
240         gio_dep.get_pkgconfig_variable('giomoduledir'))
241     core_conf.set_quoted('GIO_LIBDIR',
242         gio_dep.get_pkgconfig_variable('libdir'))
243     core_conf.set_quoted('GIO_PREFIX',
244         gio_dep.get_pkgconfig_variable('prefix'))
245 else
246     core_conf.set_quoted('GIO_MODULE_DIR', join_paths(get_option('prefix'),
247       get_option('libdir'), 'gio/modules'))
248     core_conf.set_quoted('GIO_LIBDIR', join_paths(get_option('prefix'),
249       get_option('libdir')))
250     core_conf.set_quoted('GIO_PREFIX', get_option('prefix'))
251 endif
252
253 configinc = include_directories('.')
254 libsinc = include_directories('gst-libs')
255
256 # To use the subproject make subprojects directory
257 # and put gstreamer meson git there (symlinking is fine)
258 gst_dep = dependency('gstreamer-1.0', version : gst_req,
259   fallback : ['gstreamer', 'gst_dep'])
260 gst_base_dep = dependency('gstreamer-base-1.0', version : gst_req,
261   fallback : ['gstreamer', 'gst_base_dep'])
262 gst_net_dep = dependency('gstreamer-net-1.0', version : gst_req,
263   fallback : ['gstreamer', 'gst_net_dep'])
264 if host_system != 'windows'
265   gst_check_dep = dependency('gstreamer-check-1.0', version : gst_req,
266     fallback : ['gstreamer', 'gst_check_dep'])
267 endif
268 gst_controller_dep = dependency('gstreamer-controller-1.0', version : gst_req,
269   fallback : ['gstreamer', 'gst_controller_dep'])
270
271 have_orcc = false
272 orcc_args = []
273 # Used by various libraries/elements that use Orc code
274 orc_dep = dependency('orc-0.4', version : orc_req, required : get_option('orc'))
275 orcc = find_program('orcc', required : get_option('orc'))
276 if orc_dep.found() and orcc.found()
277   have_orcc = true
278   orcc_args = [orcc, '--include', 'glib.h']
279   core_conf.set('HAVE_ORC', 1)
280 else
281   message('Orc Compiler not found or disabled, will use backup C code')
282   core_conf.set('DISABLE_ORC', 1)
283 endif
284
285 # Used to build SSE* things in audio-resampler
286 sse_args = '-msse'
287 sse2_args = '-msse2'
288 sse41_args = '-msse4.1'
289
290 have_sse = cc.has_argument(sse_args)
291 have_sse2 = cc.has_argument(sse2_args)
292 have_sse41 = cc.has_argument(sse41_args)
293
294 if gst_dep.type_name() == 'internal'
295     gst_proj = subproject('gstreamer')
296
297     if not gst_proj.get_variable('gst_debug')
298         message('GStreamer debug system is disabled')
299         add_project_arguments('-Wno-unused', language: 'c')
300     else
301         message('GStreamer debug system is enabled')
302     endif
303 else
304     # We can't check that in the case of subprojects as we won't
305     # be able to build against an internal dependency (which is not built yet)
306     if not cc.compiles('''
307 #include <gst/gstconfig.h>
308 #ifdef GST_DISABLE_GST_DEBUG
309 #error "debugging disabled, make compiler fail"
310 #endif''' , dependencies: gst_dep)
311         message('GStreamer debug system is disabled')
312         add_project_arguments('-Wno-unused', language: 'c')
313     else
314         message('GStreamer debug system is enabled')
315     endif
316 endif
317
318 gir = find_program('g-ir-scanner', required : get_option('introspection'))
319 gnome = import('gnome')
320 build_gir = gir.found() and not meson.is_cross_build()
321 gir_init_section = [ '--add-init-section=extern void gst_init(gint*,gchar**);' + \
322     'g_setenv("GST_REGISTRY_DISABLE", "yes", TRUE);' + \
323     'g_setenv("GST_REGISTRY_1.0", "@0@", TRUE);'.format(meson.current_build_dir() + '/gir_empty_registry.reg') + \
324     'g_setenv("GST_PLUGIN_PATH_1_0", "", TRUE);' + \
325     'g_setenv("GST_PLUGIN_SYSTEM_PATH_1_0", "", TRUE);' + \
326     'gst_init(NULL,NULL);' ]
327
328 pkgconfig = import('pkgconfig')
329 plugins_pkgconfig_install_dir = join_paths(plugins_install_dir, 'pkgconfig')
330 if get_option('default_library') == 'shared'
331   # If we don't build static plugins there is no need to generate pc files
332   plugins_pkgconfig_install_dir = disabler()
333 endif
334
335 subdir('gst-libs')
336 subdir('gst')
337 subdir('ext')
338 subdir('sys')
339 subdir('tools')
340 subdir('tests')
341 subdir('pkgconfig')
342
343 # xgettext is optional (on Windows for instance)
344 if find_program('xgettext', required : get_option('nls')).found()
345   core_conf.set('ENABLE_NLS', 1)
346   subdir('po')
347 endif
348
349 if build_machine.system() == 'windows'
350   message('Disabling gtk-doc while building on Windows')
351 else
352   if find_program('gtkdoc-scan', required : get_option('gtk_doc')).found()
353     subdir('docs')
354   else
355     message('Not building documentation as gtk-doc was not found')
356   endif
357 endif
358
359 # Use core_conf after all subdirs have set values
360 configure_file(output : 'config.h', configuration : core_conf)
361
362 python3 = import('python3').find_python()
363 run_command(python3, '-c', 'import shutil; shutil.copy("hooks/pre-commit.hook", ".git/hooks/pre-commit")')