meson: move gmodule check to top-level
[platform/upstream/gst-plugins-base.git] / gst-libs / gst / gl / meson.build
1 if get_option('gl').disabled()
2   message('GStreamer OpenGL integration disabled via options.')
3   gstgl_dep = disabler()
4   build_gstgl = false
5   subdir_done()
6 endif
7
8 gl_sources = [
9   'gstglapi.c',
10   'gstglbasefilter.c',
11   'gstglbasememory.c',
12   'gstglcolorconvert.c',
13   'gstglbuffer.c',
14   'gstglbufferpool.c',
15   'gstglcontext.c',
16   'gstgldebug.c',
17   'gstgldisplay.c',
18   'gstglfeature.c',
19   'gstglfilter.c',
20   'gstglformat.c',
21   'gstglframebuffer.c',
22   'gstglmemory.c',
23   'gstglmemorypbo.c',
24   'gstgloverlaycompositor.c',
25   'gstglquery.c',
26   'gstglrenderbuffer.c',
27   'gstglshader.c',
28   'gstglshaderstrings.c',
29   'gstglsl.c',
30   'gstglslstage.c',
31   'gstglsyncmeta.c',
32   'gstglupload.c',
33   'gstglutils.c',
34   'gstglviewconvert.c',
35   'gstglwindow.c',
36 ]
37
38 gl_headers = [
39   'gl.h',
40   'gl-prelude.h',
41   'gstgl_enums.h',
42   'gstgl_fwd.h',
43   'gstglapi.h',
44   'gstglbasefilter.h',
45   'gstglbasememory.h',
46   'gstglbuffer.h',
47   'gstglbufferpool.h',
48   'gstglcolorconvert.h',
49   'gstglcontext.h',
50   'gstgldebug.h',
51   'gstgldisplay.h',
52   'gstglfeature.h',
53   'gstglfilter.h',
54   'gstglformat.h',
55   'gstglfuncs.h',
56   'gstglframebuffer.h',
57   'gstglmemory.h',
58   'gstglmemorypbo.h',
59   'gstgloverlaycompositor.h',
60   'gstglquery.h',
61   'gstglrenderbuffer.h',
62   'gstglshader.h',
63   'gstglshaderstrings.h',
64   'gstglsl.h',
65   'gstglslstage.h',
66   'gstglsyncmeta.h',
67   'gstglupload.h',
68   'gstglutils.h',
69   'gstglviewconvert.h',
70   'gstglwindow.h',
71 ]
72
73 gl_prototype_headers = [
74   'glprototypes/all_functions.h',
75   'glprototypes/base.h',
76   'glprototypes/blending.h',
77   'glprototypes/buffers.h',
78   'glprototypes/debug.h',
79   'glprototypes/eglimage.h',
80   'glprototypes/fbo.h',
81   'glprototypes/fixedfunction.h',
82   'glprototypes/gles.h',
83   'glprototypes/gstgl_compat.h',
84   'glprototypes/gstgl_gles2compat.h',
85   'glprototypes/opengl.h',
86   'glprototypes/query.h',
87   'glprototypes/shaders.h',
88   'glprototypes/sync.h',
89   'glprototypes/vao.h',
90 ]
91
92 gl_x11_headers = []
93 gl_wayland_headers = []
94 gl_win32_headers = []
95 gl_cocoa_headers = []
96 gl_egl_headers = []
97
98 glconf = configuration_data()
99 glconf_options = [
100     'GST_GL_HAVE_OPENGL',
101     'GST_GL_HAVE_GLES2',
102     'GST_GL_HAVE_GLES3',
103     'GST_GL_HAVE_GLES3EXT3_H',
104
105     'GST_GL_HAVE_WINDOW_X11',
106     'GST_GL_HAVE_WINDOW_COCOA',
107     'GST_GL_HAVE_WINDOW_WIN32',
108     'GST_GL_HAVE_WINDOW_WAYLAND',
109     'GST_GL_HAVE_WINDOW_ANDROID',
110     'GST_GL_HAVE_WINDOW_DISPMANX',
111     'GST_GL_HAVE_WINDOW_EAGL',
112     'GST_GL_HAVE_WINDOW_VIV_FB',
113     'GST_GL_HAVE_WINDOW_GBM',
114
115     'GST_GL_HAVE_PLATFORM_EGL',
116     'GST_GL_HAVE_PLATFORM_GLX',
117     'GST_GL_HAVE_PLATFORM_WGL',
118     'GST_GL_HAVE_PLATFORM_CGL',
119     'GST_GL_HAVE_PLATFORM_EAGL',
120
121     'GST_GL_HAVE_DMABUF',
122     'GST_GL_HAVE_VIV_DIRECTVIV',
123
124     'GST_GL_HAVE_GLEGLIMAGEOES',
125     'GST_GL_HAVE_GLCHAR',
126     'GST_GL_HAVE_GLSIZEIPTR',
127     'GST_GL_HAVE_GLINTPTR',
128     'GST_GL_HAVE_GLSYNC',
129     'GST_GL_HAVE_GLUINT64',
130     'GST_GL_HAVE_GLINT64',
131     'GST_GL_HAVE_EGLATTRIB',
132     'GST_GL_HAVE_EGLUINT64KHR',
133 ]
134
135 foreach option : glconf_options
136   glconf.set10(option, false)
137 endforeach
138
139 unneeded_dep = dependency('', required : false)
140 if unneeded_dep.found()
141   error ('Found unfindable dependency')
142 endif
143
144 # OpenGL/GLES2 libraries
145 gl_lib_deps = []
146 # GL platform - EGL, GLX, CGL, WGL, etc
147 gl_platform_deps = []
148 # GL winsys - wayland, X11, Cocoa, win32, etc
149 gl_winsys_deps = []
150 # other things we need.
151 gl_misc_deps = []
152 # Other preprocessor arguments
153 gl_cpp_args = []
154 gl_includes = []
155 gl_objc_args = []
156
157 enabled_gl_apis = []
158 enabled_gl_platforms = []
159 enabled_gl_winsys = []
160
161 # parse provided options
162 libegl_module_name = get_option('egl_module_name')
163 if libegl_module_name != ''
164   gl_cpp_args += ['-DGST_GL_LIBEGL_MODULE_NAME="@0@"'.format(libegl_module_name)]
165 endif
166 libgles2_module_name = get_option('gles2_module_name')
167 if libgles2_module_name != ''
168   gl_cpp_args += ['-DGST_GL_LIBGLESV2_MODULE_NAME="@0@"'.format(libgles2_module_name)]
169 endif
170 libgl_module_name = get_option('opengl_module_name')
171 if libgl_module_name != ''
172   gl_cpp_args += ['-DGST_GL_LIBGL_MODULE_NAME="@0@"'.format(libgl_module_name)]
173 endif
174
175 gl_apis = get_option('gl_api')
176 if gl_apis.contains('auto')
177   need_api_opengl = 'auto'
178   need_api_gles2 = 'auto'
179 else
180   need_api_opengl = 'no'
181   need_api_gles2 = 'no'
182   foreach api : gl_apis
183     if api == 'opengl'
184       need_api_opengl = 'yes'
185     elif api == 'gles2'
186       need_api_gles2 = 'yes'
187     else
188       error('Unsupported GL api provided ' + api)
189     endif
190   endforeach
191 endif
192
193 gl_platforms = get_option('gl_platform')
194 if gl_platforms.contains('auto')
195   need_platform_egl = 'auto'
196   need_platform_glx = 'auto'
197   need_platform_cgl = 'auto'
198   need_platform_wgl = 'auto'
199   need_platform_eagl = 'auto'
200 else
201   need_platform_egl = 'no'
202   need_platform_glx = 'no'
203   need_platform_cgl = 'no'
204   need_platform_wgl = 'no'
205   need_platform_eagl = 'no'
206   foreach platform : gl_platforms
207     if platform == 'egl'
208       need_platform_egl = 'yes'
209     elif platform == 'glx'
210       need_platform_glx = 'yes'
211     elif platform == 'cgl'
212       need_platform_cgl = 'yes'
213     elif platform == 'wgl'
214       need_platform_wgl = 'yes'
215 #    elif platform == 'eagl'
216 #      need_platform_eagl = 'yes'
217     else
218       error('Unsupported GL platform provided ' + platform)
219     endif
220   endforeach
221 endif
222
223 gl_winsys = get_option('gl_winsys')
224 if gl_winsys.contains('auto')
225   need_win_x11 = 'auto'
226   need_win_wayland = 'auto'
227   need_win_win32 = 'auto'
228   need_win_cocoa = 'auto'
229   need_win_eagl = 'auto'
230   need_win_dispmanx = 'auto'
231   need_win_viv_fb = 'auto'
232   need_win_gbm = 'auto'
233 else
234   need_win_x11 = 'no'
235   need_win_wayland = 'no'
236   need_win_win32 = 'no'
237   need_win_cocoa = 'no'
238   need_win_eagl = 'no'
239   need_win_dispmanx = 'no'
240   need_win_viv_fb = 'no'
241   need_win_gbm = 'no'
242   foreach winsys : gl_winsys
243     if winsys == 'x11'
244       need_win_x11 = 'yes'
245     elif winsys == 'wayland'
246       need_win_wayland = 'yes'
247     elif winsys == 'win32'
248       need_win_win32 = 'yes'
249     elif winsys == 'cocoa'
250       need_win_cocoa = 'yes'
251 #    elif winsys == 'eagl'
252 #      need_win_eagl = 'yes'
253     elif winsys == 'dispmanx'
254       need_win_dispmanx = 'yes'
255     elif winsys == 'viv-fb'
256       need_win_viv_fb = 'yes'
257     elif winsys == 'gbm'
258       need_win_gbm = 'no'
259     else
260       error('Unsupported GL winsys provided ' + winsys)
261     endif
262   endforeach
263 endif
264
265 gl_include_header = '''
266 #ifdef __GNUC__
267 #  pragma GCC diagnostic push
268 #  pragma GCC diagnostic ignored "-Wredundant-decls"
269 #endif
270 #ifndef GL_GLEXT_PROTOTYPES
271 #define GL_GLEXT_PROTOTYPES 1
272 #endif
273 '''
274
275 # convoluted way of getting at the subproject taking into account the wrap-mode
276 # so we don't download a subproject unless allowed
277 # FIXME: dependency() needs a valid name to attempt to find otherwise meson
278 # short-circuits and will always fail and never look into the fallback
279 # subproject. https://github.com/mesonbuild/meson/issues/3754
280 gl_header_dep = dependency('gl-headers-not-findable', method : 'pkg-config',
281     fallback : ['gl-headers', 'gl_headers_dummy_dep'], required : false)
282 if gl_header_dep.type_name() == 'internal'
283   # this will only contain the includes of headers that are not found
284   compat_includes = subproject('gl-headers').get_variable('compatibility_includes')
285 else
286   compat_includes = []
287 endif
288
289 # Desktop OpenGL checks
290 gl_dep = unneeded_dep
291 glx_dep = unneeded_dep
292 if need_api_opengl != 'no' or need_platform_glx != 'no'
293   if host_machine.system() == 'darwin'
294     gl_dep = dependency('OpenGL', required : false)
295   else
296     # override meson's braindead gl detection on osx/windows/etc by forcing pkg-config
297     gl_dep = dependency('gl', method: 'pkg-config', required : false)
298   endif
299
300   if not gl_dep.found()
301     if host_machine.system() == 'windows'
302       gl_dep = cc.find_library('opengl32', required : false)
303     else
304       gl_dep = cc.find_library('GL', required : false)
305     endif
306
307     if not cc.has_header('GL/gl.h', include_directories : compat_includes)
308       gl_dep = unneeded_dep
309     endif
310
311     if not gl_dep.found() and need_api_opengl == 'yes'
312       error ('Could not find requested OpenGL library')
313     endif
314
315     if gl_dep.found()
316       gl_includes += [compat_includes]
317     endif
318   endif
319
320   glx_dep = gl_dep
321   if need_api_opengl == 'no'
322     gl_dep = unneeded_dep
323   endif
324   if need_platform_glx == 'no'
325     glx_dep = unneeded_dep
326   endif
327
328   opengl_includes = ''
329   if host_machine.system() == 'darwin'
330     opengl_includes += '''
331 #include <OpenGL/OpenGL.h>
332 #include <OpenGL/gl.h>
333 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
334 # define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
335 # include <OpenGL/gl3.h>
336 #endif
337 '''
338   else
339     opengl_includes += '''
340 #if _MSC_VER
341 # include <windows.h>
342 #endif
343 #include <GL/gl.h>
344 #if __WIN32__ || _WIN32
345 # include <GL/glext.h>
346 #endif
347 '''
348   endif
349 endif
350
351 # GLES2 checks
352 gles2_dep = unneeded_dep
353 gles3_h = false
354 gles3ext3_h = false
355 if need_api_gles2 != 'no'
356   gles2_dep = dependency('glesv2', required : false)
357   if not gles2_dep.found()
358 #    if host_machine.system() == 'windows'
359 #    elif host_machine.system() == 'darwin'
360 #      gles2_dep = cc.find_library('GLESv2', required : false)
361 #    else
362       gles2_dep = cc.find_library('GLESv2', required : false)
363 #    endif
364
365      if not cc.has_header('GLES2/gl2.h', include_directories : compat_includes)
366        gles2_dep = unneeded_dep
367      endif
368
369     if not gles2_dep.found() and need_api_gles2 == 'yes'
370       error ('Could not find requested OpenGL ES library')
371     endif
372
373     if gles2_dep.found()
374       gl_includes += [compat_includes]
375     endif
376   endif
377
378   gles3_h = gles2_dep.found() and cc.has_header('GLES3/gl3.h', dependencies : gles2_dep, include_directories : compat_includes)
379
380   gles_includes = '''
381 #ifdef HAVE_IOS /* FIXME */
382 # include <OpenGLES/ES2/gl.h>
383 # include <OpenGLES/ES2/glext.h>
384 #else'''
385   if gles3_h
386     gl_includes += [compat_includes]
387     gles3ext3_h = gles3_h and cc.has_header('GLES3/gl3ext.h', dependencies : gles2_dep, include_directories : compat_includes)
388     gles_includes += '''
389 # include <GLES3/gl3.h>
390 # include <GLES2/gl2ext.h>'''
391     if gles3ext3_h
392       gles_includes += '''
393 # include <GLES3/gl3ext.h>'''
394     endif
395   else
396     gles_includes += '''
397 # include <GLES2/gl2.h>
398 # include <GLES2/gl2ext.h>'''
399   endif
400   gles_includes += '''
401 #endif
402 '''
403 endif
404
405 # can we include both gles2 and opengl headers?
406 if gles2_dep.found() and gl_dep.found()
407   gl_include_block = gl_include_header + gles_includes + opengl_includes
408   # TODO: Revert to passing gl_include_block via prefix: once
409   # https://github.com/mesonbuild/meson/issues/2364 is fixed
410   if not cc.compiles(gl_include_block + '\n' + 'void f (void) {}',dependencies : [gles2_dep, gl_dep], include_directories : compat_includes)
411     message ('Cannot include both OpenGL and OpenGL ES headers')
412     if need_api_gles2 != 'yes'
413       gles2_dep = unneeded_dep
414     elif need_api_opengl != 'yes'
415       gl_dep = unneeded_dep
416     else
417       error('Both OpenGL and OpenGL ES were requested but cannot be included together')
418     endif
419   endif
420 endif
421 gl_include_block = gl_include_header
422 if gles2_dep.found()
423   gl_include_block += gles_includes
424 endif
425 if gl_dep.found()
426   gl_include_block += opengl_includes
427 endif
428
429 if gles2_dep.found()
430   gl_lib_deps += gles2_dep
431   glconf.set10('GST_GL_HAVE_GLES2', 1)
432   if gles3_h
433     glconf.set10('GST_GL_HAVE_GLES3', 1)
434     if gles3ext3_h
435       glconf.set10('GST_GL_HAVE_GLES3EXT3_H', 1)
436     endif
437   endif
438   enabled_gl_apis += 'gles2'
439 endif
440
441 if gl_dep.found()
442   gl_lib_deps += gl_dep
443   glconf.set10('GST_GL_HAVE_OPENGL', 1)
444   enabled_gl_apis += 'opengl'
445 endif
446
447 # EGL checks
448 egl_dep = unneeded_dep
449 if need_platform_egl != 'no'
450   egl_dep = dependency('egl', required : false)
451   if not egl_dep.found()
452     egl_dep = cc.find_library('EGL', required : false)
453
454     if not egl_dep.found() and need_platform_egl == 'yes'
455       error ('Could not find requested EGL library')
456     endif
457   endif
458
459   if egl_dep.found()
460     gl_sources += [
461       'egl/gstegl.c',
462       'egl/gsteglimage.c',
463       'egl/gstglcontext_egl.c',
464       'egl/gstgldisplay_egl.c',
465       'egl/gstglmemoryegl.c',
466     ]
467     gl_egl_headers += [
468       'egl/gstegl.h',
469       'egl/gsteglimage.h',
470       'egl/gstgldisplay_egl.h',
471       'egl/gstglmemoryegl.h',
472     ]
473     gl_platform_deps += egl_dep
474     glconf.set10('GST_GL_HAVE_PLATFORM_EGL', 1)
475
476     if cc.has_header('libdrm/drm_fourcc.h')
477       gl_misc_deps += allocators_dep
478       glconf.set10('GST_GL_HAVE_DMABUF', 1)
479     endif
480
481     egl_includes = '''
482 #include <EGL/egl.h>
483 #include <EGL/eglext.h>
484 '''
485     enabled_gl_platforms += 'egl'
486   endif
487
488 endif
489
490 # wayland checks
491 wayland_client_dep = unneeded_dep
492 wayland_cursor_dep = unneeded_dep
493 wayland_egl_dep = unneeded_dep
494 if need_win_wayland != 'no'
495   if need_win_wayland == 'yes'
496     if need_platform_egl == 'no'
497       error('Impossible situation requested: Cannot use Wayland without EGL support')
498     endif
499   endif
500   if not egl_dep.found()
501     if need_win_wayland == 'yes'
502       error ('Could not find EGL libraries for wayland')
503     else
504       message ('Could not find EGL libraries for wayland')
505     endif
506   else
507     wayland_client_dep = dependency('wayland-client', version : '>= 1.0', required : false)
508     wayland_cursor_dep = dependency('wayland-cursor', version : '>= 1.0', required : false)
509     wayland_egl_dep = dependency('wayland-egl', version : '>= 1.0', required : false)
510
511     if wayland_client_dep.found() and wayland_cursor_dep.found() and wayland_egl_dep.found()
512       gl_sources += [
513         'wayland/gstgldisplay_wayland.c',
514         'wayland/gstglwindow_wayland_egl.c',
515         'wayland/wayland_event_source.c',
516       ]
517       gl_wayland_headers += [
518         'wayland/gstgldisplay_wayland.h'
519       ]
520       glconf.set('GST_GL_HAVE_WINDOW_WAYLAND', 1)
521       gl_winsys_deps += [wayland_client_dep, wayland_cursor_dep, wayland_egl_dep]
522       enabled_gl_winsys += 'wayland'
523     else
524       if need_win_wayland == 'yes'
525         error ('Could not find requested Wayland libraries')
526       endif
527       wayland_client_dep = unneeded_dep
528       wayland_cursor_dep = unneeded_dep
529       wayland_egl_dep = unneeded_dep
530     endif
531   endif
532 endif
533
534 # X11 checks
535 if need_platform_glx == 'yes'
536   if need_win_x11 == 'no'
537     error('Impossible situation requested: Cannot use GLX without X11 support')
538   elif need_api_opengl == 'no'
539     error('Impossible situation requested: Cannot use GLX without the OpenGL library')
540   endif
541 endif
542
543 if need_win_x11 != 'no'
544   xcb_dep = dependency('x11-xcb', required : false)
545   if x11_dep.found() and xcb_dep.found()
546     gl_sources += [
547       'x11/gstgldisplay_x11.c',
548       'x11/gstglwindow_x11.c',
549       'x11/xcb_event_source.c',
550     ]
551     gl_x11_headers += [
552       'x11/gstgldisplay_x11.h',
553     ]
554     glconf.set('GST_GL_HAVE_WINDOW_X11', 1)
555     gl_winsys_deps += [x11_dep, xcb_dep]
556     enabled_gl_winsys += 'x11'
557
558     if need_platform_glx != 'no' and glx_dep.found()
559       glconf.set('GST_GL_HAVE_PLATFORM_GLX', 1)
560       gl_sources += [
561         'x11/gstglcontext_glx.c',
562       ]
563       # GLX is in the opengl library on linux
564       gl_platform_deps += glx_dep
565       enabled_gl_platforms += 'glx'
566     endif
567   elif need_win_x11 == 'yes'
568     error ('Could not find requested X11 libraries')
569   endif
570 endif
571
572 bcm_host_dep = unneeded_dep
573 if need_win_dispmanx != 'no'
574
575   # Try pkg-config for bcm_host then fallback to find_library to also
576   # support older distribution
577   bcm_host_dep = dependency('bcm_host', required : false)
578   if not bcm_host_dep.found()
579     bcm_host_dep = cc.find_library('bcm_host', required : false)
580   endif
581
582   if bcm_host_dep.found()
583     if not egl_dep.found()
584       error('dispmanx requires the use of egl')
585     endif
586
587     gl_sources += [
588       'dispmanx/gstglwindow_dispmanx_egl.c'
589     ]
590
591     glconf.set('GST_GL_HAVE_WINDOW_DISPMANX', 1)
592     gl_winsys_deps += bcm_host_dep
593     enabled_gl_winsys += 'dispmanx'
594     gl_cpp_args += ['-DUSE_EGL_RPI']
595   elif need_win_dispmanx == 'yes'
596     error('Could not find dispmanx libraries')
597   endif
598 endif
599
600 # win32 checks
601 if need_platform_wgl == 'yes'
602   if need_win_win32 == 'no'
603     error('Impossible situation requested: Cannot use WGL without the win32 window system')
604   endif
605 endif
606
607 if need_platform_wgl != 'no' and need_win_win32 != 'no'
608   gdi_dep = cc.find_library('gdi32', required : false)
609   # FIXME: Revert back to has_header once it gains prefix support
610   wglext_h = cc.has_header_symbol('GL/wglext.h', 'WGL_WGLEXT_VERSION',
611                                   prefix : '''#include <windows.h>
612                                               #include <GL/gl.h>''',
613                                   include_directories : compat_includes)
614
615   if wglext_h and gdi_dep.found() and gl_dep.found()
616     gl_includes += [compat_includes]
617     gl_platform_deps += gdi_dep
618     gl_sources += [
619       'win32/win32_message_source.c',
620       'win32/gstglwindow_win32.c',
621       'win32/gstglwindow_win32.c',
622       'win32/gstglcontext_wgl.c',
623     ]
624     enabled_gl_winsys += 'win32'
625     gl_winsys_deps += gdi_dep
626     enabled_gl_platforms += 'wgl'
627     glconf.set('GST_GL_HAVE_WINDOW_WIN32', 1)
628     glconf.set('GST_GL_HAVE_PLATFORM_WGL', 1)
629   endif
630 endif
631
632 # OSX check
633 if need_platform_cgl == 'yes'
634   if need_win_cocoa == 'no'
635     error('Impossible situation requested: Cannot use CGL without Cocoa support')
636   elif need_api_opengl == 'no'
637     error('Impossible situation requested: Cannot use CGL without the OpenGL library')
638   endif
639 elif need_platform_cgl == 'no' and need_win_cocoa == 'yes'
640   error('Impossible situation requested: Cannot use Cocoa without CGL support')
641 endif
642
643 if host_machine.system() == 'darwin'
644   if not have_objc
645     error('No ObjC compiler found')
646   endif
647
648   objc = meson.get_compiler('objc')
649   if not objc.has_argument('-fobjc-arc')
650     error('ARC is required for building')
651   endif
652
653   gl_objc_args += ['-fobjc-arc']
654
655   quartzcore_dep = dependency('QuartzCore', required : false)
656   corefoundation_dep = dependency('CoreFoundation', required : false)
657
658   if need_platform_cgl != 'no'
659     if quartzcore_dep.found() and corefoundation_dep.found()
660       gl_platform_deps += [quartzcore_dep, corefoundation_dep]
661       enabled_gl_platforms += 'cgl'
662       glconf.set10('GST_GL_HAVE_PLATFORM_CGL', 1)
663
664       if need_win_cocoa != 'no'
665         cocoa_dep = dependency('Cocoa', required : false)
666         if cocoa_dep.found()
667           gl_sources += [
668             'cocoa/gstglcaopengllayer.m',
669             'cocoa/gstglcontext_cocoa.m',
670             'cocoa/gstgldisplay_cocoa.m',
671             'cocoa/gstglwindow_cocoa.m'
672           ]
673           gl_winsys_deps += cocoa_dep
674           enabled_gl_winsys += 'cocoa'
675           glconf.set10('GST_GL_HAVE_WINDOW_COCOA', 1)
676         elif need_win_cocoa == 'yes'
677           error('Could not find Cocoa')
678         endif
679       endif
680     elif need_platform_cgl == 'yes'
681       error('Could not find CGL dependencies')
682     endif
683   endif
684 endif
685
686 # GDM Checks
687 gbm_gudev_dep = unneeded_dep
688 gbm_libdrm_dep = unneeded_dep
689 gbm_dep = unneeded_dep
690 if need_win_gbm != 'no'
691   if need_win_gbm == 'yes'
692     if need_platform_egl == 'no'
693       error('Impossible situation requested: Cannot use GBM without EGL support')
694     endif
695   endif
696
697   gbm_gudev_dep = dependency('gudev-1.0', version : '>=147', required : false)
698   gbm_libdrm_dep = dependency('libdrm', version : '>= 2.4.55', required : false)
699   gbm_dep = dependency('gbm', required : false)
700   if egl_dep.found() and gbm_gudev_dep.found() and gbm_libdrm_dep.found() and gbm_dep.found()
701     gl_sources += [
702       'gbm/gstgldisplay_gbm.c',
703       'gbm/gstgl_gbm_utils.c',
704       'gbm/gstglwindow_gbm_egl.c',
705     ]
706     enabled_gl_winsys += 'gbm'
707     gl_winsys_deps += [gbm_gudev_dep, gbm_libdrm_dep, gbm_dep]
708     glconf.set('GST_GL_HAVE_WINDOW_GBM', 1)
709   else
710     if need_win_gbm == 'yes'
711       error ('Could not find requested GBM libraries')
712     endif
713     gbm_gudev_dep = unneeded_dep
714     gbm_libdrm_dep = unneeded_dep
715     gbm_dep = unneeded_dep
716   endif
717 endif
718
719 if need_platform_egl != 'no' and need_win_viv_fb != 'no'
720   if egl_dep.found() and cc.has_function ('fbGetDisplay', dependencies : egl_dep)
721     if cc.has_function ('glTexDirectVIV', dependencies : gles2_dep)
722       enabled_gl_winsys += 'viv-fb'
723       glconf.set10('GST_GL_HAVE_WINDOW_VIV_FB', 1)
724       glconf.set10('GST_GL_HAVE_VIV_DIRECTVIV', 1)
725       gl_sources += [
726         'viv-fb/gstgldisplay_viv_fb.c',
727         'viv-fb/gstglwindow_viv_fb_egl.c',
728       ]
729       gl_cpp_args += ['-DEGL_API_FB']
730     endif
731   endif
732 endif
733
734 # TODO: Add rest of gl config here.
735 # iOS, specific support
736
737 build_gstgl = true
738 if enabled_gl_apis.length() == 0
739   message('No OpenGL API libraries found or requested')
740   build_gstgl = false
741 endif
742 if enabled_gl_platforms.length() == 0
743   message('No OpenGL Platforms found or requested')
744   build_gstgl = false
745 endif
746 if enabled_gl_winsys.length() == 0
747   message('No OpenGL Window systems found or requested')
748   build_gstgl = false
749 endif
750
751 if build_gstgl
752   # find some types that may or may not be defined
753   if cc.has_type('GLeglImageOES', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
754     glconf.set('GST_GL_HAVE_GLEGLIMAGEOES', 1)
755   endif
756   if cc.has_type('GLchar', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
757     glconf.set('GST_GL_HAVE_GLCHAR', 1)
758   endif
759   if cc.has_type('GLsizeiptr', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
760     glconf.set('GST_GL_HAVE_GLSIZEIPTR', 1)
761   endif
762   if cc.has_type('GLintptr', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
763     glconf.set('GST_GL_HAVE_GLINTPTR', 1)
764   endif
765   if cc.has_type('GLsync', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
766     glconf.set('GST_GL_HAVE_GLSYNC', 1)
767   endif
768   if cc.has_type('GLuint64', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
769     glconf.set('GST_GL_HAVE_GLUINT64', 1)
770   endif
771   if cc.has_type('GLint64', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
772     glconf.set('GST_GL_HAVE_GLINT64', 1)
773   endif
774   if egl_dep.found() and cc.has_type('EGLAttrib', prefix : gl_include_block + egl_includes, dependencies : gl_lib_deps + [egl_dep], include_directories : gl_includes)
775     glconf.set('GST_GL_HAVE_EGLATTRIB', 1)
776   endif
777   if egl_dep.found() and cc.has_type('EGLuint64KHR', prefix : gl_include_block + egl_includes, dependencies : gl_lib_deps + [egl_dep], include_directories : gl_includes)
778     glconf.set('GST_GL_HAVE_EGLUINT64KHR', 1)
779   endif
780
781   message('Building libgstgl with GL api:      ' + ' '.join(enabled_gl_apis))
782   message('Building libgstgl with GL platform: ' + ' '.join(enabled_gl_platforms))
783   message('Building libgstgl with GL winsys:   ' + ' '.join(enabled_gl_winsys))
784
785   install_headers(gl_headers, subdir : 'gstreamer-1.0/gst/gl')
786   install_headers(gl_cocoa_headers, subdir : 'gstreamer-1.0/gst/gl/cocoa')
787   install_headers(gl_egl_headers, subdir : 'gstreamer-1.0/gst/gl/egl')
788   install_headers(gl_prototype_headers, subdir : 'gstreamer-1.0/gst/gl/glprototypes')
789   install_headers(gl_x11_headers, subdir : 'gstreamer-1.0/gst/gl/x11')
790   install_headers(gl_wayland_headers, subdir : 'gstreamer-1.0/gst/gl/wayland')
791
792   configure_file(input : 'gstglconfig.h.meson',
793     output : 'gstglconfig.h',
794     install_dir : get_option('libdir') + '/gstreamer-1.0/include/gst/gl',
795     configuration : glconf)
796
797   gstgl = library('gstgl-' + api_version,
798     gl_sources,
799     c_args : gst_plugins_base_args + gl_cpp_args,
800     objc_args : gst_plugins_base_args + gl_cpp_args + gl_objc_args,
801     include_directories : [configinc, libsinc, gl_includes],
802     version : libversion,
803     soversion : soversion,
804     install : true,
805     dependencies : [gst_base_dep, video_dep, allocators_dep, gmodule_dep,
806                     gl_lib_deps, gl_platform_deps, gl_winsys_deps, gl_misc_deps])
807   gen_sources = []
808   if build_gir
809     gl_gir = gnome.generate_gir(gstgl,
810       sources : gl_sources + gl_headers,
811       namespace : 'GstGL',
812       nsversion : api_version,
813       identifier_prefix : 'Gst',
814       symbol_prefix : 'gst',
815       export_packages : 'gstreamer-gl-1.0',
816       includes : ['Gst-1.0', 'GstBase-1.0', 'GstVideo-1.0'],
817       install : true,
818       extra_args : gir_init_section + ['--c-include=gst/gl/gl.h'],
819       dependencies : [video_dep, gst_dep, gst_base_dep]
820     )
821     gen_sources += gl_gir
822   endif
823
824
825   gstgl_dep = declare_dependency(link_with : gstgl,
826     include_directories : [libsinc, compat_includes],
827     sources: gen_sources,
828     dependencies : [video_dep, gst_base_dep] + gl_winsys_deps)
829
830 elif get_option('gl').enabled()
831   error('GStreamer OpenGL integration required via options, but needed dependencies not found.')
832 endif