100a23bdaSmrg# Copyright © 2017-2018 Intel Corporation 200a23bdaSmrg 300a23bdaSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 400a23bdaSmrg# of this software and associated documentation files (the "Software"), to deal 500a23bdaSmrg# in the Software without restriction, including without limitation the rights 600a23bdaSmrg# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 700a23bdaSmrg# copies of the Software, and to permit persons to whom the Software is 800a23bdaSmrg# furnished to do so, subject to the following conditions: 900a23bdaSmrg 1000a23bdaSmrg# The above copyright notice and this permission notice shall be included in 1100a23bdaSmrg# all copies or substantial portions of the Software. 1200a23bdaSmrg 1300a23bdaSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1400a23bdaSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1500a23bdaSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1600a23bdaSmrg# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1700a23bdaSmrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1800a23bdaSmrg# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 1900a23bdaSmrg# SOFTWARE. 2000a23bdaSmrg 216acbc0e0Smrg# The versioning should always stay at 2.4.x. If bumping away from this, 226acbc0e0Smrg# you must ensure that all users of patch_ver are changed such that DSO versions 236acbc0e0Smrg# continuously increment (e.g. blindly bumping from 2.4.122 to 2.5.0 would 246acbc0e0Smrg# roll the libdrm DSO versioning from libdrm.so.2.122.0 back to libdrm.so.2.0.0 256acbc0e0Smrg# which would be bad) 2600a23bdaSmrgproject( 2700a23bdaSmrg 'libdrm', 2800a23bdaSmrg ['c'], 296acbc0e0Smrg version : '2.4.124', 3000a23bdaSmrg license : 'MIT', 31bbff01ceSmrg meson_version : '>= 0.59', 32b0ab5608Smrg default_options : ['buildtype=debugoptimized', 'c_std=c11'], 3300a23bdaSmrg) 3400a23bdaSmrg 356acbc0e0Smrgpatch_ver = meson.project_version().split('.')[2] 366acbc0e0Smrg 37b0ab5608Smrgif ['windows', 'darwin'].contains(host_machine.system()) 38b0ab5608Smrg error('unsupported OS: @0@'.format(host_machine.system())) 39b0ab5608Smrgendif 40b0ab5608Smrg 4100a23bdaSmrgpkg = import('pkgconfig') 4200a23bdaSmrg 437cdc0497Smrgconfig = configuration_data() 447cdc0497Smrg 457cdc0497Smrgconfig.set10('UDEV', get_option('udev')) 4600a23bdaSmrgwith_freedreno_kgsl = get_option('freedreno-kgsl') 4700a23bdaSmrgwith_install_tests = get_option('install-test-programs') 48b0ab5608Smrgwith_tests = get_option('tests') 4900a23bdaSmrg 5000a23bdaSmrgdep_threads = dependency('threads') 5100a23bdaSmrg 5200a23bdaSmrgcc = meson.get_compiler('c') 5300a23bdaSmrg 5449ef06a4Smrgandroid = cc.compiles('''int func() { return __ANDROID__; }''') 5549ef06a4Smrg 566acbc0e0Smrg# Solaris / Illumos 576acbc0e0Smrgif host_machine.system() == 'sunos' 586acbc0e0Smrg add_global_arguments('-D__EXTENSIONS__', language : 'c') 596acbc0e0Smrg add_global_arguments('-D_POSIX_C_SOURCE=3', language : 'c') 606acbc0e0Smrgendif 616acbc0e0Smrg 629bd392adSmrgsymbols_check = find_program('symbols-check.py') 639bd392adSmrgprog_nm = find_program('nm') 649bd392adSmrg 6500a23bdaSmrg# Check for atomics 6600a23bdaSmrgintel_atomics = false 6700a23bdaSmrglib_atomics = false 6800a23bdaSmrg 694babd585Smrgpython3 = import('python').find_installation() 700ed5401bSmrgformat_mod_static_table = custom_target( 710ed5401bSmrg 'format_mod_static_table', 720ed5401bSmrg output : 'generated_static_table_fourcc.h', 730ed5401bSmrg input : 'include/drm/drm_fourcc.h', 744babd585Smrg command : [python3, files('gen_table_fourcc.py'), '@INPUT@', '@OUTPUT@']) 754babd585Smrg 767cdc0497Smrgdep_atomic_ops = dependency('atomic_ops', required : false) 779bd392adSmrgif cc.links(''' 7800a23bdaSmrg int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); } 7900a23bdaSmrg int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); } 809bd392adSmrg int main() { } 8100a23bdaSmrg ''', 8200a23bdaSmrg name : 'Intel Atomics') 8300a23bdaSmrg intel_atomics = true 8400a23bdaSmrg with_atomics = true 857cdc0497Smrg dep_atomic_ops = [] 867cdc0497Smrgelif dep_atomic_ops.found() 8700a23bdaSmrg lib_atomics = true 8800a23bdaSmrg with_atomics = true 8900a23bdaSmrgelif cc.has_function('atomic_cas_uint') 9000a23bdaSmrg with_atomics = true 9100a23bdaSmrgelse 9200a23bdaSmrg with_atomics = false 9300a23bdaSmrgendif 9400a23bdaSmrg 9500a23bdaSmrgconfig.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics) 9600a23bdaSmrgconfig.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics) 9700a23bdaSmrg 98b0ab5608Smrgdep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : get_option('intel')) 99b0ab5608Smrg 100bbff01ceSmrgwith_intel = get_option('intel') \ 101bbff01ceSmrg .require(with_atomics, error_message : 'libdrm_intel requires atomics') \ 102bbff01ceSmrg .require(dep_pciaccess.found(), error_message : 'libdrm_intel requires libpciaccess') \ 103bbff01ceSmrg .disable_auto_if(not host_machine.cpu_family().startswith('x86')) \ 104bbff01ceSmrg .allowed() 1050ed5401bSmrgsummary('Intel', with_intel) 10600a23bdaSmrg 107bbff01ceSmrgwith_radeon = get_option('radeon') \ 108bbff01ceSmrg .require(with_atomics, error_message : 'libdrm_radeon requires atomics') \ 109bbff01ceSmrg .allowed() 1100ed5401bSmrgsummary('Radeon', with_radeon) 11100a23bdaSmrg 112bbff01ceSmrgwith_amdgpu = get_option('amdgpu') \ 113bbff01ceSmrg .require(with_atomics, error_message : 'libdrm_amdgpu requires atomics') \ 114bbff01ceSmrg .allowed() 1150ed5401bSmrgsummary('AMDGPU', with_amdgpu) 11600a23bdaSmrg 117bbff01ceSmrgwith_nouveau = get_option('nouveau') \ 118bbff01ceSmrg .require(with_atomics, error_message : 'libdrm_nouveau requires atomics') \ 119bbff01ceSmrg .allowed() 1200ed5401bSmrgsummary('Nouveau', with_nouveau) 12100a23bdaSmrg 122bbff01ceSmrgwith_vmwgfx = get_option('vmwgfx').allowed() 1230ed5401bSmrgsummary('vmwgfx', with_vmwgfx) 12400a23bdaSmrg 125bbff01ceSmrgwith_omap = get_option('omap') \ 126bbff01ceSmrg .require(with_atomics, error_message : 'libdrm_omap requires atomics') \ 127bbff01ceSmrg .enabled() 1280ed5401bSmrgsummary('OMAP', with_omap) 12900a23bdaSmrg 130bbff01ceSmrgwith_freedreno = get_option('freedreno') \ 131bbff01ceSmrg .require(with_atomics, error_message : 'libdrm_freedreno requires atomics') \ 132bbff01ceSmrg .disable_auto_if(not ['arm', 'aarch64'].contains(host_machine.cpu_family())) \ 133bbff01ceSmrg .allowed() 1340ed5401bSmrgsummary('Freedreno', with_freedreno) 1350ed5401bSmrgsummary('Freedreon-kgsl', with_freedreno_kgsl) 13600a23bdaSmrg 137bbff01ceSmrgwith_tegra = get_option('tegra') \ 138bbff01ceSmrg .require(with_atomics, error_message : 'libdrm_tegra requires atomics') \ 139bbff01ceSmrg .disable_auto_if(not ['arm', 'aarch64'].contains(host_machine.cpu_family())) \ 140bbff01ceSmrg .enabled() 1410ed5401bSmrgsummary('Tegra', with_tegra) 14200a23bdaSmrg 143bbff01ceSmrgwith_etnaviv = get_option('etnaviv') \ 144bbff01ceSmrg .require(with_atomics, error_message : 'libdrm_etnaviv requires atomics') \ 145bbff01ceSmrg .disable_auto_if(not ['arm', 'aarch64', 'arc', 'mips', 'mips64', 'loongarch64'].contains(host_machine.cpu_family())) \ 146bbff01ceSmrg .allowed() 1470ed5401bSmrgsummary('Etnaviv', with_etnaviv) 14800a23bdaSmrg 149b0ab5608Smrgwith_exynos = get_option('exynos').enabled() 1500ed5401bSmrgsummary('EXYNOS', with_exynos) 15100a23bdaSmrg 152bbff01ceSmrgwith_vc4 = get_option('vc4') \ 153bbff01ceSmrg .disable_auto_if(not ['arm', 'aarch64'].contains(host_machine.cpu_family())) \ 154bbff01ceSmrg .allowed() 1550ed5401bSmrgsummary('VC4', with_vc4) 15600a23bdaSmrg 15700a23bdaSmrg# Among others FreeBSD does not have a separate dl library. 15800a23bdaSmrgif not cc.has_function('dlsym') 15900a23bdaSmrg dep_dl = cc.find_library('dl', required : with_nouveau) 16000a23bdaSmrgelse 16100a23bdaSmrg dep_dl = [] 16200a23bdaSmrgendif 16300a23bdaSmrg# clock_gettime might require -rt, or it might not. find out 16400a23bdaSmrgif not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>') 16500a23bdaSmrg # XXX: untested 16600a23bdaSmrg dep_rt = cc.find_library('rt') 16700a23bdaSmrgelse 16800a23bdaSmrg dep_rt = [] 16900a23bdaSmrgendif 1709bd392adSmrg 1719bd392adSmrg# The header is not required on Linux, and is in fact deprecated in glibc 2.30+ 1726acbc0e0Smrgif host_machine.system() == 'linux' 1739bd392adSmrg config.set10('HAVE_SYS_SYSCTL_H', false) 1749bd392adSmrgelse 1759bd392adSmrg # From Niclas Zeising: 1769bd392adSmrg # FreeBSD requires sys/types.h for sys/sysctl.h, so add it as part of 1779bd392adSmrg # the includes when checking for headers. 1789bd392adSmrg config.set10('HAVE_SYS_SYSCTL_H', 1799bd392adSmrg cc.compiles('#include <sys/types.h>\n#include <sys/sysctl.h>', name : 'sys/sysctl.h works')) 1809bd392adSmrgendif 1819bd392adSmrg 1829bd392adSmrgforeach header : ['sys/select.h', 'alloca.h'] 1830ed5401bSmrg config.set10('HAVE_' + header.underscorify().to_upper(), cc.check_header(header)) 1847cdc0497Smrgendforeach 1859bd392adSmrg 18688f8a8d2Smrgif (cc.has_header_symbol('sys/sysmacros.h', 'major') and 18788f8a8d2Smrg cc.has_header_symbol('sys/sysmacros.h', 'minor') and 18888f8a8d2Smrg cc.has_header_symbol('sys/sysmacros.h', 'makedev')) 18900a23bdaSmrg config.set10('MAJOR_IN_SYSMACROS', true) 19088f8a8d2Smrgendif 19188f8a8d2Smrgif (cc.has_header_symbol('sys/mkdev.h', 'major') and 19288f8a8d2Smrg cc.has_header_symbol('sys/mkdev.h', 'minor') and 19388f8a8d2Smrg cc.has_header_symbol('sys/mkdev.h', 'makedev')) 19400a23bdaSmrg config.set10('MAJOR_IN_MKDEV', true) 19500a23bdaSmrgendif 1967cdc0497Smrgconfig.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream')) 19700a23bdaSmrg 1980ed5401bSmrglibdrm_c_args = cc.get_supported_arguments([ 1990ed5401bSmrg '-Wsign-compare', '-Werror=undef', '-Werror=implicit-function-declaration', 2000ed5401bSmrg '-Wpointer-arith', '-Wwrite-strings', '-Wstrict-prototypes', 2010ed5401bSmrg '-Wmissing-prototypes', '-Wmissing-declarations', '-Wnested-externs', 2020ed5401bSmrg '-Wpacked', '-Wswitch-enum', '-Wmissing-format-attribute', 2030ed5401bSmrg '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow', 2040ed5401bSmrg '-Wdeclaration-after-statement', '-Wold-style-definition', 2050ed5401bSmrg '-Wno-unused-parameter', '-Wno-attributes', '-Wno-long-long', 2060ed5401bSmrg '-Wno-missing-field-initializers']) 20700a23bdaSmrg 20800a23bdaSmrgdep_cunit = dependency('cunit', version : '>= 2.1', required : false) 209b0ab5608Smrgdep_cairo = dependency('cairo', required : get_option('cairo-tests')) 210b0ab5608Smrgwith_cairo_tests = dep_cairo.found() 211b0ab5608Smrg 212b0ab5608Smrgvalgrind_version = [] 213b0ab5608Smrgif with_freedreno 214b0ab5608Smrg valgrind_version = '>=3.10.0' 21500a23bdaSmrgendif 216b0ab5608Smrgdep_valgrind = dependency('valgrind', required : get_option('valgrind'), version : valgrind_version) 217b0ab5608Smrgwith_valgrind = dep_valgrind.found() 21800a23bdaSmrg 219b0ab5608Smrgprog_rst2man = find_program('rst2man', 'rst2man.py', required: get_option('man-pages')) 220b0ab5608Smrgwith_man_pages = prog_rst2man.found() 22100a23bdaSmrg 2220ed5401bSmrgconfig.set10('HAVE_VISIBILITY', cc.has_function_attribute('visibility:hidden')) 22300a23bdaSmrg 22400a23bdaSmrgforeach t : [ 22500a23bdaSmrg [with_exynos, 'EXYNOS'], 22600a23bdaSmrg [with_freedreno_kgsl, 'FREEDRENO_KGSL'], 22700a23bdaSmrg [with_intel, 'INTEL'], 22800a23bdaSmrg [with_nouveau, 'NOUVEAU'], 22900a23bdaSmrg [with_radeon, 'RADEON'], 23000a23bdaSmrg [with_vc4, 'VC4'], 23100a23bdaSmrg [with_vmwgfx, 'VMWGFX'], 23200a23bdaSmrg [with_cairo_tests, 'CAIRO'], 23300a23bdaSmrg [with_valgrind, 'VALGRIND'], 23400a23bdaSmrg ] 23500a23bdaSmrg config.set10('HAVE_@0@'.format(t[1]), t[0]) 23600a23bdaSmrgendforeach 23700a23bdaSmrgif with_freedreno_kgsl and not with_freedreno 23800a23bdaSmrg error('cannot enable freedreno-kgsl without freedreno support') 23900a23bdaSmrgendif 24000a23bdaSmrgconfig.set10('_GNU_SOURCE', true) 241bbff01ceSmrg 242bbff01ceSmrgif target_machine.endian() == 'big' 243bbff01ceSmrg config.set('HAVE_BIG_ENDIAN', 1) 244bbff01ceSmrgendif 245bbff01ceSmrg 2466acbc0e0Smrgif android 2476acbc0e0Smrg config.set('BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD', 1) 2486acbc0e0Smrgendif 2496acbc0e0Smrg 25000a23bdaSmrgconfig_file = configure_file( 25100a23bdaSmrg configuration : config, 25200a23bdaSmrg output : 'config.h', 25300a23bdaSmrg) 254bbff01ceSmrgadd_project_arguments('-include', meson.current_build_dir() / 'config.h', language : 'c') 25500a23bdaSmrg 25600a23bdaSmrginc_root = include_directories('.') 25700a23bdaSmrginc_drm = include_directories('include/drm') 25800a23bdaSmrg 25949ef06a4Smrglibdrm_files = [files( 26049ef06a4Smrg 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c', 26149ef06a4Smrg 'xf86drmMode.c' 26249ef06a4Smrg ), 26349ef06a4Smrg config_file, format_mod_static_table 26449ef06a4Smrg] 26549ef06a4Smrg 2660ed5401bSmrg# Build an unversioned so on android 26749ef06a4Smrgif android 2680ed5401bSmrg libdrm_kw = {} 26949ef06a4Smrgelse 2706acbc0e0Smrg libdrm_kw = { 'version' : '2.@0@.0'.format(patch_ver) } 2710ed5401bSmrgendif 2720ed5401bSmrg 2730ed5401bSmrglibdrm = library( 2740ed5401bSmrg 'drm', 2750ed5401bSmrg libdrm_files, 2760ed5401bSmrg c_args : libdrm_c_args, 277bbff01ceSmrg dependencies : [dep_valgrind, dep_rt], 2780ed5401bSmrg include_directories : inc_drm, 2790ed5401bSmrg install : true, 2800ed5401bSmrg kwargs : libdrm_kw, 2810ed5401bSmrg gnu_symbol_visibility : 'hidden', 2820ed5401bSmrg) 28300a23bdaSmrg 2849bd392adSmrgtest( 2859bd392adSmrg 'core-symbols-check', 2869bd392adSmrg symbols_check, 2879bd392adSmrg args : [ 2889bd392adSmrg '--lib', libdrm, 2899bd392adSmrg '--symbols-file', files('core-symbols.txt'), 290bbff01ceSmrg '--nm', prog_nm.full_path(), 2919bd392adSmrg ], 2929bd392adSmrg) 2939bd392adSmrg 29400a23bdaSmrgext_libdrm = declare_dependency( 29500a23bdaSmrg link_with : libdrm, 29600a23bdaSmrg include_directories : [inc_root, inc_drm], 29700a23bdaSmrg) 29800a23bdaSmrg 2990ed5401bSmrgif meson.version().version_compare('>= 0.54.0') 3000ed5401bSmrg meson.override_dependency('libdrm', ext_libdrm) 3010ed5401bSmrgendif 3020ed5401bSmrg 30300a23bdaSmrginstall_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h') 30400a23bdaSmrginstall_headers( 30500a23bdaSmrg 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h', 30600a23bdaSmrg 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h', 30700a23bdaSmrg 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h', 3087cdc0497Smrg 'include/drm/msm_drm.h', 'include/drm/nouveau_drm.h', 3097cdc0497Smrg 'include/drm/qxl_drm.h', 'include/drm/r128_drm.h', 3107cdc0497Smrg 'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h', 3117cdc0497Smrg 'include/drm/savage_drm.h', 'include/drm/sis_drm.h', 3127cdc0497Smrg 'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h', 31300a23bdaSmrg 'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h', 31400a23bdaSmrg subdir : 'libdrm', 31500a23bdaSmrg) 31600a23bdaSmrgif with_vmwgfx 31700a23bdaSmrg install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm') 31800a23bdaSmrgendif 31900a23bdaSmrg 32000a23bdaSmrgpkg.generate( 3210ed5401bSmrg libdrm, 32200a23bdaSmrg name : 'libdrm', 32300a23bdaSmrg subdirs : ['.', 'libdrm'], 32400a23bdaSmrg description : 'Userspace interface to kernel DRM services', 32500a23bdaSmrg) 32600a23bdaSmrg 32700a23bdaSmrgif with_intel 32800a23bdaSmrg subdir('intel') 32900a23bdaSmrgendif 33000a23bdaSmrgif with_nouveau 33100a23bdaSmrg subdir('nouveau') 33200a23bdaSmrgendif 33300a23bdaSmrgif with_radeon 33400a23bdaSmrg subdir('radeon') 33500a23bdaSmrgendif 33600a23bdaSmrgif with_amdgpu 33700a23bdaSmrg subdir('amdgpu') 33800a23bdaSmrgendif 33900a23bdaSmrgif with_omap 34000a23bdaSmrg subdir('omap') 34100a23bdaSmrgendif 34200a23bdaSmrgif with_exynos 34300a23bdaSmrg subdir('exynos') 34400a23bdaSmrgendif 34500a23bdaSmrgif with_freedreno 34600a23bdaSmrg subdir('freedreno') 34700a23bdaSmrgendif 34800a23bdaSmrgif with_tegra 34900a23bdaSmrg subdir('tegra') 35000a23bdaSmrgendif 35100a23bdaSmrgif with_vc4 35200a23bdaSmrg subdir('vc4') 35300a23bdaSmrgendif 35400a23bdaSmrgif with_etnaviv 35500a23bdaSmrg subdir('etnaviv') 35600a23bdaSmrgendif 35700a23bdaSmrgif with_man_pages 35800a23bdaSmrg subdir('man') 35900a23bdaSmrgendif 36000a23bdaSmrgsubdir('data') 361b0ab5608Smrgif with_tests 362b0ab5608Smrg subdir('tests') 363b0ab5608Smrgendif 364