Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 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 | project( |
| 22 | 'libdrm', |
| 23 | ['c'], |
Rob Clark | 85ae22a | 2018-03-05 15:55:51 -0500 | [diff] [blame] | 24 | version : '2.4.91', |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 25 | license : 'MIT', |
Dylan Baker | 5df9367 | 2018-01-12 11:53:39 -0800 | [diff] [blame] | 26 | meson_version : '>= 0.43', |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 27 | default_options : ['buildtype=debugoptimized', 'c_std=gnu99'], |
| 28 | ) |
| 29 | |
| 30 | pkg = import('pkgconfig') |
| 31 | |
| 32 | with_udev = get_option('udev') |
| 33 | with_freedreno_kgsl = get_option('freedreno-kgsl') |
| 34 | with_install_tests = get_option('install-test-programs') |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 35 | |
| 36 | config = configuration_data() |
| 37 | |
Jonathan Gray | 9eb6c8a | 2018-02-20 17:09:14 +1100 | [diff] [blame] | 38 | if ['freebsd', 'dragonfly', 'netbsd'].contains(host_machine.system()) |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 39 | dep_pthread_stubs = dependency('pthread-stubs', version : '>= 0.4') |
| 40 | else |
| 41 | dep_pthread_stubs = [] |
| 42 | endif |
| 43 | dep_threads = dependency('threads') |
| 44 | |
| 45 | cc = meson.get_compiler('c') |
| 46 | |
| 47 | # Check for atomics |
| 48 | intel_atomics = false |
| 49 | lib_atomics = false |
| 50 | |
Eric Engestrom | 5236de6 | 2018-02-07 14:20:52 +0000 | [diff] [blame] | 51 | dep_atomic_ops = dependency('atomic_ops', required : false) |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 52 | if cc.compiles(''' |
| 53 | int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); } |
| 54 | int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); } |
| 55 | ''', |
| 56 | name : 'Intel Atomics') |
| 57 | intel_atomics = true |
| 58 | with_atomics = true |
Eric Engestrom | 5236de6 | 2018-02-07 14:20:52 +0000 | [diff] [blame] | 59 | dep_atomic_ops = [] |
| 60 | elif dep_atomic_ops.found() |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 61 | lib_atomics = true |
| 62 | with_atomics = true |
| 63 | elif cc.has_function('atomic_cas_uint') |
| 64 | with_atomics = true |
| 65 | else |
| 66 | with_atomics = false |
| 67 | endif |
| 68 | |
| 69 | config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics) |
| 70 | config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics) |
| 71 | |
| 72 | with_intel = false |
| 73 | _intel = get_option('intel') |
| 74 | if _intel != 'false' |
| 75 | if _intel == 'true' and not with_atomics |
| 76 | error('libdrm_intel requires atomics.') |
| 77 | else |
| 78 | with_intel = _intel == 'true' or host_machine.cpu_family().startswith('x86') |
| 79 | endif |
| 80 | endif |
| 81 | |
| 82 | with_radeon = false |
| 83 | _radeon = get_option('radeon') |
| 84 | if _radeon != 'false' |
| 85 | if _radeon == 'true' and not with_atomics |
| 86 | error('libdrm_radeon requires atomics.') |
| 87 | endif |
| 88 | with_radeon = true |
| 89 | endif |
| 90 | |
| 91 | with_amdgpu = false |
| 92 | _amdgpu = get_option('amdgpu') |
| 93 | if _amdgpu != 'false' |
| 94 | if _amdgpu == 'true' and not with_atomics |
| 95 | error('libdrm_amdgpu requires atomics.') |
| 96 | endif |
| 97 | with_amdgpu = true |
| 98 | endif |
| 99 | |
| 100 | with_nouveau = false |
| 101 | _nouveau = get_option('nouveau') |
| 102 | if _nouveau != 'false' |
| 103 | if _nouveau == 'true' and not with_atomics |
| 104 | error('libdrm_nouveau requires atomics.') |
| 105 | endif |
| 106 | with_nouveau = true |
| 107 | endif |
| 108 | |
| 109 | with_vmwgfx = false |
| 110 | _vmwgfx = get_option('vmwgfx') |
| 111 | if _vmwgfx != 'false' |
| 112 | with_vmwgfx = true |
| 113 | endif |
| 114 | |
| 115 | with_omap = false |
| 116 | _omap = get_option('omap') |
| 117 | if _omap == 'true' |
| 118 | if not with_atomics |
| 119 | error('libdrm_omap requires atomics.') |
| 120 | endif |
| 121 | with_omap = true |
| 122 | endif |
| 123 | |
| 124 | with_freedreno = false |
| 125 | _freedreno = get_option('freedreno') |
| 126 | if _freedreno != 'false' |
| 127 | if _freedreno == 'true' and not with_atomics |
| 128 | error('libdrm_freedreno requires atomics.') |
| 129 | else |
| 130 | with_freedreno = _freedreno == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family()) |
| 131 | endif |
| 132 | endif |
| 133 | |
| 134 | with_tegra = false |
| 135 | _tegra = get_option('tegra') |
| 136 | if _tegra == 'true' |
| 137 | if not with_atomics |
| 138 | error('libdrm_tegra requires atomics.') |
| 139 | endif |
| 140 | with_tegra = true |
| 141 | endif |
| 142 | |
| 143 | with_etnaviv = false |
| 144 | _etnaviv = get_option('etnaviv') |
| 145 | if _etnaviv == 'true' |
| 146 | if not with_atomics |
| 147 | error('libdrm_etnaviv requires atomics.') |
| 148 | endif |
| 149 | with_etnaviv = true |
| 150 | endif |
| 151 | |
| 152 | with_exynos = get_option('exynos') == 'true' |
| 153 | |
| 154 | with_vc4 = false |
| 155 | _vc4 = get_option('vc4') |
| 156 | if _vc4 != 'false' |
| 157 | with_vc4 = _vc4 == 'true' or ['arm', 'aarch64'].contains(host_machine.cpu_family()) |
| 158 | endif |
| 159 | |
| 160 | # XXX: Aparently only freebsd and dragonfly bsd actually need this (and |
| 161 | # gnu/kfreebsd), not openbsd and netbsd |
| 162 | with_libkms = false |
| 163 | _libkms = get_option('libkms') |
| 164 | if _libkms != 'false' |
| 165 | with_libkms = _libkms == 'true' or ['linux', 'freebsd', 'dragonfly'].contains(host_machine.system()) |
| 166 | endif |
| 167 | |
| 168 | if with_udev |
| 169 | dep_udev = dependency('udev') |
| 170 | config.set10('UDEV', true) |
| 171 | else |
| 172 | dep_udev = [] |
| 173 | endif |
| 174 | |
| 175 | # Among others FreeBSD does not have a separate dl library. |
| 176 | if not cc.has_function('dlsym') |
| 177 | dep_dl = cc.find_library('dl', required : with_nouveau) |
| 178 | else |
| 179 | dep_dl = [] |
| 180 | endif |
| 181 | # clock_gettime might require -rt, or it might not. find out |
| 182 | if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>') |
| 183 | # XXX: untested |
| 184 | dep_rt = cc.find_library('rt') |
| 185 | else |
| 186 | dep_rt = [] |
| 187 | endif |
| 188 | dep_m = cc.find_library('m', required : false) |
Dylan Baker | 0663dbd | 2018-03-12 10:10:51 -0700 | [diff] [blame^] | 189 | if cc.compiles('#include <sys/sysctl.h>', name : 'sys/sysctl.h works') |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 190 | config.set10('HAVE_SYS_SYSCTL_H', true) |
| 191 | endif |
Dylan Baker | 0663dbd | 2018-03-12 10:10:51 -0700 | [diff] [blame^] | 192 | if cc.compiles('#include <sys/select.h>', name : 'sys/select.h works') |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 193 | config.set10('HAVE_SYS_SELECT_H', true) |
| 194 | endif |
| 195 | if cc.has_header_symbol('sys/sysmacros.h', 'major') |
| 196 | config.set10('MAJOR_IN_SYSMACROS', true) |
| 197 | elif cc.has_header_symbol('sys/mkdev.h', 'major') |
| 198 | config.set10('MAJOR_IN_MKDEV', true) |
| 199 | endif |
| 200 | if cc.has_function('open_memstream') |
| 201 | config.set10('HAVE_OPEN_MEMSTREAM', true) |
| 202 | endif |
| 203 | |
| 204 | warn_c_args = [] |
Eric Engestrom | ba17673 | 2018-01-26 11:18:03 +0000 | [diff] [blame] | 205 | foreach a : ['-Wall', '-Wextra', '-Wsign-compare', '-Werror=undef', |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 206 | '-Werror-implicit-function-declaration', '-Wpointer-arith', |
| 207 | '-Wwrite-strings', '-Wstrict-prototypes', '-Wmissing-prototypes', |
| 208 | '-Wmissing-declarations', '-Wnested-externs', '-Wpacked', |
Eric Engestrom | 8177d73 | 2018-01-26 11:18:30 +0000 | [diff] [blame] | 209 | '-Wswitch-enum', '-Wmissing-format-attribute', |
| 210 | '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow', |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 211 | '-Wdeclaration-after-statement', '-Wold-style-definition'] |
| 212 | if cc.has_argument(a) |
| 213 | warn_c_args += a |
| 214 | endif |
| 215 | endforeach |
| 216 | # GCC will never error for -Wno-*, so check for -W* then add -Wno-* to the list |
| 217 | # of options |
Eric Engestrom | 8177d73 | 2018-01-26 11:18:30 +0000 | [diff] [blame] | 218 | foreach a : ['unused-parameter', 'attributes', 'long-long', |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 219 | 'missing-field-initializers'] |
| 220 | if cc.has_argument('-W@0@'.format(a)) |
| 221 | warn_c_args += '-Wno-@0@'.format(a) |
| 222 | endif |
| 223 | endforeach |
| 224 | |
| 225 | |
| 226 | dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : with_intel) |
| 227 | dep_cunit = dependency('cunit', version : '>= 2.1', required : false) |
Igor Gnatenko | 9411f8e | 2018-02-19 13:55:27 +0100 | [diff] [blame] | 228 | _cairo_tests = get_option('cairo-tests') |
| 229 | if _cairo_tests != 'false' |
| 230 | dep_cairo = dependency('cairo', required : _cairo_tests == 'true') |
| 231 | with_cairo_tests = dep_cairo.found() |
| 232 | else |
| 233 | dep_cairo = [] |
| 234 | with_cairo_tests = false |
| 235 | endif |
| 236 | _valgrind = get_option('valgrind') |
| 237 | if _valgrind != 'false' |
| 238 | dep_valgrind = dependency('valgrind', required : _valgrind == 'true') |
| 239 | with_valgrind = dep_valgrind.found() |
| 240 | else |
| 241 | dep_valgrind = [] |
| 242 | with_valgrind = false |
| 243 | endif |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 244 | |
| 245 | with_man_pages = get_option('man-pages') |
| 246 | prog_xslt = find_program('xsltproc', required : with_man_pages == 'true') |
| 247 | prog_sed = find_program('sed', required : with_man_pages == 'true') |
| 248 | manpage_style = 'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl' |
| 249 | if prog_xslt.found() |
| 250 | if run_command(prog_xslt, '--nonet', manpage_style).returncode() != 0 |
| 251 | if with_man_pages == 'true' |
| 252 | error('Manpage style sheet cannot be found') |
| 253 | endif |
| 254 | with_man_pages = 'false' |
| 255 | endif |
| 256 | endif |
| 257 | with_man_pages = with_man_pages != 'false' and prog_xslt.found() and prog_sed.found() |
| 258 | |
| 259 | # Used for tets |
| 260 | prog_bash = find_program('bash') |
| 261 | |
| 262 | if cc.compiles('''int foo_hidden(void) __attribute__((visibility(("hidden"))));''', |
| 263 | name : 'compiler supports __attribute__(("hidden"))') |
| 264 | config.set10('HAVE_VISIBILITY', true) |
| 265 | endif |
| 266 | |
Eric Engestrom | 5457e00 | 2018-01-26 16:23:01 +0000 | [diff] [blame] | 267 | foreach t : [ |
Eric Engestrom | 2cd9105 | 2018-01-26 16:17:53 +0000 | [diff] [blame] | 268 | [with_exynos, 'EXYNOS'], |
Eric Engestrom | ec53f48 | 2018-01-26 15:19:03 +0000 | [diff] [blame] | 269 | [with_freedreno_kgsl, 'FREEDRENO_KGSL'], |
Eric Engestrom | 5457e00 | 2018-01-26 16:23:01 +0000 | [diff] [blame] | 270 | [with_intel, 'INTEL'], |
| 271 | [with_nouveau, 'NOUVEAU'], |
| 272 | [with_radeon, 'RADEON'], |
| 273 | [with_vc4, 'VC4'], |
| 274 | [with_vmwgfx, 'VMWGFX'], |
Igor Gnatenko | 9411f8e | 2018-02-19 13:55:27 +0100 | [diff] [blame] | 275 | [with_cairo_tests, 'CAIRO'], |
| 276 | [with_valgrind, 'VALGRIND'], |
Eric Engestrom | 5457e00 | 2018-01-26 16:23:01 +0000 | [diff] [blame] | 277 | ] |
Eric Engestrom | ee47329 | 2018-01-26 16:21:30 +0000 | [diff] [blame] | 278 | config.set10('HAVE_@0@'.format(t[1]), t[0]) |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 279 | endforeach |
Eric Engestrom | ec53f48 | 2018-01-26 15:19:03 +0000 | [diff] [blame] | 280 | if with_freedreno_kgsl and not with_freedreno |
| 281 | error('cannot enable freedreno-kgsl without freedreno support') |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 282 | endif |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 283 | config.set10('_GNU_SOURCE', true) |
| 284 | config_file = configure_file( |
| 285 | configuration : config, |
| 286 | output : 'config.h', |
| 287 | ) |
| 288 | add_project_arguments('-DHAVE_CONFIG_H', language : 'c') |
| 289 | |
| 290 | inc_root = include_directories('.') |
| 291 | inc_drm = include_directories('include/drm') |
| 292 | |
| 293 | libdrm = shared_library( |
| 294 | 'drm', |
| 295 | [files( |
| 296 | 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c', |
| 297 | 'xf86drmMode.c' |
| 298 | ), |
| 299 | config_file, |
| 300 | ], |
| 301 | c_args : warn_c_args, |
| 302 | dependencies : [dep_udev, dep_valgrind, dep_rt, dep_m], |
| 303 | include_directories : inc_drm, |
| 304 | version : '2.4.0', |
| 305 | install : true, |
| 306 | ) |
| 307 | |
| 308 | ext_libdrm = declare_dependency( |
| 309 | link_with : libdrm, |
Dylan Baker | deb5978 | 2018-02-07 15:35:24 -0800 | [diff] [blame] | 310 | include_directories : [inc_root, inc_drm], |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 311 | ) |
| 312 | |
| 313 | install_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h') |
| 314 | install_headers( |
| 315 | 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h', |
| 316 | 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h', |
| 317 | 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h', |
| 318 | 'include/drm/nouveau_drm.h', 'include/drm/qxl_drm.h', |
| 319 | 'include/drm/r128_drm.h', 'include/drm/radeon_drm.h', |
| 320 | 'include/drm/amdgpu_drm.h', 'include/drm/savage_drm.h', |
| 321 | 'include/drm/sis_drm.h', '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 | ) |
| 325 | if with_vmwgfx |
| 326 | install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm') |
| 327 | endif |
| 328 | |
| 329 | pkg.generate( |
| 330 | name : 'libdrm', |
| 331 | libraries : libdrm, |
| 332 | subdirs : ['.', 'libdrm'], |
| 333 | version : meson.project_version(), |
| 334 | description : 'Userspace interface to kernel DRM services', |
| 335 | ) |
Eric Engestrom | 8177d73 | 2018-01-26 11:18:30 +0000 | [diff] [blame] | 336 | |
Heiko Becker | 4f08bfe | 2018-02-19 15:13:15 +0000 | [diff] [blame] | 337 | env_test = environment() |
| 338 | env_test.set('NM', find_program('nm').path()) |
| 339 | |
Dylan Baker | 5f7deb5 | 2017-09-13 11:46:13 -0700 | [diff] [blame] | 340 | if with_libkms |
| 341 | subdir('libkms') |
| 342 | endif |
| 343 | if with_intel |
| 344 | subdir('intel') |
| 345 | endif |
| 346 | if with_nouveau |
| 347 | subdir('nouveau') |
| 348 | endif |
| 349 | if with_radeon |
| 350 | subdir('radeon') |
| 351 | endif |
| 352 | if with_amdgpu |
| 353 | subdir('amdgpu') |
| 354 | endif |
| 355 | if with_omap |
| 356 | subdir('omap') |
| 357 | endif |
| 358 | if with_exynos |
| 359 | subdir('exynos') |
| 360 | endif |
| 361 | if with_freedreno |
| 362 | subdir('freedreno') |
| 363 | endif |
| 364 | if with_tegra |
| 365 | subdir('tegra') |
| 366 | endif |
| 367 | if with_vc4 |
| 368 | subdir('vc4') |
| 369 | endif |
| 370 | if with_etnaviv |
| 371 | subdir('etnaviv') |
| 372 | endif |
| 373 | if with_man_pages |
| 374 | subdir('man') |
| 375 | endif |
| 376 | subdir('data') |
| 377 | subdir('tests') |
Eric Engestrom | 7a58c21 | 2018-02-26 15:42:18 +0000 | [diff] [blame] | 378 | |
| 379 | message('') |
| 380 | message('@0@ will be compiled with:'.format(meson.project_name())) |
| 381 | message('') |
| 382 | message(' libkms @0@'.format(with_libkms)) |
| 383 | message(' Intel API @0@'.format(with_intel)) |
| 384 | message(' vmwgfx API @0@'.format(with_vmwgfx)) |
| 385 | message(' Radeon API @0@'.format(with_radeon)) |
| 386 | message(' AMDGPU API @0@'.format(with_amdgpu)) |
| 387 | message(' Nouveau API @0@'.format(with_nouveau)) |
| 388 | message(' OMAP API @0@'.format(with_omap)) |
| 389 | message(' EXYNOS API @0@'.format(with_exynos)) |
| 390 | message(' Freedreno API @0@ (kgsl: @1@)'.format(with_freedreno, with_freedreno_kgsl)) |
| 391 | message(' Tegra API @0@'.format(with_tegra)) |
| 392 | message(' VC4 API @0@'.format(with_vc4)) |
| 393 | message(' Etnaviv API @0@'.format(with_etnaviv)) |
| 394 | message('') |