meson.build revision 6532f28e
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'], 246532f28eSmrg version : '2.4.97', 2500a23bdaSmrg license : 'MIT', 2600a23bdaSmrg meson_version : '>= 0.43', 2700a23bdaSmrg default_options : ['buildtype=debugoptimized', 'c_std=gnu99'], 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 4700a23bdaSmrg# Check for atomics 4800a23bdaSmrgintel_atomics = false 4900a23bdaSmrglib_atomics = false 5000a23bdaSmrg 517cdc0497Smrgdep_atomic_ops = dependency('atomic_ops', required : false) 5200a23bdaSmrgif cc.compiles(''' 5300a23bdaSmrg int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); } 5400a23bdaSmrg int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); } 5500a23bdaSmrg ''', 5600a23bdaSmrg name : 'Intel Atomics') 5700a23bdaSmrg intel_atomics = true 5800a23bdaSmrg with_atomics = true 597cdc0497Smrg dep_atomic_ops = [] 607cdc0497Smrgelif dep_atomic_ops.found() 6100a23bdaSmrg lib_atomics = true 6200a23bdaSmrg with_atomics = true 6300a23bdaSmrgelif cc.has_function('atomic_cas_uint') 6400a23bdaSmrg with_atomics = true 6500a23bdaSmrgelse 6600a23bdaSmrg with_atomics = false 6700a23bdaSmrgendif 6800a23bdaSmrg 6900a23bdaSmrgconfig.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics) 7000a23bdaSmrgconfig.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics) 7100a23bdaSmrg 7200a23bdaSmrgwith_intel = false 7300a23bdaSmrg_intel = get_option('intel') 7400a23bdaSmrgif _intel != 'false' 7500a23bdaSmrg if _intel == 'true' and not with_atomics 7600a23bdaSmrg error('libdrm_intel requires atomics.') 7700a23bdaSmrg else 7800a23bdaSmrg with_intel = _intel == 'true' or host_machine.cpu_family().startswith('x86') 7900a23bdaSmrg endif 8000a23bdaSmrgendif 8100a23bdaSmrg 8200a23bdaSmrgwith_radeon = false 8300a23bdaSmrg_radeon = get_option('radeon') 8400a23bdaSmrgif _radeon != 'false' 8500a23bdaSmrg if _radeon == 'true' and not with_atomics 8600a23bdaSmrg error('libdrm_radeon requires atomics.') 8700a23bdaSmrg endif 8800a23bdaSmrg with_radeon = true 8900a23bdaSmrgendif 9000a23bdaSmrg 9100a23bdaSmrgwith_amdgpu = false 9200a23bdaSmrg_amdgpu = get_option('amdgpu') 9300a23bdaSmrgif _amdgpu != 'false' 9400a23bdaSmrg if _amdgpu == 'true' and not with_atomics 9500a23bdaSmrg error('libdrm_amdgpu requires atomics.') 9600a23bdaSmrg endif 9700a23bdaSmrg with_amdgpu = true 9800a23bdaSmrgendif 9900a23bdaSmrg 10000a23bdaSmrgwith_nouveau = false 10100a23bdaSmrg_nouveau = get_option('nouveau') 10200a23bdaSmrgif _nouveau != 'false' 10300a23bdaSmrg if _nouveau == 'true' and not with_atomics 10400a23bdaSmrg error('libdrm_nouveau requires atomics.') 10500a23bdaSmrg endif 10600a23bdaSmrg with_nouveau = true 10700a23bdaSmrgendif 10800a23bdaSmrg 10900a23bdaSmrgwith_vmwgfx = false 11000a23bdaSmrg_vmwgfx = get_option('vmwgfx') 11100a23bdaSmrgif _vmwgfx != 'false' 11200a23bdaSmrg with_vmwgfx = true 11300a23bdaSmrgendif 11400a23bdaSmrg 11500a23bdaSmrgwith_omap = false 11600a23bdaSmrg_omap = get_option('omap') 11700a23bdaSmrgif _omap == 'true' 11800a23bdaSmrg if not with_atomics 11900a23bdaSmrg error('libdrm_omap requires atomics.') 12000a23bdaSmrg endif 12100a23bdaSmrg with_omap = true 12200a23bdaSmrgendif 12300a23bdaSmrg 12400a23bdaSmrgwith_freedreno = false 12500a23bdaSmrg_freedreno = get_option('freedreno') 12600a23bdaSmrgif _freedreno != 'false' 12700a23bdaSmrg if _freedreno == 'true' and not with_atomics 12800a23bdaSmrg error('libdrm_freedreno requires atomics.') 12900a23bdaSmrg else 13000a23bdaSmrg with_freedreno = _freedreno == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family()) 13100a23bdaSmrg endif 13200a23bdaSmrgendif 13300a23bdaSmrg 13400a23bdaSmrgwith_tegra = false 13500a23bdaSmrg_tegra = get_option('tegra') 13600a23bdaSmrgif _tegra == 'true' 13700a23bdaSmrg if not with_atomics 13800a23bdaSmrg error('libdrm_tegra requires atomics.') 13900a23bdaSmrg endif 14000a23bdaSmrg with_tegra = true 14100a23bdaSmrgendif 14200a23bdaSmrg 14300a23bdaSmrgwith_etnaviv = false 14400a23bdaSmrg_etnaviv = get_option('etnaviv') 14500a23bdaSmrgif _etnaviv == 'true' 14600a23bdaSmrg if not with_atomics 14700a23bdaSmrg error('libdrm_etnaviv requires atomics.') 14800a23bdaSmrg endif 14900a23bdaSmrg with_etnaviv = true 15000a23bdaSmrgendif 15100a23bdaSmrg 15200a23bdaSmrgwith_exynos = get_option('exynos') == 'true' 15300a23bdaSmrg 15400a23bdaSmrgwith_vc4 = false 15500a23bdaSmrg_vc4 = get_option('vc4') 15600a23bdaSmrgif _vc4 != 'false' 15700a23bdaSmrg with_vc4 = _vc4 == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family()) 15800a23bdaSmrgendif 15900a23bdaSmrg 16000a23bdaSmrg# XXX: Aparently only freebsd and dragonfly bsd actually need this (and 16100a23bdaSmrg# gnu/kfreebsd), not openbsd and netbsd 16200a23bdaSmrgwith_libkms = false 16300a23bdaSmrg_libkms = get_option('libkms') 16400a23bdaSmrgif _libkms != 'false' 16500a23bdaSmrg with_libkms = _libkms == 'true' or ['linux', 'freebsd', 'dragonfly'].contains(host_machine.system()) 16600a23bdaSmrgendif 16700a23bdaSmrg 16800a23bdaSmrg# Among others FreeBSD does not have a separate dl library. 16900a23bdaSmrgif not cc.has_function('dlsym') 17000a23bdaSmrg dep_dl = cc.find_library('dl', required : with_nouveau) 17100a23bdaSmrgelse 17200a23bdaSmrg dep_dl = [] 17300a23bdaSmrgendif 17400a23bdaSmrg# clock_gettime might require -rt, or it might not. find out 17500a23bdaSmrgif not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>') 17600a23bdaSmrg # XXX: untested 17700a23bdaSmrg dep_rt = cc.find_library('rt') 17800a23bdaSmrgelse 17900a23bdaSmrg dep_rt = [] 18000a23bdaSmrgendif 18100a23bdaSmrgdep_m = cc.find_library('m', required : false) 1827cdc0497Smrgforeach header : ['sys/sysctl.h', 'sys/select.h', 'alloca.h'] 1837cdc0497Smrg config.set('HAVE_' + header.underscorify().to_upper(), 1847cdc0497Smrg cc.compiles('#include <@0@>'.format(header), name : '@0@ works'.format(header))) 1857cdc0497Smrgendforeach 18600a23bdaSmrgif cc.has_header_symbol('sys/sysmacros.h', 'major') 18700a23bdaSmrg config.set10('MAJOR_IN_SYSMACROS', true) 18800a23bdaSmrgelif cc.has_header_symbol('sys/mkdev.h', 'major') 18900a23bdaSmrg config.set10('MAJOR_IN_MKDEV', true) 19000a23bdaSmrgendif 1917cdc0497Smrgconfig.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream')) 19200a23bdaSmrg 19300a23bdaSmrgwarn_c_args = [] 19400a23bdaSmrgforeach a : ['-Wall', '-Wextra', '-Wsign-compare', '-Werror=undef', 1956532f28eSmrg '-Werror=implicit-function-declaration', '-Wpointer-arith', 19600a23bdaSmrg '-Wwrite-strings', '-Wstrict-prototypes', '-Wmissing-prototypes', 19700a23bdaSmrg '-Wmissing-declarations', '-Wnested-externs', '-Wpacked', 19800a23bdaSmrg '-Wswitch-enum', '-Wmissing-format-attribute', 19900a23bdaSmrg '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow', 20000a23bdaSmrg '-Wdeclaration-after-statement', '-Wold-style-definition'] 20100a23bdaSmrg if cc.has_argument(a) 20200a23bdaSmrg warn_c_args += a 20300a23bdaSmrg endif 20400a23bdaSmrgendforeach 20500a23bdaSmrg# GCC will never error for -Wno-*, so check for -W* then add -Wno-* to the list 20600a23bdaSmrg# of options 20700a23bdaSmrgforeach a : ['unused-parameter', 'attributes', 'long-long', 20800a23bdaSmrg 'missing-field-initializers'] 20900a23bdaSmrg if cc.has_argument('-W@0@'.format(a)) 21000a23bdaSmrg warn_c_args += '-Wno-@0@'.format(a) 21100a23bdaSmrg endif 21200a23bdaSmrgendforeach 21300a23bdaSmrg 2147cdc0497Smrg# all c args: 2157cdc0497Smrglibdrm_c_args = warn_c_args + ['-fvisibility=hidden'] 2167cdc0497Smrg 21700a23bdaSmrg 21800a23bdaSmrgdep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel) 21900a23bdaSmrgdep_cunit = dependency('cunit', version : '>= 2.1', required : false) 22000a23bdaSmrg_cairo_tests = get_option('cairo-tests') 22100a23bdaSmrgif _cairo_tests != 'false' 22200a23bdaSmrg dep_cairo = dependency('cairo', required : _cairo_tests == 'true') 22300a23bdaSmrg with_cairo_tests = dep_cairo.found() 22400a23bdaSmrgelse 22500a23bdaSmrg dep_cairo = [] 22600a23bdaSmrg with_cairo_tests = false 22700a23bdaSmrgendif 22800a23bdaSmrg_valgrind = get_option('valgrind') 22900a23bdaSmrgif _valgrind != 'false' 23000a23bdaSmrg dep_valgrind = dependency('valgrind', required : _valgrind == 'true') 23100a23bdaSmrg with_valgrind = dep_valgrind.found() 23200a23bdaSmrgelse 23300a23bdaSmrg dep_valgrind = [] 23400a23bdaSmrg with_valgrind = false 23500a23bdaSmrgendif 23600a23bdaSmrg 23700a23bdaSmrgwith_man_pages = get_option('man-pages') 23800a23bdaSmrgprog_xslt = find_program('xsltproc', required : with_man_pages == 'true') 23900a23bdaSmrgprog_sed = find_program('sed', required : with_man_pages == 'true') 24000a23bdaSmrgmanpage_style = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl' 24100a23bdaSmrgif prog_xslt.found() 24200a23bdaSmrg if run_command(prog_xslt, '--nonet', manpage_style).returncode() != 0 24300a23bdaSmrg if with_man_pages == 'true' 24400a23bdaSmrg error('Manpage style sheet cannot be found') 24500a23bdaSmrg endif 24600a23bdaSmrg with_man_pages = 'false' 24700a23bdaSmrg endif 24800a23bdaSmrgendif 24900a23bdaSmrgwith_man_pages = with_man_pages != 'false' and prog_xslt.found() and prog_sed.found() 25000a23bdaSmrg 25100a23bdaSmrg# Used for tets 25200a23bdaSmrgprog_bash = find_program('bash') 25300a23bdaSmrg 2547cdc0497Smrgconfig.set10('HAVE_VISIBILITY', 2557cdc0497Smrg cc.compiles('''int foo_hidden(void) __attribute__((visibility(("hidden"))));''', 2567cdc0497Smrg name : 'compiler supports __attribute__(("hidden"))')) 25700a23bdaSmrg 25800a23bdaSmrgforeach t : [ 25900a23bdaSmrg [with_exynos, 'EXYNOS'], 26000a23bdaSmrg [with_freedreno_kgsl, 'FREEDRENO_KGSL'], 26100a23bdaSmrg [with_intel, 'INTEL'], 26200a23bdaSmrg [with_nouveau, 'NOUVEAU'], 26300a23bdaSmrg [with_radeon, 'RADEON'], 26400a23bdaSmrg [with_vc4, 'VC4'], 26500a23bdaSmrg [with_vmwgfx, 'VMWGFX'], 26600a23bdaSmrg [with_cairo_tests, 'CAIRO'], 26700a23bdaSmrg [with_valgrind, 'VALGRIND'], 26800a23bdaSmrg ] 26900a23bdaSmrg config.set10('HAVE_@0@'.format(t[1]), t[0]) 27000a23bdaSmrgendforeach 27100a23bdaSmrgif with_freedreno_kgsl and not with_freedreno 27200a23bdaSmrg error('cannot enable freedreno-kgsl without freedreno support') 27300a23bdaSmrgendif 27400a23bdaSmrgconfig.set10('_GNU_SOURCE', true) 27500a23bdaSmrgconfig_file = configure_file( 27600a23bdaSmrg configuration : config, 27700a23bdaSmrg output : 'config.h', 27800a23bdaSmrg) 2797cdc0497Smrgadd_project_arguments('-include', 'config.h', language : 'c') 28000a23bdaSmrg 28100a23bdaSmrginc_root = include_directories('.') 28200a23bdaSmrginc_drm = include_directories('include/drm') 28300a23bdaSmrg 28400a23bdaSmrglibdrm = shared_library( 28500a23bdaSmrg 'drm', 28600a23bdaSmrg [files( 28700a23bdaSmrg 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c', 28800a23bdaSmrg 'xf86drmMode.c' 28900a23bdaSmrg ), 29000a23bdaSmrg config_file, 29100a23bdaSmrg ], 2927cdc0497Smrg c_args : libdrm_c_args, 2937cdc0497Smrg dependencies : [dep_valgrind, dep_rt, dep_m], 29400a23bdaSmrg include_directories : inc_drm, 29500a23bdaSmrg version : '2.4.0', 29600a23bdaSmrg install : true, 29700a23bdaSmrg) 29800a23bdaSmrg 29900a23bdaSmrgext_libdrm = declare_dependency( 30000a23bdaSmrg link_with : libdrm, 30100a23bdaSmrg include_directories : [inc_root, inc_drm], 30200a23bdaSmrg) 30300a23bdaSmrg 30400a23bdaSmrginstall_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h') 30500a23bdaSmrginstall_headers( 30600a23bdaSmrg 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h', 30700a23bdaSmrg 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h', 30800a23bdaSmrg 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h', 3097cdc0497Smrg 'include/drm/msm_drm.h', 'include/drm/nouveau_drm.h', 3107cdc0497Smrg 'include/drm/qxl_drm.h', 'include/drm/r128_drm.h', 3117cdc0497Smrg 'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h', 3127cdc0497Smrg 'include/drm/savage_drm.h', 'include/drm/sis_drm.h', 3137cdc0497Smrg 'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h', 31400a23bdaSmrg 'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h', 31500a23bdaSmrg subdir : 'libdrm', 31600a23bdaSmrg) 31700a23bdaSmrgif with_vmwgfx 31800a23bdaSmrg install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm') 31900a23bdaSmrgendif 32000a23bdaSmrg 32100a23bdaSmrgpkg.generate( 32200a23bdaSmrg name : 'libdrm', 32300a23bdaSmrg libraries : libdrm, 32400a23bdaSmrg subdirs : ['.', 'libdrm'], 32500a23bdaSmrg version : meson.project_version(), 32600a23bdaSmrg description : 'Userspace interface to kernel DRM services', 32700a23bdaSmrg) 32800a23bdaSmrg 32900a23bdaSmrgenv_test = environment() 33000a23bdaSmrgenv_test.set('NM', find_program('nm').path()) 33100a23bdaSmrg 33200a23bdaSmrgif with_libkms 33300a23bdaSmrg subdir('libkms') 33400a23bdaSmrgendif 33500a23bdaSmrgif with_intel 33600a23bdaSmrg subdir('intel') 33700a23bdaSmrgendif 33800a23bdaSmrgif with_nouveau 33900a23bdaSmrg subdir('nouveau') 34000a23bdaSmrgendif 34100a23bdaSmrgif with_radeon 34200a23bdaSmrg subdir('radeon') 34300a23bdaSmrgendif 34400a23bdaSmrgif with_amdgpu 34500a23bdaSmrg subdir('amdgpu') 34600a23bdaSmrgendif 34700a23bdaSmrgif with_omap 34800a23bdaSmrg subdir('omap') 34900a23bdaSmrgendif 35000a23bdaSmrgif with_exynos 35100a23bdaSmrg subdir('exynos') 35200a23bdaSmrgendif 35300a23bdaSmrgif with_freedreno 35400a23bdaSmrg subdir('freedreno') 35500a23bdaSmrgendif 35600a23bdaSmrgif with_tegra 35700a23bdaSmrg subdir('tegra') 35800a23bdaSmrgendif 35900a23bdaSmrgif with_vc4 36000a23bdaSmrg subdir('vc4') 36100a23bdaSmrgendif 36200a23bdaSmrgif with_etnaviv 36300a23bdaSmrg subdir('etnaviv') 36400a23bdaSmrgendif 36500a23bdaSmrgif with_man_pages 36600a23bdaSmrg subdir('man') 36700a23bdaSmrgendif 36800a23bdaSmrgsubdir('data') 36900a23bdaSmrgsubdir('tests') 37000a23bdaSmrg 37100a23bdaSmrgmessage('') 37200a23bdaSmrgmessage('@0@ will be compiled with:'.format(meson.project_name())) 37300a23bdaSmrgmessage('') 37400a23bdaSmrgmessage(' libkms @0@'.format(with_libkms)) 37500a23bdaSmrgmessage(' Intel API @0@'.format(with_intel)) 37600a23bdaSmrgmessage(' vmwgfx API @0@'.format(with_vmwgfx)) 37700a23bdaSmrgmessage(' Radeon API @0@'.format(with_radeon)) 37800a23bdaSmrgmessage(' AMDGPU API @0@'.format(with_amdgpu)) 37900a23bdaSmrgmessage(' Nouveau API @0@'.format(with_nouveau)) 38000a23bdaSmrgmessage(' OMAP API @0@'.format(with_omap)) 38100a23bdaSmrgmessage(' EXYNOS API @0@'.format(with_exynos)) 38200a23bdaSmrgmessage(' Freedreno API @0@ (kgsl: @1@)'.format(with_freedreno, with_freedreno_kgsl)) 38300a23bdaSmrgmessage(' Tegra API @0@'.format(with_tegra)) 38400a23bdaSmrgmessage(' VC4 API @0@'.format(with_vc4)) 38500a23bdaSmrgmessage(' Etnaviv API @0@'.format(with_etnaviv)) 38600a23bdaSmrgmessage('') 387