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