1# Copyright © 2017-2018 Intel Corporation 2 3# Permission is hereby granted, free of charge, to any person obtaining a copy 4# of this software and associated documentation files (the "Software"), to deal 5# in the Software without restriction, including without limitation the rights 6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7# copies of the Software, and to permit persons to whom the Software is 8# furnished to do so, subject to the following conditions: 9 10# The above copyright notice and this permission notice shall be included in 11# all copies or substantial portions of the Software. 12 13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19# SOFTWARE. 20 21project( 22 'libdrm', 23 ['c'], 24 version : '2.4.110', 25 license : 'MIT', 26 meson_version : '>= 0.53', 27 default_options : ['buildtype=debugoptimized', 'c_std=c99'], 28) 29 30pkg = import('pkgconfig') 31 32config = configuration_data() 33 34config.set10('UDEV', get_option('udev')) 35with_freedreno_kgsl = get_option('freedreno-kgsl') 36with_install_tests = get_option('install-test-programs') 37 38if ['freebsd', 'dragonfly', 'netbsd'].contains(host_machine.system()) 39 dep_pthread_stubs = dependency('pthread-stubs', version : '>= 0.4') 40else 41 dep_pthread_stubs = [] 42endif 43dep_threads = dependency('threads') 44 45cc = meson.get_compiler('c') 46 47android = cc.compiles('''int func() { return __ANDROID__; }''') 48 49symbols_check = find_program('symbols-check.py') 50prog_nm = find_program('nm') 51 52# Check for atomics 53intel_atomics = false 54lib_atomics = false 55 56python3 = import('python').find_installation() 57format_mod_static_table = custom_target( 58 'format_mod_static_table', 59 output : 'generated_static_table_fourcc.h', 60 input : 'include/drm/drm_fourcc.h', 61 command : [python3, files('gen_table_fourcc.py'), '@INPUT@', '@OUTPUT@']) 62 63dep_atomic_ops = dependency('atomic_ops', required : false) 64if cc.links(''' 65 int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); } 66 int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); } 67 int main() { } 68 ''', 69 name : 'Intel Atomics') 70 intel_atomics = true 71 with_atomics = true 72 dep_atomic_ops = [] 73elif dep_atomic_ops.found() 74 lib_atomics = true 75 with_atomics = true 76elif cc.has_function('atomic_cas_uint') 77 with_atomics = true 78else 79 with_atomics = false 80endif 81 82config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics) 83config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics) 84 85with_intel = false 86_intel = get_option('intel') 87if _intel != 'false' 88 if _intel == 'true' and not with_atomics 89 error('libdrm_intel requires atomics.') 90 else 91 with_intel = _intel == 'true' or host_machine.cpu_family().startswith('x86') 92 endif 93endif 94summary('Intel', with_intel) 95 96with_radeon = false 97_radeon = get_option('radeon') 98if _radeon != 'false' 99 if _radeon == 'true' and not with_atomics 100 error('libdrm_radeon requires atomics.') 101 endif 102 with_radeon = true 103endif 104summary('Radeon', with_radeon) 105 106with_amdgpu = false 107_amdgpu = get_option('amdgpu') 108if _amdgpu != 'false' 109 if _amdgpu == 'true' and not with_atomics 110 error('libdrm_amdgpu requires atomics.') 111 endif 112 with_amdgpu = true 113endif 114summary('AMDGPU', with_amdgpu) 115 116with_nouveau = false 117_nouveau = get_option('nouveau') 118if _nouveau != 'false' 119 if _nouveau == 'true' and not with_atomics 120 error('libdrm_nouveau requires atomics.') 121 endif 122 with_nouveau = true 123endif 124summary('Nouveau', with_nouveau) 125 126with_vmwgfx = false 127_vmwgfx = get_option('vmwgfx') 128if _vmwgfx != 'false' 129 with_vmwgfx = true 130endif 131summary('vmwgfx', with_vmwgfx) 132 133with_omap = false 134_omap = get_option('omap') 135if _omap == 'true' 136 if not with_atomics 137 error('libdrm_omap requires atomics.') 138 endif 139 with_omap = true 140endif 141summary('OMAP', with_omap) 142 143with_freedreno = false 144_freedreno = get_option('freedreno') 145if _freedreno != 'false' 146 if _freedreno == 'true' and not with_atomics 147 error('libdrm_freedreno requires atomics.') 148 else 149 with_freedreno = _freedreno == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family()) 150 endif 151endif 152summary('Freedreno', with_freedreno) 153summary('Freedreon-kgsl', with_freedreno_kgsl) 154 155with_tegra = false 156_tegra = get_option('tegra') 157if _tegra == 'true' 158 if not with_atomics 159 error('libdrm_tegra requires atomics.') 160 endif 161 with_tegra = true 162endif 163summary('Tegra', with_tegra) 164 165with_etnaviv = false 166_etnaviv = get_option('etnaviv') 167if _etnaviv == 'true' 168 if not with_atomics 169 error('libdrm_etnaviv requires atomics.') 170 endif 171 with_etnaviv = true 172endif 173summary('Etnaviv', with_etnaviv) 174 175with_exynos = get_option('exynos') == 'true' 176summary('EXYNOS', with_exynos) 177 178with_vc4 = false 179_vc4 = get_option('vc4') 180if _vc4 != 'false' 181 with_vc4 = _vc4 == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family()) 182endif 183summary('VC4', with_vc4) 184 185# XXX: Apparently only freebsd and dragonfly bsd actually need this (and 186# gnu/kfreebsd), not openbsd and netbsd 187with_libkms = false 188_libkms = get_option('libkms') 189if _libkms != 'false' 190 with_libkms = _libkms == 'true' or (['linux', 'freebsd', 'dragonfly'].contains(host_machine.system()) and not android) 191endif 192summary('libkms', with_libkms) 193 194# Among others FreeBSD does not have a separate dl library. 195if not cc.has_function('dlsym') 196 dep_dl = cc.find_library('dl', required : with_nouveau) 197else 198 dep_dl = [] 199endif 200# clock_gettime might require -rt, or it might not. find out 201if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>') 202 # XXX: untested 203 dep_rt = cc.find_library('rt') 204else 205 dep_rt = [] 206endif 207dep_m = cc.find_library('m', required : false) 208 209# The header is not required on Linux, and is in fact deprecated in glibc 2.30+ 210if ['linux'].contains(host_machine.system()) 211 config.set10('HAVE_SYS_SYSCTL_H', false) 212else 213 # From Niclas Zeising: 214 # FreeBSD requires sys/types.h for sys/sysctl.h, so add it as part of 215 # the includes when checking for headers. 216 config.set10('HAVE_SYS_SYSCTL_H', 217 cc.compiles('#include <sys/types.h>\n#include <sys/sysctl.h>', name : 'sys/sysctl.h works')) 218endif 219 220foreach header : ['sys/select.h', 'alloca.h'] 221 config.set10('HAVE_' + header.underscorify().to_upper(), cc.check_header(header)) 222endforeach 223 224if (cc.has_header_symbol('sys/sysmacros.h', 'major') and 225 cc.has_header_symbol('sys/sysmacros.h', 'minor') and 226 cc.has_header_symbol('sys/sysmacros.h', 'makedev')) 227 config.set10('MAJOR_IN_SYSMACROS', true) 228endif 229if (cc.has_header_symbol('sys/mkdev.h', 'major') and 230 cc.has_header_symbol('sys/mkdev.h', 'minor') and 231 cc.has_header_symbol('sys/mkdev.h', 'makedev')) 232 config.set10('MAJOR_IN_MKDEV', true) 233endif 234config.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream')) 235 236libdrm_c_args = cc.get_supported_arguments([ 237 '-Wsign-compare', '-Werror=undef', '-Werror=implicit-function-declaration', 238 '-Wpointer-arith', '-Wwrite-strings', '-Wstrict-prototypes', 239 '-Wmissing-prototypes', '-Wmissing-declarations', '-Wnested-externs', 240 '-Wpacked', '-Wswitch-enum', '-Wmissing-format-attribute', 241 '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow', 242 '-Wdeclaration-after-statement', '-Wold-style-definition', 243 '-Wno-unused-parameter', '-Wno-attributes', '-Wno-long-long', 244 '-Wno-missing-field-initializers']) 245 246dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel) 247dep_cunit = dependency('cunit', version : '>= 2.1', required : false) 248_cairo_tests = get_option('cairo-tests') 249if _cairo_tests != 'false' 250 dep_cairo = dependency('cairo', required : _cairo_tests == 'true') 251 with_cairo_tests = dep_cairo.found() 252else 253 dep_cairo = [] 254 with_cairo_tests = false 255endif 256_valgrind = get_option('valgrind') 257if _valgrind != 'false' 258 if with_freedreno 259 dep_valgrind = dependency('valgrind', required : _valgrind == 'true', version : '>=3.10.0') 260 else 261 dep_valgrind = dependency('valgrind', required : _valgrind == 'true') 262 endif 263 with_valgrind = dep_valgrind.found() 264else 265 dep_valgrind = [] 266 with_valgrind = false 267endif 268 269with_man_pages = get_option('man-pages') 270prog_rst2man = find_program('rst2man', 'rst2man.py', required: with_man_pages == 'true') 271with_man_pages = with_man_pages != 'false' and prog_rst2man.found() 272 273config.set10('HAVE_VISIBILITY', cc.has_function_attribute('visibility:hidden')) 274 275foreach t : [ 276 [with_exynos, 'EXYNOS'], 277 [with_freedreno_kgsl, 'FREEDRENO_KGSL'], 278 [with_intel, 'INTEL'], 279 [with_nouveau, 'NOUVEAU'], 280 [with_radeon, 'RADEON'], 281 [with_vc4, 'VC4'], 282 [with_vmwgfx, 'VMWGFX'], 283 [with_cairo_tests, 'CAIRO'], 284 [with_valgrind, 'VALGRIND'], 285 ] 286 config.set10('HAVE_@0@'.format(t[1]), t[0]) 287endforeach 288if with_freedreno_kgsl and not with_freedreno 289 error('cannot enable freedreno-kgsl without freedreno support') 290endif 291config.set10('_GNU_SOURCE', true) 292config_file = configure_file( 293 configuration : config, 294 output : 'config.h', 295) 296add_project_arguments('-include', '@0@'.format(config_file), language : 'c') 297 298inc_root = include_directories('.') 299inc_drm = include_directories('include/drm') 300 301libdrm_files = [files( 302 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c', 303 'xf86drmMode.c' 304 ), 305 config_file, format_mod_static_table 306] 307 308# Build an unversioned so on android 309if android 310 libdrm_kw = {} 311else 312 libdrm_kw = {'version' : '2.4.0'} 313endif 314 315libdrm = library( 316 'drm', 317 libdrm_files, 318 c_args : libdrm_c_args, 319 dependencies : [dep_valgrind, dep_rt, dep_m], 320 include_directories : inc_drm, 321 install : true, 322 kwargs : libdrm_kw, 323 gnu_symbol_visibility : 'hidden', 324) 325 326test( 327 'core-symbols-check', 328 symbols_check, 329 args : [ 330 '--lib', libdrm, 331 '--symbols-file', files('core-symbols.txt'), 332 '--nm', prog_nm.path(), 333 ], 334) 335 336ext_libdrm = declare_dependency( 337 link_with : libdrm, 338 include_directories : [inc_root, inc_drm], 339) 340 341if meson.version().version_compare('>= 0.54.0') 342 meson.override_dependency('libdrm', ext_libdrm) 343endif 344 345install_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h') 346install_headers( 347 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h', 348 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h', 349 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h', 350 'include/drm/msm_drm.h', 'include/drm/nouveau_drm.h', 351 'include/drm/qxl_drm.h', 'include/drm/r128_drm.h', 352 'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h', 353 'include/drm/savage_drm.h', 'include/drm/sis_drm.h', 354 'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h', 355 'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h', 356 subdir : 'libdrm', 357) 358if with_vmwgfx 359 install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm') 360endif 361 362pkg.generate( 363 libdrm, 364 name : 'libdrm', 365 subdirs : ['.', 'libdrm'], 366 description : 'Userspace interface to kernel DRM services', 367) 368 369if with_libkms 370 subdir('libkms') 371endif 372if with_intel 373 subdir('intel') 374endif 375if with_nouveau 376 subdir('nouveau') 377endif 378if with_radeon 379 subdir('radeon') 380endif 381if with_amdgpu 382 subdir('amdgpu') 383endif 384if with_omap 385 subdir('omap') 386endif 387if with_exynos 388 subdir('exynos') 389endif 390if with_freedreno 391 subdir('freedreno') 392endif 393if with_tegra 394 subdir('tegra') 395endif 396if with_vc4 397 subdir('vc4') 398endif 399if with_etnaviv 400 subdir('etnaviv') 401endif 402if with_man_pages 403 subdir('man') 404endif 405subdir('data') 406subdir('tests') 407