17ec681f3Smrg# Copyright © 2017-2019 Intel Corporation
201e04c3fSmrg
301e04c3fSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy
401e04c3fSmrg# of this software and associated documentation files (the "Software"), to deal
501e04c3fSmrg# in the Software without restriction, including without limitation the rights
601e04c3fSmrg# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
701e04c3fSmrg# copies of the Software, and to permit persons to whom the Software is
801e04c3fSmrg# furnished to do so, subject to the following conditions:
901e04c3fSmrg
1001e04c3fSmrg# The above copyright notice and this permission notice shall be included in
1101e04c3fSmrg# all copies or substantial portions of the Software.
1201e04c3fSmrg
1301e04c3fSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1401e04c3fSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1501e04c3fSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1601e04c3fSmrg# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1701e04c3fSmrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1801e04c3fSmrg# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1901e04c3fSmrg# SOFTWARE.
2001e04c3fSmrg
2101e04c3fSmrginc_egl = include_directories('.', 'main')
2201e04c3fSmrginc_egl_dri2 = include_directories('drivers/dri2')
2301e04c3fSmrg
247ec681f3Smrgc_args_for_egl = [asan_c_args]
257ec681f3Smrgcpp_args_for_egl = []
2601e04c3fSmrglink_for_egl = []
2701e04c3fSmrgdeps_for_egl = []
287e102996Smayaincs_for_egl = [inc_include, inc_src, inc_egl]
2901e04c3fSmrg
3001e04c3fSmrgfiles_egl = files(
3101e04c3fSmrg  'main/eglapi.c',
3201e04c3fSmrg  'main/eglarray.c',
3301e04c3fSmrg  'main/eglarray.h',
3401e04c3fSmrg  'main/eglconfig.c',
3501e04c3fSmrg  'main/eglconfig.h',
3601e04c3fSmrg  'main/eglcontext.c',
3701e04c3fSmrg  'main/eglcontext.h',
3801e04c3fSmrg  'main/eglcurrent.c',
3901e04c3fSmrg  'main/eglcurrent.h',
4001e04c3fSmrg  'main/egldefines.h',
4101e04c3fSmrg  'main/egldevice.c',
4201e04c3fSmrg  'main/egldevice.h',
4301e04c3fSmrg  'main/egldisplay.c',
4401e04c3fSmrg  'main/egldisplay.h',
4501e04c3fSmrg  'main/egldriver.h',
4601e04c3fSmrg  'main/eglglobals.c',
4701e04c3fSmrg  'main/eglglobals.h',
4801e04c3fSmrg  'main/eglimage.c',
4901e04c3fSmrg  'main/eglimage.h',
5001e04c3fSmrg  'main/egllog.c',
5101e04c3fSmrg  'main/egllog.h',
5201e04c3fSmrg  'main/eglsurface.c',
5301e04c3fSmrg  'main/eglsurface.h',
5401e04c3fSmrg  'main/eglsync.c',
5501e04c3fSmrg  'main/eglsync.h',
5601e04c3fSmrg  'main/eglentrypoint.h',
5701e04c3fSmrg  'main/egltypedefs.h',
5801e04c3fSmrg)
5901e04c3fSmrg
6001e04c3fSmrgg_egldispatchstubs_c = custom_target(
6101e04c3fSmrg  'g_egldispatchstubs.c',
6201e04c3fSmrg  input : [
637e102996Smaya    'generate/gen_egl_dispatch.py',
6401e04c3fSmrg    'generate/egl.xml', 'generate/egl_other.xml'
6501e04c3fSmrg  ],
6601e04c3fSmrg  output : 'g_egldispatchstubs.c',
6701e04c3fSmrg  command : [
687e102996Smaya    prog_python, '@INPUT0@', 'source', '@INPUT1@', '@INPUT2@',
6901e04c3fSmrg  ],
707e102996Smaya  depend_files : [ files('generate/eglFunctionList.py'), genCommon_py, ],
7101e04c3fSmrg  capture : true,
7201e04c3fSmrg)
7301e04c3fSmrg
7401e04c3fSmrgg_egldispatchstubs_h = custom_target(
7501e04c3fSmrg  'g_egldispatchstubs.h',
7601e04c3fSmrg  input : [
777e102996Smaya    'generate/gen_egl_dispatch.py',
7801e04c3fSmrg    'generate/egl.xml', 'generate/egl_other.xml'
7901e04c3fSmrg  ],
8001e04c3fSmrg  output : 'g_egldispatchstubs.h',
8101e04c3fSmrg  command : [
827e102996Smaya    prog_python, '@INPUT0@', 'header', '@INPUT1@', '@INPUT2@',
8301e04c3fSmrg  ],
847e102996Smaya  depend_files : [ files('generate/eglFunctionList.py'), genCommon_py, ],
8501e04c3fSmrg  capture : true,
8601e04c3fSmrg)
8701e04c3fSmrg
8801e04c3fSmrgif with_dri2
8901e04c3fSmrg  files_egl += files(
9001e04c3fSmrg    'drivers/dri2/egl_dri2.c',
9101e04c3fSmrg    'drivers/dri2/egl_dri2.h',
9201e04c3fSmrg  )
937ec681f3Smrg  deps_for_egl += idep_xmlconfig
947ec681f3Smrg  link_for_egl += libloader
95993e1d59Smrg  incs_for_egl += inc_loader
9601e04c3fSmrg
977ec681f3Smrg  files_egl += files(
987ec681f3Smrg    'drivers/dri2/platform_device.c',
997ec681f3Smrg    'drivers/dri2/platform_surfaceless.c',
1007ec681f3Smrg  )
10101e04c3fSmrg  if with_platform_x11
10201e04c3fSmrg    files_egl += files('drivers/dri2/platform_x11.c')
10301e04c3fSmrg    if with_dri3
10401e04c3fSmrg      files_egl += files('drivers/dri2/platform_x11_dri3.c')
10501e04c3fSmrg      link_for_egl += libloader_dri3_helper
10601e04c3fSmrg    endif
10701e04c3fSmrg    deps_for_egl += [dep_x11_xcb, dep_xcb_dri2, dep_xcb_xfixes]
10801e04c3fSmrg  endif
1097ec681f3Smrg  if with_gbm and not with_platform_android
11001e04c3fSmrg    files_egl += files('drivers/dri2/platform_drm.c')
111993e1d59Smrg    link_for_egl += libgbm
112993e1d59Smrg    incs_for_egl += [inc_gbm, include_directories('../gbm/main')]
11301e04c3fSmrg    deps_for_egl += dep_libdrm
11401e04c3fSmrg  endif
11501e04c3fSmrg  if with_platform_wayland
11601e04c3fSmrg    deps_for_egl += [dep_wayland_client, dep_wayland_server, dep_wayland_egl_headers]
11701e04c3fSmrg    link_for_egl += libwayland_drm
11801e04c3fSmrg    files_egl += files('drivers/dri2/platform_wayland.c')
11901e04c3fSmrg    files_egl += [
12001e04c3fSmrg      linux_dmabuf_unstable_v1_protocol_c,
12101e04c3fSmrg      linux_dmabuf_unstable_v1_client_protocol_h,
12201e04c3fSmrg      wayland_drm_client_protocol_h,
12301e04c3fSmrg    ]
12401e04c3fSmrg    incs_for_egl += include_directories('wayland/wayland-drm')
12501e04c3fSmrg  endif
12601e04c3fSmrg  if with_platform_android
12701e04c3fSmrg    deps_for_egl += dep_android
12801e04c3fSmrg    files_egl += files('drivers/dri2/platform_android.c')
1297ec681f3Smrg    if dep_android_mapper4.found()
1307ec681f3Smrg      files_egl += files('drivers/dri2/platform_android_mapper.cpp')
1317ec681f3Smrg      c_args_for_egl += '-DUSE_IMAPPER4_METADATA_API'
1327ec681f3Smrg      cpp_args_for_egl += ['-std=c++17', '-DUSE_IMAPPER4_METADATA_API']
1337ec681f3Smrg    endif
13401e04c3fSmrg  endif
13501e04c3fSmrgelif with_platform_haiku
13601e04c3fSmrg  incs_for_egl += inc_haikugl
13701e04c3fSmrg  c_args_for_egl += [
13801e04c3fSmrg    '-D_EGL_BUILT_IN_DRIVER_HAIKU',
13901e04c3fSmrg  ]
14001e04c3fSmrg  files_egl += files('drivers/haiku/egl_haiku.cpp')
14101e04c3fSmrg  link_for_egl += libgl
14201e04c3fSmrg  deps_for_egl += cpp.find_library('be')
1437ec681f3Smrgelif with_platform_windows
1447ec681f3Smrg  c_args_for_egl += [
1457ec681f3Smrg    '-DEGLAPI=', '-DPUBLIC='
1467ec681f3Smrg  ]
1477ec681f3Smrg  files_egl += files('drivers/wgl/egl_wgl.c')
1487ec681f3Smrg  incs_for_egl += [inc_wgl, inc_gallium, inc_gallium_aux]
1497ec681f3Smrg  link_for_egl += libgallium_wgl
15001e04c3fSmrgendif
15101e04c3fSmrg
15201e04c3fSmrgif cc.has_function('mincore')
15301e04c3fSmrg  c_args_for_egl += '-DHAVE_MINCORE'
15401e04c3fSmrgendif
15501e04c3fSmrg
15601e04c3fSmrgif not with_glvnd
1577e102996Smaya  egl_lib_name = 'EGL' + get_option('egl-lib-suffix')
15801e04c3fSmrg  egl_lib_version = '1.0.0'
1597ec681f3Smrg  egl_lib_soversion = host_machine.system() == 'windows' ? '' : '1'
16001e04c3fSmrgelse
1617ec681f3Smrg  egl_lib_name = 'EGL_@0@'.format(glvnd_vendor_name)
16201e04c3fSmrg  egl_lib_version = '0.0.0'
1637ec681f3Smrg  egl_lib_soversion = '0'
1647ec681f3Smrg  deps_for_egl += dep_glvnd
16501e04c3fSmrg  files_egl += [g_egldispatchstubs_h, g_egldispatchstubs_c]
16601e04c3fSmrg  files_egl += files('main/eglglvnd.c', 'main/egldispatchstubs.c')
1677ec681f3Smrg  glvnd_config = configuration_data()
1687ec681f3Smrg  glvnd_config.set('glvnd_vendor_name', get_option('glvnd-vendor-name'))
1697ec681f3Smrg  configure_file(
1707ec681f3Smrg    configuration: glvnd_config,
1717ec681f3Smrg    input : 'main/50_mesa.json',
1727ec681f3Smrg    output: '50_@0@.json'.format(glvnd_vendor_name),
1737ec681f3Smrg    install : true,
17401e04c3fSmrg    install_dir : join_paths(get_option('datadir'), 'glvnd', 'egl_vendor.d')
17501e04c3fSmrg  )
17601e04c3fSmrgendif
17701e04c3fSmrg
17801e04c3fSmrglibegl = shared_library(
17901e04c3fSmrg  egl_lib_name,
18001e04c3fSmrg  files_egl,
18101e04c3fSmrg  c_args : [
18201e04c3fSmrg    c_args_for_egl,
18301e04c3fSmrg    '-D_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_@0@'.format(egl_native_platform.to_upper()),
18401e04c3fSmrg  ],
1857ec681f3Smrg  cpp_args : [cpp_args_for_egl],
1867ec681f3Smrg  gnu_symbol_visibility : 'hidden',
18701e04c3fSmrg  include_directories : incs_for_egl,
1887ec681f3Smrg  link_with : [link_for_egl, libglapi],
18901e04c3fSmrg  link_args : [ld_args_bsymbolic, ld_args_gc_sections],
1907ec681f3Smrg  dependencies : [deps_for_egl, dep_dl, dep_libdrm, dep_clock, dep_thread, idep_mesautil],
19101e04c3fSmrg  install : true,
19201e04c3fSmrg  version : egl_lib_version,
1937ec681f3Smrg  soversion : egl_lib_soversion,
1947ec681f3Smrg  name_prefix : 'lib', # even on windows
1957ec681f3Smrg  vs_module_defs : 'main/egl.def'
19601e04c3fSmrg)
19701e04c3fSmrg
1987ec681f3Smrgif not with_glvnd
1997ec681f3Smrg  pkg.generate(
2007ec681f3Smrg    name : 'egl',
2017ec681f3Smrg    description : 'Mesa EGL Library',
2027ec681f3Smrg    version : meson.project_version(),
2037ec681f3Smrg    libraries : libegl,
2047ec681f3Smrg    libraries_private: gl_priv_libs,
2057ec681f3Smrg    requires_private : gl_priv_reqs,
2067ec681f3Smrg    extra_cflags : gl_pkgconfig_c_flags,
2077ec681f3Smrg  )
20801e04c3fSmrgendif
20901e04c3fSmrg
2107ec681f3Smrgif with_symbols_check
21101e04c3fSmrg  if with_glvnd
2127ec681f3Smrg    egl_symbols = files('egl-glvnd-symbols.txt')
21301e04c3fSmrg  else
2147ec681f3Smrg    egl_symbols = files('egl-symbols.txt')
21501e04c3fSmrg  endif
2167ec681f3Smrg  test('egl-symbols-check',
2177ec681f3Smrg    symbols_check,
2187ec681f3Smrg    args : [
2197ec681f3Smrg      '--lib', libegl,
2207ec681f3Smrg      '--symbols-file', egl_symbols,
2217ec681f3Smrg      symbols_check_args,
2227ec681f3Smrg    ],
2237ec681f3Smrg    suite : ['egl'],
2247ec681f3Smrg  )
22501e04c3fSmrg  test('egl-entrypoint-check',
2267ec681f3Smrg    prog_python,
2277ec681f3Smrg    args : files('egl-entrypoint-check.py', 'main/eglentrypoint.h'),
2287e102996Smaya    suite : ['egl'],
22901e04c3fSmrg  )
23001e04c3fSmrgendif
231