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