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