meson/gl: use separate deps for gl and glx
[platform/upstream/gstreamer.git] / gst-libs / gst / gl / meson.build
1 gl_sources = [
2   'gstglapi.c',
3   'gstglbasefilter.c',
4   'gstglbasememory.c',
5   'gstglcolorconvert.c',
6   'gstglcontrolbindingproxy.c',
7   'gstglbuffer.c',
8   'gstglbufferpool.c',
9   'gstglcontext.c',
10   'gstgldebug.c',
11   'gstgldisplay.c',
12   'gstglfeature.c',
13   'gstglfilter.c',
14   'gstglformat.c',
15   'gstglframebuffer.c',
16   'gstglmemory.c',
17   'gstglmemorypbo.c',
18   'gstgloverlaycompositor.c',
19   'gstglquery.c',
20   'gstglrenderbuffer.c',
21   'gstglshader.c',
22   'gstglshaderstrings.c',
23   'gstglsl.c',
24   'gstglslstage.c',
25   'gstglsyncmeta.c',
26   'gstglupload.c',
27   'gstglutils.c',
28   'gstglviewconvert.c',
29   'gstglwindow.c',
30 ]
31
32 gl_headers = [
33   'gl.h',
34   'gstgl_enums.h',
35   'gstgl_fwd.h',
36   'gstglapi.h',
37   'gstglbasefilter.h',
38   'gstglbasememory.h',
39   'gstglbuffer.h',
40   'gstglbufferpool.h',
41   'gstglcolorconvert.h',
42   'gstglcontext.h',
43   'gstglcontrolbindingproxy.h',
44   'gstgldebug.h',
45   'gstgldisplay.h',
46   'gstglfeature.h',
47   'gstglfilter.h',
48   'gstglformat.h',
49   'gstglframebuffer.h',
50   'gstglmemory.h',
51   'gstglmemorypbo.h',
52   'gstgloverlaycompositor.h',
53   'gstglquery.h',
54   'gstglshader.h',
55   'gstglshaderstrings.h',
56   'gstglsl.h',
57   'gstglslstage.h',
58   'gstglsyncmeta.h',
59   'gstglupload.h',
60   'gstglutils.h',
61   'gstglviewconvert.h',
62   'gstglwindow.h',
63 ]
64
65 gl_prototype_headers = [
66   'glprototypes/all_functions.h',
67   'glprototypes/base.h',
68   'glprototypes/blending.h',
69   'glprototypes/buffers.h',
70   'glprototypes/debug.h',
71   'glprototypes/eglimage.h',
72   'glprototypes/fbo.h',
73   'glprototypes/fixedfunction.h',
74   'glprototypes/gles.h',
75   'glprototypes/gstgl_compat.h',
76   'glprototypes/gstgl_gles2compat.h',
77   'glprototypes/Makefile.am',
78   'glprototypes/opengl.h',
79   'glprototypes/query.h',
80   'glprototypes/README',
81   'glprototypes/shaders.h',
82   'glprototypes/sync.h',
83   'glprototypes/vao.h',
84 ]
85
86 gl_x11_headers = []
87 gl_wayland_headers = []
88 gl_win32_headers = []
89 gl_cocoa_headers = []
90 gl_egl_headers = []
91
92 glconf = configuration_data()
93
94 gmodule_dep = dependency('gmodule-no-export-2.0')
95 unneeded_dep = dependency('', required : false)
96 if unneeded_dep.found()
97   error ('Found unfindable dependency')
98 endif
99
100 # OpenGL/GLES2 libraries
101 gl_lib_deps = []
102 # GL platform - EGL, GLX, CGL, WGL, etc
103 gl_platform_deps = []
104 # GL winsys - wayland, X11, Cocoa, win32, etc
105 gl_winsys_deps = []
106 # other things we need.
107 gl_misc_deps = []
108
109 enabled_gl_apis = []
110 enabled_gl_platforms = []
111 enabled_gl_winsys = []
112
113 # parse provided options
114 gl_apis_s = get_option ('with_gl_api')
115 if gl_apis_s == 'auto'
116   need_api_opengl = 'auto'
117   need_api_gles2 = 'auto'
118 else
119   need_api_opengl = 'no'
120   need_api_gles2 = 'no'
121   gl_apis = gl_apis_s.split(',')
122   foreach api : gl_apis
123     if api == 'opengl'
124       need_api_opengl = 'yes'
125     elif api == 'gles2'
126       need_api_gles2 = 'yes'
127     else
128       error('Unsupported GL api provided ' + api)
129     endif
130   endforeach
131 endif
132
133 gl_platforms_s = get_option ('with_gl_platform')
134 if gl_platforms_s == 'auto'
135   need_platform_egl = 'auto'
136   need_platform_glx = 'auto'
137   need_platform_cgl = 'auto'
138   need_platform_wgl = 'auto'
139   need_platform_eagl = 'auto'
140 else
141   need_platform_egl = 'no'
142   need_platform_glx = 'no'
143   need_platform_cgl = 'no'
144   need_platform_wgl = 'no'
145   need_platform_eagl = 'no'
146   gl_platforms = gl_platforms_s.split(',')
147   foreach platform : gl_platforms
148     if platform == 'egl'
149       need_platform_egl = 'yes'
150     elif platform == 'glx'
151       need_platform_glx = 'yes'
152 #    elif platform == 'cgl'
153 #      need_platform_cgl = 'yes'
154 #    elif platform == 'wgl'
155 #      need_platform_wgl = 'yes'
156 #    elif platform == 'eagl'
157 #      need_platform_eagl = 'yes'
158     else
159       error('Unsupported GL platform provided ' + platform)
160     endif
161   endforeach
162 endif
163
164 gl_winsys_s = get_option ('with_gl_winsys')
165 if gl_winsys_s == 'auto'
166   need_win_x11 = 'auto'
167   need_win_wayland = 'auto'
168   need_win_win32 = 'auto'
169   need_win_cocoa = 'auto'
170   need_win_eagl = 'auto'
171   need_win_dispmanx = 'auto'
172 else
173   need_win_x11 = 'no'
174   need_win_wayland = 'no'
175   need_win_win32 = 'no'
176   need_win_cocoa = 'no'
177   need_win_eagl = 'no'
178   need_win_dispmanx = 'no'
179   gl_winsys = gl_winsys_s.split(',')
180   foreach winsys : gl_winsys
181     if winsys == 'x11'
182       need_win_x11 = 'yes'
183     elif winsys == 'wayland'
184       need_win_wayland = 'yes'
185 #    elif winsys == 'win32'
186 #      need_win_win32 = 'yes'
187 #    elif winsys == 'cocoa'
188 #      need_win_cocoa = 'yes'
189 #    elif winsys == 'eagl'
190 #      need_win_eagl = 'yes'
191 #    elif winsys == 'dispmanx'
192 #      need_win_dispmanx = 'yes'
193     else
194       error('Unsupported GL winsys provided ' + platform)
195     endif
196   endforeach
197 endif
198
199 gl_include_header = '''
200 #ifdef __GNUC__
201 #  pragma GCC diagnostic push
202 #  pragma GCC diagnostic ignored "-Wredundant-decls"
203 #endif
204 #ifndef GL_GLEXT_PROTOTYPES
205 #define GL_GLEXT_PROTOTYPES 1
206 #endif
207 '''
208
209 # Desktop OpenGL checks
210 gl_dep = unneeded_dep
211 glx_dep = unneeded_dep
212 if need_api_opengl != 'no' and need_platform_glx != 'no'
213   gl_dep = dependency('GL', required : false)
214   if not gl_dep.found()
215 #    if host_machine.system() == 'windows'
216 #      gl_dep = cc.find_library('opengl32', required : false)
217 #    elif host_machine.system() == 'darwin'
218 #      gl_dep = cc.find_library('OpenGL', required : false)
219 #    else
220       gl_dep = cc.find_library('GL', required : false)
221 #    endif
222
223     if not gl_dep.found() and need_api_opengl == 'yes'
224       error ('Could not find requested OpenGL library')
225     endif
226   endif
227
228   glx_dep = gl_dep
229   if need_api_opengl == 'no'
230     gl_dep = unneeded_dep
231   endif
232   if need_platform_glx == 'no'
233     glx_dep = unneeded_dep
234   endif
235
236   opengl_includes = '''
237 #ifdef __APPLE__
238 # include <OpenGL/OpenGL.h>
239 # include <OpenGL/gl.h>
240 # if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
241 #  define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
242 #  include <OpenGL/gl3.h>
243 # endif
244 #else
245 # include <GL/gl.h>
246 # if __WIN32__ || _WIN32
247 #  include <GL/glext.h>
248 # endif
249 #endif
250 '''
251 endif
252
253 # GLES2 checks
254 gles2_dep = unneeded_dep
255 if need_api_gles2 != 'no'
256   gles2_dep = dependency('GLESv2', required : false)
257   if not gles2_dep.found()
258 #    if host_machine.system() == 'windows'
259 #    elif host_machine.system() == 'darwin'
260 #      gles2_dep = cc.find_library('GLESv2', required : false)
261 #    else
262       gles2_dep = cc.find_library('GLESv2', required : false)
263 #    endif
264
265     if not gles2_dep.found() and need_api_gles2 == 'yes'
266       error ('Could not find requested OpenGL ES library')
267     endif
268   endif
269
270   gles3_h = gles2_dep.found() and cc.has_header('GLES3/gl3.h', required : false, dependencies : gles2_dep)
271
272   gles_includes = '''
273 #ifdef HAVE_IOS /* FIXME */
274 # include <OpenGLES/ES2/gl.h>
275 # include <OpenGLES/ES2/glext.h>
276 #else'''
277   if gles3_h
278     gles_includes += '''
279 # include <GLES3/gl3.h>
280 # include <GLES3/gl3ext.h>'''
281   else
282     gles_includes += '''
283 # include <GLES2/gl2.h>
284 # include <GLES2/gl2ext.h>'''
285   endif
286   gles_includes += '''
287 #endif
288 '''
289 endif
290
291 # can we include both gles2 and opengl headers?
292 if gles2_dep.found() and gl_dep.found()
293   gl_include_block = gl_include_header + gles_includes + opengl_includes
294   if not cc.compiles('void f (void) {}', prefix : gl_include_block, dependencies : [gles2_dep, gl_dep] )
295     message ('Cannot include both OpenGL and OpenGL ES headers')
296     if need_gles2 != 'yes'
297       gles2_dep = unneeded_dep
298     elif need_opengl != 'yes'
299       gl_dep = unneeded_dep
300     else
301       error('Both OpenGL and OpenGL ES were requested but cannot be included together')
302     endif
303   endif
304 endif
305 gl_include_block = gl_include_header
306 if gles2_dep.found()
307   gl_include_block += gles_includes
308 endif
309 if gl_dep.found()
310   gl_include_block += opengl_includes
311 endif
312
313 if gles2_dep.found()
314   gl_lib_deps += gles2_dep
315   glconf.set10('GST_GL_HAVE_GLES2', 1)
316   if gles3_h
317     glconf.set10('GST_GL_HAVE_GLES3', 1)
318   endif
319   enabled_gl_apis += 'gles2'
320 endif
321
322 if gl_dep.found()
323   gl_lib_deps += gl_dep
324   glconf.set10('GST_GL_HAVE_OPENGL', 1)
325   enabled_gl_apis += 'opengl'
326 endif
327
328 # EGL checks
329 egl_dep = unneeded_dep
330 if need_platform_egl != 'no'
331   egl_dep = dependency('EGL', required : false)
332   if not egl_dep.found()
333     egl_dep = cc.find_library('EGL', required : false)
334
335     if not egl_dep.found() and need_platform_egl == 'yes'
336       error ('Could not find requested EGL library')
337     endif
338   endif
339
340   if egl_dep.found()
341     gl_sources += [
342       'egl/gsteglimage.c',
343       'egl/gstglcontext_egl.c',
344       'egl/gstgldisplay_egl.c',
345       'egl/gstglmemoryegl.c',
346     ]
347     gl_egl_headers += [
348       'egl/gstegl.h',
349       'egl/gsteglimage.h',
350       'egl/gstglcontext_egl.h',
351       'egl/gstgldisplay_egl.h',
352       'egl/gstglmemoryegl.h',
353     ]
354     gl_platform_deps += egl_dep
355     glconf.set10('GST_GL_HAVE_PLATFORM_EGL', 1)
356
357     if cc.has_header('libdrm/drm_fourcc.h', required : false)
358       gl_misc_deps += gstallocators_dep
359       glconf.set10('GST_GL_HAVE_DMABUF', 1)
360     endif
361
362     egl_includes = '''
363 #include <EGL/egl.h>
364 #include <EGL/eglext.h>
365 '''
366   endif
367
368   enabled_gl_platforms += 'egl'
369 endif
370
371 # wayland checks
372 wayland_client_dep = unneeded_dep
373 wayland_cursor_dep = unneeded_dep
374 wayland_egl_dep = unneeded_dep
375 if need_win_wayland != 'no'
376   if need_win_wayland == 'yes'
377     if need_platform_egl == 'no'
378       error('Impossible situation requested: Cannot use Wayland without EGL support')
379     endif
380   endif
381   if not egl_dep.found()
382     if need_win_wayland == 'yes'
383       error ('Could not find EGL libraries for wayland')
384     else
385       message ('Could not find EGL libraries for wayland')
386     endif
387   else
388     wayland_client_dep = dependency('wayland-client', version : '>= 1.0', required : false)
389     wayland_cursor_dep = dependency('wayland-cursor', version : '>= 1.0', required : false)
390     wayland_egl_dep = dependency('wayland-egl', version : '>= 1.0', required : false)
391
392     if wayland_client_dep.found() and wayland_cursor_dep.found() and wayland_egl_dep.found()
393       gl_sources += [
394         'wayland/gstgldisplay_wayland.c',
395         'wayland/gstglwindow_wayland_egl.c',
396         'wayland/wayland_event_source.c',
397       ]
398       glconf.set('GST_GL_HAVE_WINDOW_WAYLAND', 1)
399       gl_winsys_deps += [wayland_client_dep, wayland_cursor_dep, wayland_egl_dep]
400       enabled_gl_winsys += 'wayland'
401     else
402       if need_win_wayland == 'yes'
403         error ('Could not find requested Wayland libraries')
404       endif
405       wayland_client_dep = unneeded_dep
406       wayland_cursor_dep = unneeded_dep
407       wayland_egl_dep = unneeded_dep
408     endif
409   endif
410 endif
411
412 # X11 checks
413 if need_platform_glx == 'yes'
414   if need_win_x11 == 'no'
415     error('Impossible situation requested: Cannot use GLX without X11 support')
416   elif need_api_opengl == 'no'
417     error('Impossible situation requested: Cannot use GLX without the OpenGL library')
418   endif
419 endif
420
421 if need_win_x11 != 'no'
422   if x11_dep.found()
423     gl_sources += [
424       'x11/gstgldisplay_x11.c',
425       'x11/gstglwindow_x11.c',
426       'x11/x11_event_source.c',
427     ]
428     gl_x11_headers += [
429       'x11/gstgldisplay_x11.h',
430     ]
431     glconf.set('GST_GL_HAVE_WINDOW_X11', 1)
432     gl_winsys_deps += x11_dep
433     enabled_gl_winsys += 'x11'
434
435     if need_platform_glx != 'no' and glx_dep.found()
436       glconf.set('GST_GL_HAVE_PLATFORM_GLX', 1)
437       gl_sources += [
438         'x11/gstglcontext_glx.c',
439       ]
440       # GLX is in the opengl library on linux
441       gl_platform_deps += glx_dep
442       enabled_gl_platforms += 'glx'
443     endif
444   elif need_win_x11 == 'yes'
445     error ('Could not find requested X11 libraries')
446   endif
447 endif
448
449 # win32 checks
450 if need_platform_wgl == 'yes'
451   if need_win_win32 == 'no'
452     error('Impossible situation requested: Cannot use WGL without the win32 window system')
453   endif
454 endif
455
456 # XXX: untested
457 #if need_platform_wgl != 'no' and need_win_win32 != 'no'
458 #  gdi_dep = cc.find_library('gdi32', required : false)
459 #
460 #  if cc.has_header('GL/wglext.h') and gdi_dep.found() and gl_dep.found()
461 #    gl_platform_deps += gdi_dep
462 #    gl_sources += [
463 #      'win32/gstglwindow_win32.c',
464 #      'win32/gstglwindow_win32.c',
465 #    ]
466 #    enabled_gl_winsys += 'win32'
467 #    enabled_gl_platforms += 'wgl'
468 #  endif
469 #endif
470
471 if host_machine.system() == 'darwin'
472   # FIXME: how to know if we're on iOS or OS X?
473 #  gl_cocoa_headers += [
474 #    'gstglcontext_cocoa.h',
475 #    'gstglcaopengllayer.h',
476 #  ]
477 endif
478
479 # TODO: Add rest of gl config here.
480 # --with-{egl,gles2,opengl}-module-name
481 # rpi, arm-mali, iOS, OS X, win32 specific support
482
483 build_gstgl = true
484 if gl_lib_deps.length() == 0
485   message('No OpenGL API libraries found or requested')
486   build_gstgl = false
487 endif
488 if gl_platform_deps.length() == 0
489   message('No OpenGL Platforms found or requested')
490   build_gstgl = false
491 endif
492 if gl_winsys_deps.length() == 0
493   message('No OpenGL Window systems found or requested')
494   build_gstgl = false
495 endif
496
497 if build_gstgl
498   # find some types that may or may not be defined
499   if cc.has_type('GLeglImageOES', prefix : gl_include_block, dependencies : gl_lib_deps)
500     glconf.set('GST_GL_HAVE_GLEGLIMAGEOES', 1)
501   endif
502   if cc.has_type('GLchar', prefix : gl_include_block, dependencies : gl_lib_deps)
503     glconf.set('GST_GL_HAVE_GLCHAR', 1)
504   endif
505   if cc.has_type('GLsizeiptr', prefix : gl_include_block, dependencies : gl_lib_deps)
506     glconf.set('GST_GL_HAVE_GLSIZEIPTR', 1)
507   endif
508   if cc.has_type('GLintptr', prefix : gl_include_block, dependencies : gl_lib_deps)
509     glconf.set('GST_GL_HAVE_GLINTPTR', 1)
510   endif
511   if cc.has_type('GLsync', prefix : gl_include_block, dependencies : gl_lib_deps)
512     glconf.set('GST_GL_HAVE_GLSYNC', 1)
513   endif
514   if cc.has_type('GLuint64', prefix : gl_include_block, dependencies : gl_lib_deps)
515     glconf.set('GST_GL_HAVE_GLUINT64', 1)
516   endif
517   if cc.has_type('GLint64', prefix : gl_include_block, dependencies : gl_lib_deps)
518     glconf.set('GST_GL_HAVE_GLINT64', 1)
519   endif
520   if egl_dep.found() and cc.has_type('EGLAttrib', prefix : gl_include_block + egl_includes, dependencies : gl_lib_deps + [egl_dep])
521     glconf.set('GST_GL_HAVE_EGLATTRIB', 1)
522   endif
523
524   message('Building libgstgl with GL api:      ' + ' '.join(enabled_gl_apis))
525   message('Building libgstgl with GL platform: ' + ' '.join(enabled_gl_platforms))
526   message('Building libgstgl with GL winsys:   ' + ' '.join(enabled_gl_winsys))
527
528   install_headers(gl_headers, subdir : 'gstreamer-1.0/gst/gl')
529   install_headers(gl_cocoa_headers, subdir : 'gstreamer-1.0/gst/gl/cocoa')
530   install_headers(gl_egl_headers, subdir : 'gstreamer-1.0/gst/gl/egl')
531   install_headers(gl_prototype_headers, subdir : 'gstreamer-1.0/gst/gl/glprototypes')
532   install_headers(gl_x11_headers, subdir : 'gstreamer-1.0/gst/gl/x11')
533
534   configure_file(input : 'gstglconfig.h.meson',
535     output : 'gstglconfig.h',
536     install_dir : get_option('libdir') + '/gstreamer-1.0/include/gst/gl',
537     configuration : glconf)
538
539   gstgl = library('gstgl-' + api_version,
540     gl_sources,
541     c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API'],
542     include_directories : [configinc, libsinc],
543     version : libversion,
544     soversion : soversion,
545     install : true,
546     dependencies : [gstbase_dep, gstvideo_dep, gmodule_dep,
547                     gl_lib_deps, gl_platform_deps, gl_winsys_deps, gl_misc_deps],
548     # FIXME: This symbol list is generated on Linux, so this is wrong for Windows
549     vs_module_defs: vs_module_defs_dir + 'libgstgl.def',
550   )
551   # TODO: generate gir
552
553   gstgl_dep = declare_dependency(link_with : gstgl,
554     include_directories : [libsinc],
555     dependencies : [gstbase_dep, gstvideo_dep])
556 endif