1b8e80941Smrg# Copyright © 2017 Intel Corporation
2b8e80941Smrg
3b8e80941Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy
4b8e80941Smrg# of this software and associated documentation files (the "Software"), to deal
5b8e80941Smrg# in the Software without restriction, including without limitation the rights
6b8e80941Smrg# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7b8e80941Smrg# copies of the Software, and to permit persons to whom the Software is
8b8e80941Smrg# furnished to do so, subject to the following conditions:
9b8e80941Smrg
10b8e80941Smrg# The above copyright notice and this permission notice shall be included in
11b8e80941Smrg# all copies or substantial portions of the Software.
12b8e80941Smrg
13b8e80941Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14b8e80941Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15b8e80941Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16b8e80941Smrg# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17b8e80941Smrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18b8e80941Smrg# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19b8e80941Smrg# SOFTWARE.
20b8e80941Smrg
21b8e80941Smrginc_egl = include_directories('.', 'main')
22b8e80941Smrginc_egl_dri2 = include_directories('drivers/dri2')
23b8e80941Smrg
24b8e80941Smrgc_args_for_egl = []
25b8e80941Smrglink_for_egl = []
26b8e80941Smrgdeps_for_egl = []
27b8e80941Smrgincs_for_egl = [inc_include, inc_src, inc_egl]
28b8e80941Smrg
29b8e80941Smrgfiles_egl = files(
30b8e80941Smrg  'main/eglapi.c',
31b8e80941Smrg  'main/eglapi.h',
32b8e80941Smrg  'main/eglarray.c',
33b8e80941Smrg  'main/eglarray.h',
34b8e80941Smrg  'main/eglconfig.c',
35b8e80941Smrg  'main/eglconfig.h',
36b8e80941Smrg  'main/eglcontext.c',
37b8e80941Smrg  'main/eglcontext.h',
38b8e80941Smrg  'main/eglcurrent.c',
39b8e80941Smrg  'main/eglcurrent.h',
40b8e80941Smrg  'main/egldefines.h',
41b8e80941Smrg  'main/egldevice.c',
42b8e80941Smrg  'main/egldevice.h',
43b8e80941Smrg  'main/egldisplay.c',
44b8e80941Smrg  'main/egldisplay.h',
45b8e80941Smrg  'main/egldriver.c',
46b8e80941Smrg  'main/egldriver.h',
47b8e80941Smrg  'main/eglfallbacks.c',
48b8e80941Smrg  'main/eglglobals.c',
49b8e80941Smrg  'main/eglglobals.h',
50b8e80941Smrg  'main/eglimage.c',
51b8e80941Smrg  'main/eglimage.h',
52b8e80941Smrg  'main/egllog.c',
53b8e80941Smrg  'main/egllog.h',
54b8e80941Smrg  'main/eglsurface.c',
55b8e80941Smrg  'main/eglsurface.h',
56b8e80941Smrg  'main/eglsync.c',
57b8e80941Smrg  'main/eglsync.h',
58b8e80941Smrg  'main/eglentrypoint.h',
59b8e80941Smrg  'main/egltypedefs.h',
60b8e80941Smrg)
61b8e80941Smrg
62b8e80941Smrgg_egldispatchstubs_c = custom_target(
63b8e80941Smrg  'g_egldispatchstubs.c',
64b8e80941Smrg  input : [
65b8e80941Smrg    'generate/gen_egl_dispatch.py',
66b8e80941Smrg    'generate/egl.xml', 'generate/egl_other.xml'
67b8e80941Smrg  ],
68b8e80941Smrg  output : 'g_egldispatchstubs.c',
69b8e80941Smrg  command : [
70b8e80941Smrg    prog_python, '@INPUT0@', 'source', '@INPUT1@', '@INPUT2@',
71b8e80941Smrg  ],
72b8e80941Smrg  depend_files : [ files('generate/eglFunctionList.py'), genCommon_py, ],
73b8e80941Smrg  capture : true,
74b8e80941Smrg)
75b8e80941Smrg
76b8e80941Smrgg_egldispatchstubs_h = custom_target(
77b8e80941Smrg  'g_egldispatchstubs.h',
78b8e80941Smrg  input : [
79b8e80941Smrg    'generate/gen_egl_dispatch.py',
80b8e80941Smrg    'generate/egl.xml', 'generate/egl_other.xml'
81b8e80941Smrg  ],
82b8e80941Smrg  output : 'g_egldispatchstubs.h',
83b8e80941Smrg  command : [
84b8e80941Smrg    prog_python, '@INPUT0@', 'header', '@INPUT1@', '@INPUT2@',
85b8e80941Smrg  ],
86b8e80941Smrg  depend_files : [ files('generate/eglFunctionList.py'), genCommon_py, ],
87b8e80941Smrg  capture : true,
88b8e80941Smrg)
89b8e80941Smrg
90b8e80941Smrgif with_dri2
91b8e80941Smrg  files_egl += files(
92b8e80941Smrg    'drivers/dri2/egl_dri2.c',
93b8e80941Smrg    'drivers/dri2/egl_dri2.h',
94b8e80941Smrg    'drivers/dri2/egl_dri2_fallbacks.h',
95b8e80941Smrg  )
96b8e80941Smrg  link_for_egl += [libloader, libxmlconfig]
97b8e80941Smrg  incs_for_egl += inc_loader
98b8e80941Smrg
99b8e80941Smrg  if with_platform_x11
100b8e80941Smrg    files_egl += files('drivers/dri2/platform_x11.c')
101b8e80941Smrg    if with_dri3
102b8e80941Smrg      files_egl += files('drivers/dri2/platform_x11_dri3.c')
103b8e80941Smrg      link_for_egl += libloader_dri3_helper
104b8e80941Smrg    endif
105b8e80941Smrg    deps_for_egl += [dep_x11_xcb, dep_xcb_dri2, dep_xcb_xfixes]
106b8e80941Smrg  endif
107b8e80941Smrg  if with_platform_drm
108b8e80941Smrg    files_egl += files('drivers/dri2/platform_drm.c')
109b8e80941Smrg    link_for_egl += libgbm
110b8e80941Smrg    incs_for_egl += [inc_gbm, include_directories('../gbm/main')]
111b8e80941Smrg    deps_for_egl += dep_libdrm
112b8e80941Smrg  endif
113b8e80941Smrg  if with_platform_surfaceless
114b8e80941Smrg    files_egl += files('drivers/dri2/platform_surfaceless.c')
115b8e80941Smrg  endif
116b8e80941Smrg  if with_platform_wayland
117b8e80941Smrg    deps_for_egl += [dep_wayland_client, dep_wayland_server, dep_wayland_egl_headers]
118b8e80941Smrg    link_for_egl += libwayland_drm
119b8e80941Smrg    files_egl += files('drivers/dri2/platform_wayland.c')
120b8e80941Smrg    files_egl += [
121b8e80941Smrg      linux_dmabuf_unstable_v1_protocol_c,
122b8e80941Smrg      linux_dmabuf_unstable_v1_client_protocol_h,
123b8e80941Smrg      wayland_drm_client_protocol_h,
124b8e80941Smrg    ]
125b8e80941Smrg    incs_for_egl += include_directories('wayland/wayland-drm')
126b8e80941Smrg  endif
127b8e80941Smrg  if with_platform_android
128b8e80941Smrg    deps_for_egl += dep_android
129b8e80941Smrg    files_egl += files('drivers/dri2/platform_android.c')
130b8e80941Smrg  endif
131b8e80941Smrgelif with_platform_haiku
132b8e80941Smrg  incs_for_egl += inc_haikugl
133b8e80941Smrg  c_args_for_egl += [
134b8e80941Smrg    '-D_EGL_BUILT_IN_DRIVER_HAIKU',
135b8e80941Smrg  ]
136b8e80941Smrg  files_egl += files('drivers/haiku/egl_haiku.cpp')
137b8e80941Smrg  link_for_egl += libgl
138b8e80941Smrg  deps_for_egl += cpp.find_library('be')
139b8e80941Smrgendif
140b8e80941Smrg
141b8e80941Smrgif cc.has_function('mincore')
142b8e80941Smrg  c_args_for_egl += '-DHAVE_MINCORE'
143b8e80941Smrgendif
144b8e80941Smrg
145b8e80941Smrgif not with_glvnd
146b8e80941Smrg  egl_lib_name = 'EGL' + get_option('egl-lib-suffix')
147b8e80941Smrg  egl_lib_version = '1.0.0'
148b8e80941Smrgelse
149b8e80941Smrg  egl_lib_name = 'EGL_mesa'
150b8e80941Smrg  egl_lib_version = '0.0.0'
151b8e80941Smrg  files_egl += [g_egldispatchstubs_h, g_egldispatchstubs_c]
152b8e80941Smrg  files_egl += files('main/eglglvnd.c', 'main/egldispatchstubs.c')
153b8e80941Smrg  install_data(
154b8e80941Smrg    'main/50_mesa.json',
155b8e80941Smrg    install_dir : join_paths(get_option('datadir'), 'glvnd', 'egl_vendor.d')
156b8e80941Smrg  )
157b8e80941Smrgendif
158b8e80941Smrg
159b8e80941Smrglibegl = shared_library(
160b8e80941Smrg  egl_lib_name,
161b8e80941Smrg  files_egl,
162b8e80941Smrg  c_args : [
163b8e80941Smrg    c_vis_args,
164b8e80941Smrg    c_args_for_egl,
165b8e80941Smrg    '-D_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_@0@'.format(egl_native_platform.to_upper()),
166b8e80941Smrg  ],
167b8e80941Smrg  include_directories : incs_for_egl,
168b8e80941Smrg  link_with : [link_for_egl, libglapi, libmesa_util],
169b8e80941Smrg  link_args : [ld_args_bsymbolic, ld_args_gc_sections],
170b8e80941Smrg  dependencies : [deps_for_egl, dep_dl, dep_libdrm, dep_clock, dep_thread],
171b8e80941Smrg  install : true,
172b8e80941Smrg  version : egl_lib_version,
173b8e80941Smrg)
174b8e80941Smrg
175b8e80941Smrg# If using glvnd the pkg-config header should not point to EGL_mesa, it should
176b8e80941Smrg# point to EGL. glvnd is only available on unix like platforms so adding -l
177b8e80941Smrg# should be safe here
178b8e80941Smrg# TODO: in the glvnd case glvnd itself should really be providing this.
179b8e80941Smrgif with_glvnd
180b8e80941Smrg  _egl = '-L${libdir} -lEGL'
181b8e80941Smrgelse
182b8e80941Smrg  _egl = libegl
183b8e80941Smrgendif
184b8e80941Smrg
185b8e80941Smrgpkg.generate(
186b8e80941Smrg  name : 'egl',
187b8e80941Smrg  description : 'Mesa EGL Library',
188b8e80941Smrg  version : meson.project_version(),
189b8e80941Smrg  libraries : _egl,
190b8e80941Smrg  libraries_private: gl_priv_libs,
191b8e80941Smrg  requires_private : gl_priv_reqs,
192b8e80941Smrg  extra_cflags : gl_pkgconfig_c_flags,
193b8e80941Smrg)
194b8e80941Smrg
195b8e80941Smrgif with_tests and prog_nm.found()
196b8e80941Smrg  if with_glvnd
197b8e80941Smrg    # TODO: add glvnd symbol check
198b8e80941Smrg  else
199b8e80941Smrg    test('egl-symbols-check',
200b8e80941Smrg      find_program('egl-symbols-check'),
201b8e80941Smrg      env : env_test,
202b8e80941Smrg      args : libegl,
203b8e80941Smrg      suite : ['egl'],
204b8e80941Smrg    )
205b8e80941Smrg  endif
206b8e80941Smrg  test('egl-entrypoint-check',
207b8e80941Smrg    find_program('egl-entrypoint-check'),
208b8e80941Smrg    env : ['srcdir=' + meson.current_source_dir()],
209b8e80941Smrg    suite : ['egl'],
210b8e80941Smrg  )
211b8e80941Smrgendif
212