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 21# The versioning should always stay at 2.4.x. If bumping away from this, 22# you must ensure that all users of patch_ver are changed such that DSO versions 23# continuously increment (e.g. blindly bumping from 2.4.122 to 2.5.0 would 24# roll the libdrm DSO versioning from libdrm.so.2.122.0 back to libdrm.so.2.0.0 25# which would be bad) 26project( 27 'libdrm', 28 ['c'], 29 version : '2.4.124', 30 license : 'MIT', 31 meson_version : '>= 0.59', 32 default_options : ['buildtype=debugoptimized', 'c_std=c11'], 33) 34 35patch_ver = meson.project_version().split('.')[2] 36 37if ['windows', 'darwin'].contains(host_machine.system()) 38 error('unsupported OS: @0@'.format(host_machine.system())) 39endif 40 41pkg = import('pkgconfig') 42 43config = configuration_data() 44 45config.set10('UDEV', get_option('udev')) 46with_freedreno_kgsl = get_option('freedreno-kgsl') 47with_install_tests = get_option('install-test-programs') 48with_tests = get_option('tests') 49 50dep_threads = dependency('threads') 51 52cc = meson.get_compiler('c') 53 54android = cc.compiles('''int func() { return __ANDROID__; }''') 55 56# Solaris / Illumos 57if host_machine.system() == 'sunos' 58 add_global_arguments('-D__EXTENSIONS__', language : 'c') 59 add_global_arguments('-D_POSIX_C_SOURCE=3', language : 'c') 60endif 61 62symbols_check = find_program('symbols-check.py') 63prog_nm = find_program('nm') 64 65# Check for atomics 66intel_atomics = false 67lib_atomics = false 68 69python3 = import('python').find_installation() 70format_mod_static_table = custom_target( 71 'format_mod_static_table', 72 output : 'generated_static_table_fourcc.h', 73 input : 'include/drm/drm_fourcc.h', 74 command : [python3, files('gen_table_fourcc.py'), '@INPUT@', '@OUTPUT@']) 75 76dep_atomic_ops = dependency('atomic_ops', required : false) 77if cc.links(''' 78 int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); } 79 int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); } 80 int main() { } 81 ''', 82 name : 'Intel Atomics') 83 intel_atomics = true 84 with_atomics = true 85 dep_atomic_ops = [] 86elif dep_atomic_ops.found() 87 lib_atomics = true 88 with_atomics = true 89elif cc.has_function('atomic_cas_uint') 90 with_atomics = true 91else 92 with_atomics = false 93endif 94 95config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics) 96config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics) 97 98dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : get_option('intel')) 99 100with_intel = get_option('intel') \ 101 .require(with_atomics, error_message : 'libdrm_intel requires atomics') \ 102 .require(dep_pciaccess.found(), error_message : 'libdrm_intel requires libpciaccess') \ 103 .disable_auto_if(not host_machine.cpu_family().startswith('x86')) \ 104 .allowed() 105summary('Intel', with_intel) 106 107with_radeon = get_option('radeon') \ 108 .require(with_atomics, error_message : 'libdrm_radeon requires atomics') \ 109 .allowed() 110summary('Radeon', with_radeon) 111 112with_amdgpu = get_option('amdgpu') \ 113 .require(with_atomics, error_message : 'libdrm_amdgpu requires atomics') \ 114 .allowed() 115summary('AMDGPU', with_amdgpu) 116 117with_nouveau = get_option('nouveau') \ 118 .require(with_atomics, error_message : 'libdrm_nouveau requires atomics') \ 119 .allowed() 120summary('Nouveau', with_nouveau) 121 122with_vmwgfx = get_option('vmwgfx').allowed() 123summary('vmwgfx', with_vmwgfx) 124 125with_omap = get_option('omap') \ 126 .require(with_atomics, error_message : 'libdrm_omap requires atomics') \ 127 .enabled() 128summary('OMAP', with_omap) 129 130with_freedreno = get_option('freedreno') \ 131 .require(with_atomics, error_message : 'libdrm_freedreno requires atomics') \ 132 .disable_auto_if(not ['arm', 'aarch64'].contains(host_machine.cpu_family())) \ 133 .allowed() 134summary('Freedreno', with_freedreno) 135summary('Freedreon-kgsl', with_freedreno_kgsl) 136 137with_tegra = get_option('tegra') \ 138 .require(with_atomics, error_message : 'libdrm_tegra requires atomics') \ 139 .disable_auto_if(not ['arm', 'aarch64'].contains(host_machine.cpu_family())) \ 140 .enabled() 141summary('Tegra', with_tegra) 142 143with_etnaviv = get_option('etnaviv') \ 144 .require(with_atomics, error_message : 'libdrm_etnaviv requires atomics') \ 145 .disable_auto_if(not ['arm', 'aarch64', 'arc', 'mips', 'mips64', 'loongarch64'].contains(host_machine.cpu_family())) \ 146 .allowed() 147summary('Etnaviv', with_etnaviv) 148 149with_exynos = get_option('exynos').enabled() 150summary('EXYNOS', with_exynos) 151 152with_vc4 = get_option('vc4') \ 153 .disable_auto_if(not ['arm', 'aarch64'].contains(host_machine.cpu_family())) \ 154 .allowed() 155summary('VC4', with_vc4) 156 157# XXX: Apparently only freebsd and dragonfly bsd actually need this (and 158# gnu/kfreebsd), not openbsd and netbsd 159with_libkms = false 160_libkms = get_option('libkms') 161if _libkms != 'false' 162 with_libkms = _libkms == 'true' or (['linux', 'freebsd', 'dragonfly'].contains(host_machine.system()) and not android) 163endif 164summary('libkms', with_libkms) 165 166# Among others FreeBSD does not have a separate dl library. 167if not cc.has_function('dlsym') 168 dep_dl = cc.find_library('dl', required : with_nouveau) 169else 170 dep_dl = [] 171endif 172# clock_gettime might require -rt, or it might not. find out 173if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>') 174 # XXX: untested 175 dep_rt = cc.find_library('rt') 176else 177 dep_rt = [] 178endif 179 180# The header is not required on Linux, and is in fact deprecated in glibc 2.30+ 181if host_machine.system() == 'linux' 182 config.set10('HAVE_SYS_SYSCTL_H', false) 183else 184 # From Niclas Zeising: 185 # FreeBSD requires sys/types.h for sys/sysctl.h, so add it as part of 186 # the includes when checking for headers. 187 config.set10('HAVE_SYS_SYSCTL_H', 188 cc.compiles('#include <sys/types.h>\n#include <sys/sysctl.h>', name : 'sys/sysctl.h works')) 189endif 190 191foreach header : ['sys/select.h', 'alloca.h'] 192 config.set10('HAVE_' + header.underscorify().to_upper(), cc.check_header(header)) 193endforeach 194 195if (cc.has_header_symbol('sys/sysmacros.h', 'major') and 196 cc.has_header_symbol('sys/sysmacros.h', 'minor') and 197 cc.has_header_symbol('sys/sysmacros.h', 'makedev')) 198 config.set10('MAJOR_IN_SYSMACROS', true) 199endif 200if (cc.has_header_symbol('sys/mkdev.h', 'major') and 201 cc.has_header_symbol('sys/mkdev.h', 'minor') and 202 cc.has_header_symbol('sys/mkdev.h', 'makedev')) 203 config.set10('MAJOR_IN_MKDEV', true) 204endif 205config.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream')) 206 207libdrm_c_args = cc.get_supported_arguments([ 208 '-Wsign-compare', '-Werror=undef', '-Werror=implicit-function-declaration', 209 '-Wpointer-arith', '-Wwrite-strings', '-Wstrict-prototypes', 210 '-Wmissing-prototypes', '-Wmissing-declarations', '-Wnested-externs', 211 '-Wpacked', '-Wswitch-enum', '-Wmissing-format-attribute', 212 '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow', 213 '-Wdeclaration-after-statement', '-Wold-style-definition', 214 '-Wno-unused-parameter', '-Wno-attributes', '-Wno-long-long', 215 '-Wno-missing-field-initializers']) 216 217dep_cunit = dependency('cunit', version : '>= 2.1', required : false) 218dep_cairo = dependency('cairo', required : get_option('cairo-tests')) 219with_cairo_tests = dep_cairo.found() 220 221valgrind_version = [] 222if with_freedreno 223 valgrind_version = '>=3.10.0' 224endif 225dep_valgrind = dependency('valgrind', required : get_option('valgrind'), version : valgrind_version) 226with_valgrind = dep_valgrind.found() 227 228prog_rst2man = find_program('rst2man', 'rst2man.py', required: get_option('man-pages')) 229with_man_pages = prog_rst2man.found() 230 231config.set10('HAVE_VISIBILITY', cc.has_function_attribute('visibility:hidden')) 232 233foreach t : [ 234 [with_exynos, 'EXYNOS'], 235 [with_freedreno_kgsl, 'FREEDRENO_KGSL'], 236 [with_intel, 'INTEL'], 237 [with_nouveau, 'NOUVEAU'], 238 [with_radeon, 'RADEON'], 239 [with_vc4, 'VC4'], 240 [with_vmwgfx, 'VMWGFX'], 241 [with_cairo_tests, 'CAIRO'], 242 [with_valgrind, 'VALGRIND'], 243 ] 244 config.set10('HAVE_@0@'.format(t[1]), t[0]) 245endforeach 246if with_freedreno_kgsl and not with_freedreno 247 error('cannot enable freedreno-kgsl without freedreno support') 248endif 249config.set10('_GNU_SOURCE', true) 250 251if target_machine.endian() == 'big' 252 config.set('HAVE_BIG_ENDIAN', 1) 253endif 254 255if android 256 config.set('BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD', 1) 257endif 258 259config_file = configure_file( 260 configuration : config, 261 output : 'config.h', 262) 263add_project_arguments('-include', meson.current_build_dir() / 'config.h', language : 'c') 264 265inc_root = include_directories('.') 266inc_drm = include_directories('include/drm') 267 268libdrm_files = [files( 269 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c', 270 'xf86drmMode.c' 271 ), 272 config_file, format_mod_static_table 273] 274 275# Build an unversioned so on android 276if android 277 libdrm_kw = {} 278else 279 libdrm_kw = { 'version' : '2.@[email protected]'.format(patch_ver) } 280endif 281 282libdrm = library( 283 'drm', 284 libdrm_files, 285 c_args : libdrm_c_args, 286 dependencies : [dep_valgrind, dep_rt], 287 include_directories : inc_drm, 288 install : true, 289 kwargs : libdrm_kw, 290 gnu_symbol_visibility : 'hidden', 291) 292 293test( 294 'core-symbols-check', 295 symbols_check, 296 args : [ 297 '--lib', libdrm, 298 '--symbols-file', files('core-symbols.txt'), 299 '--nm', prog_nm.full_path(), 300 ], 301) 302 303ext_libdrm = declare_dependency( 304 link_with : libdrm, 305 include_directories : [inc_root, inc_drm], 306) 307 308if meson.version().version_compare('>= 0.54.0') 309 meson.override_dependency('libdrm', ext_libdrm) 310endif 311 312install_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h') 313install_headers( 314 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h', 315 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h', 316 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h', 317 'include/drm/msm_drm.h', 'include/drm/nouveau_drm.h', 318 'include/drm/qxl_drm.h', 'include/drm/r128_drm.h', 319 'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h', 320 'include/drm/savage_drm.h', 'include/drm/sis_drm.h', 321 'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h', 322 'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h', 323 subdir : 'libdrm', 324) 325if with_vmwgfx 326 install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm') 327endif 328 329pkg.generate( 330 libdrm, 331 name : 'libdrm', 332 subdirs : ['.', 'libdrm'], 333 description : 'Userspace interface to kernel DRM services', 334) 335 336if with_libkms 337 subdir('libkms') 338endif 339if with_intel 340 subdir('intel') 341endif 342if with_nouveau 343 subdir('nouveau') 344endif 345if with_radeon 346 subdir('radeon') 347endif 348if with_amdgpu 349 subdir('amdgpu') 350endif 351if with_omap 352 subdir('omap') 353endif 354if with_exynos 355 subdir('exynos') 356endif 357if with_freedreno 358 subdir('freedreno') 359endif 360if with_tegra 361 subdir('tegra') 362endif 363if with_vc4 364 subdir('vc4') 365endif 366if with_etnaviv 367 subdir('etnaviv') 368endif 369if with_man_pages 370 subdir('man') 371endif 372subdir('data') 373if with_tests 374 subdir('tests') 375endif 376