meson.build revision 88f8a8d2
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'], 2488f8a8d2Smrg version : '2.4.100', 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 1605324fb0dSmrg# XXX: Apparently 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) 18288f8a8d2Smrg# From Niclas Zeising: 18388f8a8d2Smrg# FreeBSD requires sys/types.h for sys/sysctl.h, add it as part of the 18488f8a8d2Smrg# includes when checking for headers. 1857cdc0497Smrgforeach header : ['sys/sysctl.h', 'sys/select.h', 'alloca.h'] 1867cdc0497Smrg config.set('HAVE_' + header.underscorify().to_upper(), 18788f8a8d2Smrg cc.compiles('#include <sys/types.h>\n#include <@0@>'.format(header), name : '@0@ works'.format(header))) 1887cdc0497Smrgendforeach 18988f8a8d2Smrgif (cc.has_header_symbol('sys/sysmacros.h', 'major') and 19088f8a8d2Smrg cc.has_header_symbol('sys/sysmacros.h', 'minor') and 19188f8a8d2Smrg cc.has_header_symbol('sys/sysmacros.h', 'makedev')) 19200a23bdaSmrg config.set10('MAJOR_IN_SYSMACROS', true) 19388f8a8d2Smrgendif 19488f8a8d2Smrgif (cc.has_header_symbol('sys/mkdev.h', 'major') and 19588f8a8d2Smrg cc.has_header_symbol('sys/mkdev.h', 'minor') and 19688f8a8d2Smrg cc.has_header_symbol('sys/mkdev.h', 'makedev')) 19700a23bdaSmrg config.set10('MAJOR_IN_MKDEV', true) 19800a23bdaSmrgendif 1997cdc0497Smrgconfig.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream')) 20000a23bdaSmrg 20100a23bdaSmrgwarn_c_args = [] 20200a23bdaSmrgforeach a : ['-Wall', '-Wextra', '-Wsign-compare', '-Werror=undef', 2036532f28eSmrg '-Werror=implicit-function-declaration', '-Wpointer-arith', 20400a23bdaSmrg '-Wwrite-strings', '-Wstrict-prototypes', '-Wmissing-prototypes', 20500a23bdaSmrg '-Wmissing-declarations', '-Wnested-externs', '-Wpacked', 20600a23bdaSmrg '-Wswitch-enum', '-Wmissing-format-attribute', 20700a23bdaSmrg '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow', 20800a23bdaSmrg '-Wdeclaration-after-statement', '-Wold-style-definition'] 20900a23bdaSmrg if cc.has_argument(a) 21000a23bdaSmrg warn_c_args += a 21100a23bdaSmrg endif 21200a23bdaSmrgendforeach 21300a23bdaSmrg# GCC will never error for -Wno-*, so check for -W* then add -Wno-* to the list 21400a23bdaSmrg# of options 21500a23bdaSmrgforeach a : ['unused-parameter', 'attributes', 'long-long', 21600a23bdaSmrg 'missing-field-initializers'] 21700a23bdaSmrg if cc.has_argument('-W@0@'.format(a)) 21800a23bdaSmrg warn_c_args += '-Wno-@0@'.format(a) 21900a23bdaSmrg endif 22000a23bdaSmrgendforeach 22100a23bdaSmrg 2227cdc0497Smrg# all c args: 2237cdc0497Smrglibdrm_c_args = warn_c_args + ['-fvisibility=hidden'] 2247cdc0497Smrg 22500a23bdaSmrg 22600a23bdaSmrgdep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel) 22700a23bdaSmrgdep_cunit = dependency('cunit', version : '>= 2.1', required : false) 22800a23bdaSmrg_cairo_tests = get_option('cairo-tests') 22900a23bdaSmrgif _cairo_tests != 'false' 23000a23bdaSmrg dep_cairo = dependency('cairo', required : _cairo_tests == 'true') 23100a23bdaSmrg with_cairo_tests = dep_cairo.found() 23200a23bdaSmrgelse 23300a23bdaSmrg dep_cairo = [] 23400a23bdaSmrg with_cairo_tests = false 23500a23bdaSmrgendif 23600a23bdaSmrg_valgrind = get_option('valgrind') 23700a23bdaSmrgif _valgrind != 'false' 23800a23bdaSmrg dep_valgrind = dependency('valgrind', required : _valgrind == 'true') 23900a23bdaSmrg with_valgrind = dep_valgrind.found() 24000a23bdaSmrgelse 24100a23bdaSmrg dep_valgrind = [] 24200a23bdaSmrg with_valgrind = false 24300a23bdaSmrgendif 24400a23bdaSmrg 24500a23bdaSmrgwith_man_pages = get_option('man-pages') 24600a23bdaSmrgprog_xslt = find_program('xsltproc', required : with_man_pages == 'true') 24700a23bdaSmrgprog_sed = find_program('sed', required : with_man_pages == 'true') 24800a23bdaSmrgmanpage_style = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl' 24900a23bdaSmrgif prog_xslt.found() 25000a23bdaSmrg if run_command(prog_xslt, '--nonet', manpage_style).returncode() != 0 25100a23bdaSmrg if with_man_pages == 'true' 25200a23bdaSmrg error('Manpage style sheet cannot be found') 25300a23bdaSmrg endif 25400a23bdaSmrg with_man_pages = 'false' 25500a23bdaSmrg endif 25600a23bdaSmrgendif 25700a23bdaSmrgwith_man_pages = with_man_pages != 'false' and prog_xslt.found() and prog_sed.found() 25800a23bdaSmrg 2597cdc0497Smrgconfig.set10('HAVE_VISIBILITY', 2607cdc0497Smrg cc.compiles('''int foo_hidden(void) __attribute__((visibility(("hidden"))));''', 2617cdc0497Smrg name : 'compiler supports __attribute__(("hidden"))')) 26200a23bdaSmrg 26300a23bdaSmrgforeach t : [ 26400a23bdaSmrg [with_exynos, 'EXYNOS'], 26500a23bdaSmrg [with_freedreno_kgsl, 'FREEDRENO_KGSL'], 26600a23bdaSmrg [with_intel, 'INTEL'], 26700a23bdaSmrg [with_nouveau, 'NOUVEAU'], 26800a23bdaSmrg [with_radeon, 'RADEON'], 26900a23bdaSmrg [with_vc4, 'VC4'], 27000a23bdaSmrg [with_vmwgfx, 'VMWGFX'], 27100a23bdaSmrg [with_cairo_tests, 'CAIRO'], 27200a23bdaSmrg [with_valgrind, 'VALGRIND'], 27300a23bdaSmrg ] 27400a23bdaSmrg config.set10('HAVE_@0@'.format(t[1]), t[0]) 27500a23bdaSmrgendforeach 27600a23bdaSmrgif with_freedreno_kgsl and not with_freedreno 27700a23bdaSmrg error('cannot enable freedreno-kgsl without freedreno support') 27800a23bdaSmrgendif 27900a23bdaSmrgconfig.set10('_GNU_SOURCE', true) 28000a23bdaSmrgconfig_file = configure_file( 28100a23bdaSmrg configuration : config, 28200a23bdaSmrg output : 'config.h', 28300a23bdaSmrg) 2847cdc0497Smrgadd_project_arguments('-include', 'config.h', language : 'c') 28500a23bdaSmrg 28600a23bdaSmrginc_root = include_directories('.') 28700a23bdaSmrginc_drm = include_directories('include/drm') 28800a23bdaSmrg 28900a23bdaSmrglibdrm = shared_library( 29000a23bdaSmrg 'drm', 29100a23bdaSmrg [files( 29200a23bdaSmrg 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c', 29300a23bdaSmrg 'xf86drmMode.c' 29400a23bdaSmrg ), 29500a23bdaSmrg config_file, 29600a23bdaSmrg ], 2977cdc0497Smrg c_args : libdrm_c_args, 2987cdc0497Smrg dependencies : [dep_valgrind, dep_rt, dep_m], 29900a23bdaSmrg include_directories : inc_drm, 30000a23bdaSmrg version : '2.4.0', 30100a23bdaSmrg install : true, 30200a23bdaSmrg) 30300a23bdaSmrg 30400a23bdaSmrgext_libdrm = declare_dependency( 30500a23bdaSmrg link_with : libdrm, 30600a23bdaSmrg include_directories : [inc_root, inc_drm], 30700a23bdaSmrg) 30800a23bdaSmrg 30900a23bdaSmrginstall_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h') 31000a23bdaSmrginstall_headers( 31100a23bdaSmrg 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h', 31200a23bdaSmrg 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h', 31300a23bdaSmrg 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h', 3147cdc0497Smrg 'include/drm/msm_drm.h', 'include/drm/nouveau_drm.h', 3157cdc0497Smrg 'include/drm/qxl_drm.h', 'include/drm/r128_drm.h', 3167cdc0497Smrg 'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h', 3177cdc0497Smrg 'include/drm/savage_drm.h', 'include/drm/sis_drm.h', 3187cdc0497Smrg 'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h', 31900a23bdaSmrg 'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h', 32000a23bdaSmrg subdir : 'libdrm', 32100a23bdaSmrg) 32200a23bdaSmrgif with_vmwgfx 32300a23bdaSmrg install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm') 32400a23bdaSmrgendif 32500a23bdaSmrg 32600a23bdaSmrgpkg.generate( 32700a23bdaSmrg name : 'libdrm', 32800a23bdaSmrg libraries : libdrm, 32900a23bdaSmrg subdirs : ['.', 'libdrm'], 33000a23bdaSmrg version : meson.project_version(), 33100a23bdaSmrg description : 'Userspace interface to kernel DRM services', 33200a23bdaSmrg) 33300a23bdaSmrg 33400a23bdaSmrgenv_test = environment() 33500a23bdaSmrgenv_test.set('NM', find_program('nm').path()) 33600a23bdaSmrg 33700a23bdaSmrgif with_libkms 33800a23bdaSmrg subdir('libkms') 33900a23bdaSmrgendif 34000a23bdaSmrgif with_intel 34100a23bdaSmrg subdir('intel') 34200a23bdaSmrgendif 34300a23bdaSmrgif with_nouveau 34400a23bdaSmrg subdir('nouveau') 34500a23bdaSmrgendif 34600a23bdaSmrgif with_radeon 34700a23bdaSmrg subdir('radeon') 34800a23bdaSmrgendif 34900a23bdaSmrgif with_amdgpu 35000a23bdaSmrg subdir('amdgpu') 35100a23bdaSmrgendif 35200a23bdaSmrgif with_omap 35300a23bdaSmrg subdir('omap') 35400a23bdaSmrgendif 35500a23bdaSmrgif with_exynos 35600a23bdaSmrg subdir('exynos') 35700a23bdaSmrgendif 35800a23bdaSmrgif with_freedreno 35900a23bdaSmrg subdir('freedreno') 36000a23bdaSmrgendif 36100a23bdaSmrgif with_tegra 36200a23bdaSmrg subdir('tegra') 36300a23bdaSmrgendif 36400a23bdaSmrgif with_vc4 36500a23bdaSmrg subdir('vc4') 36600a23bdaSmrgendif 36700a23bdaSmrgif with_etnaviv 36800a23bdaSmrg subdir('etnaviv') 36900a23bdaSmrgendif 37000a23bdaSmrgif with_man_pages 37100a23bdaSmrg subdir('man') 37200a23bdaSmrgendif 37300a23bdaSmrgsubdir('data') 37400a23bdaSmrgsubdir('tests') 37500a23bdaSmrg 37600a23bdaSmrgmessage('') 37700a23bdaSmrgmessage('@0@ will be compiled with:'.format(meson.project_name())) 37800a23bdaSmrgmessage('') 37900a23bdaSmrgmessage(' libkms @0@'.format(with_libkms)) 38000a23bdaSmrgmessage(' Intel API @0@'.format(with_intel)) 38100a23bdaSmrgmessage(' vmwgfx API @0@'.format(with_vmwgfx)) 38200a23bdaSmrgmessage(' Radeon API @0@'.format(with_radeon)) 38300a23bdaSmrgmessage(' AMDGPU API @0@'.format(with_amdgpu)) 38400a23bdaSmrgmessage(' Nouveau API @0@'.format(with_nouveau)) 38500a23bdaSmrgmessage(' OMAP API @0@'.format(with_omap)) 38600a23bdaSmrgmessage(' EXYNOS API @0@'.format(with_exynos)) 38700a23bdaSmrgmessage(' Freedreno API @0@ (kgsl: @1@)'.format(with_freedreno, with_freedreno_kgsl)) 38800a23bdaSmrgmessage(' Tegra API @0@'.format(with_tegra)) 38900a23bdaSmrgmessage(' VC4 API @0@'.format(with_vc4)) 39000a23bdaSmrgmessage(' Etnaviv API @0@'.format(with_etnaviv)) 39100a23bdaSmrgmessage('') 392