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