meson.build revision 0ed5401b
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 2100a23bdaSmrgproject( 2200a23bdaSmrg 'libdrm', 2300a23bdaSmrg ['c'], 240ed5401bSmrg version : '2.4.112', 2500a23bdaSmrg license : 'MIT', 260ed5401bSmrg meson_version : '>= 0.53', 270ed5401bSmrg default_options : ['buildtype=debugoptimized', 'c_std=c99'], 2800a23bdaSmrg) 2900a23bdaSmrg 3000a23bdaSmrgpkg = import('pkgconfig') 3100a23bdaSmrg 327cdc0497Smrgconfig = configuration_data() 337cdc0497Smrg 347cdc0497Smrgconfig.set10('UDEV', get_option('udev')) 3500a23bdaSmrgwith_freedreno_kgsl = get_option('freedreno-kgsl') 3600a23bdaSmrgwith_install_tests = get_option('install-test-programs') 3700a23bdaSmrg 3800a23bdaSmrgif ['freebsd', 'dragonfly', 'netbsd'].contains(host_machine.system()) 3900a23bdaSmrg dep_pthread_stubs = dependency('pthread-stubs', version : '>= 0.4') 4000a23bdaSmrgelse 4100a23bdaSmrg dep_pthread_stubs = [] 4200a23bdaSmrgendif 4300a23bdaSmrgdep_threads = dependency('threads') 4400a23bdaSmrg 4500a23bdaSmrgcc = meson.get_compiler('c') 4600a23bdaSmrg 4749ef06a4Smrgandroid = cc.compiles('''int func() { return __ANDROID__; }''') 4849ef06a4Smrg 499bd392adSmrgsymbols_check = find_program('symbols-check.py') 509bd392adSmrgprog_nm = find_program('nm') 519bd392adSmrg 5200a23bdaSmrg# Check for atomics 5300a23bdaSmrgintel_atomics = false 5400a23bdaSmrglib_atomics = false 5500a23bdaSmrg 564babd585Smrgpython3 = import('python').find_installation() 570ed5401bSmrgformat_mod_static_table = custom_target( 580ed5401bSmrg 'format_mod_static_table', 590ed5401bSmrg output : 'generated_static_table_fourcc.h', 600ed5401bSmrg input : 'include/drm/drm_fourcc.h', 614babd585Smrg command : [python3, files('gen_table_fourcc.py'), '@INPUT@', '@OUTPUT@']) 624babd585Smrg 637cdc0497Smrgdep_atomic_ops = dependency('atomic_ops', required : false) 649bd392adSmrgif cc.links(''' 6500a23bdaSmrg int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); } 6600a23bdaSmrg int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); } 679bd392adSmrg int main() { } 6800a23bdaSmrg ''', 6900a23bdaSmrg name : 'Intel Atomics') 7000a23bdaSmrg intel_atomics = true 7100a23bdaSmrg with_atomics = true 727cdc0497Smrg dep_atomic_ops = [] 737cdc0497Smrgelif dep_atomic_ops.found() 7400a23bdaSmrg lib_atomics = true 7500a23bdaSmrg with_atomics = true 7600a23bdaSmrgelif cc.has_function('atomic_cas_uint') 7700a23bdaSmrg with_atomics = true 7800a23bdaSmrgelse 7900a23bdaSmrg with_atomics = false 8000a23bdaSmrgendif 8100a23bdaSmrg 8200a23bdaSmrgconfig.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics) 8300a23bdaSmrgconfig.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics) 8400a23bdaSmrg 8500a23bdaSmrgwith_intel = false 8600a23bdaSmrg_intel = get_option('intel') 8700a23bdaSmrgif _intel != 'false' 8800a23bdaSmrg if _intel == 'true' and not with_atomics 8900a23bdaSmrg error('libdrm_intel requires atomics.') 9000a23bdaSmrg else 9100a23bdaSmrg with_intel = _intel == 'true' or host_machine.cpu_family().startswith('x86') 9200a23bdaSmrg endif 9300a23bdaSmrgendif 940ed5401bSmrgsummary('Intel', with_intel) 9500a23bdaSmrg 9600a23bdaSmrgwith_radeon = false 9700a23bdaSmrg_radeon = get_option('radeon') 9800a23bdaSmrgif _radeon != 'false' 9900a23bdaSmrg if _radeon == 'true' and not with_atomics 10000a23bdaSmrg error('libdrm_radeon requires atomics.') 10100a23bdaSmrg endif 10200a23bdaSmrg with_radeon = true 10300a23bdaSmrgendif 1040ed5401bSmrgsummary('Radeon', with_radeon) 10500a23bdaSmrg 10600a23bdaSmrgwith_amdgpu = false 10700a23bdaSmrg_amdgpu = get_option('amdgpu') 10800a23bdaSmrgif _amdgpu != 'false' 10900a23bdaSmrg if _amdgpu == 'true' and not with_atomics 11000a23bdaSmrg error('libdrm_amdgpu requires atomics.') 11100a23bdaSmrg endif 11200a23bdaSmrg with_amdgpu = true 11300a23bdaSmrgendif 1140ed5401bSmrgsummary('AMDGPU', with_amdgpu) 11500a23bdaSmrg 11600a23bdaSmrgwith_nouveau = false 11700a23bdaSmrg_nouveau = get_option('nouveau') 11800a23bdaSmrgif _nouveau != 'false' 11900a23bdaSmrg if _nouveau == 'true' and not with_atomics 12000a23bdaSmrg error('libdrm_nouveau requires atomics.') 12100a23bdaSmrg endif 12200a23bdaSmrg with_nouveau = true 12300a23bdaSmrgendif 1240ed5401bSmrgsummary('Nouveau', with_nouveau) 12500a23bdaSmrg 12600a23bdaSmrgwith_vmwgfx = false 12700a23bdaSmrg_vmwgfx = get_option('vmwgfx') 12800a23bdaSmrgif _vmwgfx != 'false' 12900a23bdaSmrg with_vmwgfx = true 13000a23bdaSmrgendif 1310ed5401bSmrgsummary('vmwgfx', with_vmwgfx) 13200a23bdaSmrg 13300a23bdaSmrgwith_omap = false 13400a23bdaSmrg_omap = get_option('omap') 13500a23bdaSmrgif _omap == 'true' 13600a23bdaSmrg if not with_atomics 13700a23bdaSmrg error('libdrm_omap requires atomics.') 13800a23bdaSmrg endif 13900a23bdaSmrg with_omap = true 14000a23bdaSmrgendif 1410ed5401bSmrgsummary('OMAP', with_omap) 14200a23bdaSmrg 14300a23bdaSmrgwith_freedreno = false 14400a23bdaSmrg_freedreno = get_option('freedreno') 14500a23bdaSmrgif _freedreno != 'false' 14600a23bdaSmrg if _freedreno == 'true' and not with_atomics 14700a23bdaSmrg error('libdrm_freedreno requires atomics.') 14800a23bdaSmrg else 14900a23bdaSmrg with_freedreno = _freedreno == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family()) 15000a23bdaSmrg endif 15100a23bdaSmrgendif 1520ed5401bSmrgsummary('Freedreno', with_freedreno) 1530ed5401bSmrgsummary('Freedreon-kgsl', with_freedreno_kgsl) 15400a23bdaSmrg 15500a23bdaSmrgwith_tegra = false 15600a23bdaSmrg_tegra = get_option('tegra') 15700a23bdaSmrgif _tegra == 'true' 15800a23bdaSmrg if not with_atomics 15900a23bdaSmrg error('libdrm_tegra requires atomics.') 16000a23bdaSmrg endif 16100a23bdaSmrg with_tegra = true 16200a23bdaSmrgendif 1630ed5401bSmrgsummary('Tegra', with_tegra) 16400a23bdaSmrg 16500a23bdaSmrgwith_etnaviv = false 16600a23bdaSmrg_etnaviv = get_option('etnaviv') 16700a23bdaSmrgif _etnaviv == 'true' 16800a23bdaSmrg if not with_atomics 16900a23bdaSmrg error('libdrm_etnaviv requires atomics.') 17000a23bdaSmrg endif 17100a23bdaSmrg with_etnaviv = true 17200a23bdaSmrgendif 1730ed5401bSmrgsummary('Etnaviv', with_etnaviv) 17400a23bdaSmrg 17500a23bdaSmrgwith_exynos = get_option('exynos') == 'true' 1760ed5401bSmrgsummary('EXYNOS', with_exynos) 17700a23bdaSmrg 17800a23bdaSmrgwith_vc4 = false 17900a23bdaSmrg_vc4 = get_option('vc4') 18000a23bdaSmrgif _vc4 != 'false' 18100a23bdaSmrg with_vc4 = _vc4 == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family()) 18200a23bdaSmrgendif 1830ed5401bSmrgsummary('VC4', with_vc4) 18400a23bdaSmrg 18500a23bdaSmrg# Among others FreeBSD does not have a separate dl library. 18600a23bdaSmrgif not cc.has_function('dlsym') 18700a23bdaSmrg dep_dl = cc.find_library('dl', required : with_nouveau) 18800a23bdaSmrgelse 18900a23bdaSmrg dep_dl = [] 19000a23bdaSmrgendif 19100a23bdaSmrg# clock_gettime might require -rt, or it might not. find out 19200a23bdaSmrgif not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>') 19300a23bdaSmrg # XXX: untested 19400a23bdaSmrg dep_rt = cc.find_library('rt') 19500a23bdaSmrgelse 19600a23bdaSmrg dep_rt = [] 19700a23bdaSmrgendif 19800a23bdaSmrgdep_m = cc.find_library('m', required : false) 1999bd392adSmrg 2009bd392adSmrg# The header is not required on Linux, and is in fact deprecated in glibc 2.30+ 2019bd392adSmrgif ['linux'].contains(host_machine.system()) 2029bd392adSmrg config.set10('HAVE_SYS_SYSCTL_H', false) 2039bd392adSmrgelse 2049bd392adSmrg # From Niclas Zeising: 2059bd392adSmrg # FreeBSD requires sys/types.h for sys/sysctl.h, so add it as part of 2069bd392adSmrg # the includes when checking for headers. 2079bd392adSmrg config.set10('HAVE_SYS_SYSCTL_H', 2089bd392adSmrg cc.compiles('#include <sys/types.h>\n#include <sys/sysctl.h>', name : 'sys/sysctl.h works')) 2099bd392adSmrgendif 2109bd392adSmrg 2119bd392adSmrgforeach header : ['sys/select.h', 'alloca.h'] 2120ed5401bSmrg config.set10('HAVE_' + header.underscorify().to_upper(), cc.check_header(header)) 2137cdc0497Smrgendforeach 2149bd392adSmrg 21588f8a8d2Smrgif (cc.has_header_symbol('sys/sysmacros.h', 'major') and 21688f8a8d2Smrg cc.has_header_symbol('sys/sysmacros.h', 'minor') and 21788f8a8d2Smrg cc.has_header_symbol('sys/sysmacros.h', 'makedev')) 21800a23bdaSmrg config.set10('MAJOR_IN_SYSMACROS', true) 21988f8a8d2Smrgendif 22088f8a8d2Smrgif (cc.has_header_symbol('sys/mkdev.h', 'major') and 22188f8a8d2Smrg cc.has_header_symbol('sys/mkdev.h', 'minor') and 22288f8a8d2Smrg cc.has_header_symbol('sys/mkdev.h', 'makedev')) 22300a23bdaSmrg config.set10('MAJOR_IN_MKDEV', true) 22400a23bdaSmrgendif 2257cdc0497Smrgconfig.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream')) 22600a23bdaSmrg 2270ed5401bSmrglibdrm_c_args = cc.get_supported_arguments([ 2280ed5401bSmrg '-Wsign-compare', '-Werror=undef', '-Werror=implicit-function-declaration', 2290ed5401bSmrg '-Wpointer-arith', '-Wwrite-strings', '-Wstrict-prototypes', 2300ed5401bSmrg '-Wmissing-prototypes', '-Wmissing-declarations', '-Wnested-externs', 2310ed5401bSmrg '-Wpacked', '-Wswitch-enum', '-Wmissing-format-attribute', 2320ed5401bSmrg '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow', 2330ed5401bSmrg '-Wdeclaration-after-statement', '-Wold-style-definition', 2340ed5401bSmrg '-Wno-unused-parameter', '-Wno-attributes', '-Wno-long-long', 2350ed5401bSmrg '-Wno-missing-field-initializers']) 23600a23bdaSmrg 23700a23bdaSmrgdep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel) 23800a23bdaSmrgdep_cunit = dependency('cunit', version : '>= 2.1', required : false) 23900a23bdaSmrg_cairo_tests = get_option('cairo-tests') 24000a23bdaSmrgif _cairo_tests != 'false' 24100a23bdaSmrg dep_cairo = dependency('cairo', required : _cairo_tests == 'true') 24200a23bdaSmrg with_cairo_tests = dep_cairo.found() 24300a23bdaSmrgelse 24400a23bdaSmrg dep_cairo = [] 24500a23bdaSmrg with_cairo_tests = false 24600a23bdaSmrgendif 24700a23bdaSmrg_valgrind = get_option('valgrind') 24800a23bdaSmrgif _valgrind != 'false' 2499bd392adSmrg if with_freedreno 2509bd392adSmrg dep_valgrind = dependency('valgrind', required : _valgrind == 'true', version : '>=3.10.0') 2519bd392adSmrg else 2529bd392adSmrg dep_valgrind = dependency('valgrind', required : _valgrind == 'true') 2539bd392adSmrg endif 25400a23bdaSmrg with_valgrind = dep_valgrind.found() 25500a23bdaSmrgelse 25600a23bdaSmrg dep_valgrind = [] 25700a23bdaSmrg with_valgrind = false 25800a23bdaSmrgendif 25900a23bdaSmrg 26000a23bdaSmrgwith_man_pages = get_option('man-pages') 26141687f09Smrgprog_rst2man = find_program('rst2man', 'rst2man.py', required: with_man_pages == 'true') 26241687f09Smrgwith_man_pages = with_man_pages != 'false' and prog_rst2man.found() 26300a23bdaSmrg 2640ed5401bSmrgconfig.set10('HAVE_VISIBILITY', cc.has_function_attribute('visibility:hidden')) 26500a23bdaSmrg 26600a23bdaSmrgforeach t : [ 26700a23bdaSmrg [with_exynos, 'EXYNOS'], 26800a23bdaSmrg [with_freedreno_kgsl, 'FREEDRENO_KGSL'], 26900a23bdaSmrg [with_intel, 'INTEL'], 27000a23bdaSmrg [with_nouveau, 'NOUVEAU'], 27100a23bdaSmrg [with_radeon, 'RADEON'], 27200a23bdaSmrg [with_vc4, 'VC4'], 27300a23bdaSmrg [with_vmwgfx, 'VMWGFX'], 27400a23bdaSmrg [with_cairo_tests, 'CAIRO'], 27500a23bdaSmrg [with_valgrind, 'VALGRIND'], 27600a23bdaSmrg ] 27700a23bdaSmrg config.set10('HAVE_@0@'.format(t[1]), t[0]) 27800a23bdaSmrgendforeach 27900a23bdaSmrgif with_freedreno_kgsl and not with_freedreno 28000a23bdaSmrg error('cannot enable freedreno-kgsl without freedreno support') 28100a23bdaSmrgendif 28200a23bdaSmrgconfig.set10('_GNU_SOURCE', true) 28300a23bdaSmrgconfig_file = configure_file( 28400a23bdaSmrg configuration : config, 28500a23bdaSmrg output : 'config.h', 28600a23bdaSmrg) 2879bd392adSmrgadd_project_arguments('-include', '@0@'.format(config_file), language : 'c') 28800a23bdaSmrg 28900a23bdaSmrginc_root = include_directories('.') 29000a23bdaSmrginc_drm = include_directories('include/drm') 29100a23bdaSmrg 29249ef06a4Smrglibdrm_files = [files( 29349ef06a4Smrg 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c', 29449ef06a4Smrg 'xf86drmMode.c' 29549ef06a4Smrg ), 29649ef06a4Smrg config_file, format_mod_static_table 29749ef06a4Smrg] 29849ef06a4Smrg 2990ed5401bSmrg# Build an unversioned so on android 30049ef06a4Smrgif android 3010ed5401bSmrg libdrm_kw = {} 30249ef06a4Smrgelse 3030ed5401bSmrg libdrm_kw = {'version' : '2.4.0'} 3040ed5401bSmrgendif 3050ed5401bSmrg 3060ed5401bSmrglibdrm = library( 3070ed5401bSmrg 'drm', 3080ed5401bSmrg libdrm_files, 3090ed5401bSmrg c_args : libdrm_c_args, 3100ed5401bSmrg dependencies : [dep_valgrind, dep_rt, dep_m], 3110ed5401bSmrg include_directories : inc_drm, 3120ed5401bSmrg install : true, 3130ed5401bSmrg kwargs : libdrm_kw, 3140ed5401bSmrg gnu_symbol_visibility : 'hidden', 3150ed5401bSmrg) 31600a23bdaSmrg 3179bd392adSmrgtest( 3189bd392adSmrg 'core-symbols-check', 3199bd392adSmrg symbols_check, 3209bd392adSmrg args : [ 3219bd392adSmrg '--lib', libdrm, 3229bd392adSmrg '--symbols-file', files('core-symbols.txt'), 3239bd392adSmrg '--nm', prog_nm.path(), 3249bd392adSmrg ], 3259bd392adSmrg) 3269bd392adSmrg 32700a23bdaSmrgext_libdrm = declare_dependency( 32800a23bdaSmrg link_with : libdrm, 32900a23bdaSmrg include_directories : [inc_root, inc_drm], 33000a23bdaSmrg) 33100a23bdaSmrg 3320ed5401bSmrgif meson.version().version_compare('>= 0.54.0') 3330ed5401bSmrg meson.override_dependency('libdrm', ext_libdrm) 3340ed5401bSmrgendif 3350ed5401bSmrg 33600a23bdaSmrginstall_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h') 33700a23bdaSmrginstall_headers( 33800a23bdaSmrg 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h', 33900a23bdaSmrg 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h', 34000a23bdaSmrg 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h', 3417cdc0497Smrg 'include/drm/msm_drm.h', 'include/drm/nouveau_drm.h', 3427cdc0497Smrg 'include/drm/qxl_drm.h', 'include/drm/r128_drm.h', 3437cdc0497Smrg 'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h', 3447cdc0497Smrg 'include/drm/savage_drm.h', 'include/drm/sis_drm.h', 3457cdc0497Smrg 'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h', 34600a23bdaSmrg 'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h', 34700a23bdaSmrg subdir : 'libdrm', 34800a23bdaSmrg) 34900a23bdaSmrgif with_vmwgfx 35000a23bdaSmrg install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm') 35100a23bdaSmrgendif 35200a23bdaSmrg 35300a23bdaSmrgpkg.generate( 3540ed5401bSmrg libdrm, 35500a23bdaSmrg name : 'libdrm', 35600a23bdaSmrg subdirs : ['.', 'libdrm'], 35700a23bdaSmrg description : 'Userspace interface to kernel DRM services', 35800a23bdaSmrg) 35900a23bdaSmrg 36000a23bdaSmrgif with_intel 36100a23bdaSmrg subdir('intel') 36200a23bdaSmrgendif 36300a23bdaSmrgif with_nouveau 36400a23bdaSmrg subdir('nouveau') 36500a23bdaSmrgendif 36600a23bdaSmrgif with_radeon 36700a23bdaSmrg subdir('radeon') 36800a23bdaSmrgendif 36900a23bdaSmrgif with_amdgpu 37000a23bdaSmrg subdir('amdgpu') 37100a23bdaSmrgendif 37200a23bdaSmrgif with_omap 37300a23bdaSmrg subdir('omap') 37400a23bdaSmrgendif 37500a23bdaSmrgif with_exynos 37600a23bdaSmrg subdir('exynos') 37700a23bdaSmrgendif 37800a23bdaSmrgif with_freedreno 37900a23bdaSmrg subdir('freedreno') 38000a23bdaSmrgendif 38100a23bdaSmrgif with_tegra 38200a23bdaSmrg subdir('tegra') 38300a23bdaSmrgendif 38400a23bdaSmrgif with_vc4 38500a23bdaSmrg subdir('vc4') 38600a23bdaSmrgendif 38700a23bdaSmrgif with_etnaviv 38800a23bdaSmrg subdir('etnaviv') 38900a23bdaSmrgendif 39000a23bdaSmrgif with_man_pages 39100a23bdaSmrg subdir('man') 39200a23bdaSmrgendif 39300a23bdaSmrgsubdir('data') 39400a23bdaSmrgsubdir('tests') 395