meson: Don't confuse the install and search paths for dri drivers
[mesa.git] / meson.build
1 # Copyright © 2017 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 'mesa',
23 ['c', 'cpp'],
24 version : run_command(
25 [find_program('python', 'python2', 'python3'), 'bin/meson_get_version.py']
26 ).stdout(),
27 license : 'MIT',
28 meson_version : '>= 0.42',
29 default_options : ['buildtype=debugoptimized', 'c_std=c99', 'cpp_std=c++11']
30 )
31
32 # Arguments for the preprocessor, put these in a separate array from the C and
33 # C++ (cpp in meson terminology) arguments since they need to be added to the
34 # default arguments for both C and C++.
35 pre_args = [
36 '-D__STDC_CONSTANT_MACROS',
37 '-D__STDC_FORMAT_MACROS',
38 '-D__STDC_LIMIT_MACROS',
39 '-DVERSION="@0@"'.format(meson.project_version()),
40 '-DPACKAGE_VERSION=VERSION',
41 '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
42 ]
43
44 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
45 with_tests = get_option('build-tests')
46 with_valgrind = get_option('valgrind')
47 with_libunwind = get_option('libunwind')
48 with_asm = get_option('asm')
49 with_osmesa = get_option('osmesa')
50 with_swr_arches = get_option('swr-arches').split(',')
51 if get_option('texture-float')
52 pre_args += '-DTEXTURE_FLOAT_ENABLED'
53 message('WARNING: Floating-point texture enabled. Please consult docs/patents.txt and your lawyer before building mesa.')
54 endif
55
56 dri_drivers_path = get_option('dri-drivers-path')
57 if dri_drivers_path == ''
58 dri_drivers_path = join_paths(get_option('libdir'), 'dri')
59 endif
60 dri_search_path = get_option('dri-search-path')
61 if dri_search_path == ''
62 dri_search_path = join_paths(get_option('prefix'), dri_drivers_path)
63 endif
64
65 with_gles1 = get_option('gles1')
66 with_gles2 = get_option('gles2')
67 with_opengl = get_option('opengl')
68 with_any_opengl = with_opengl or with_gles1 or with_gles2
69 # Only build shared_glapi if at least one OpenGL API is enabled
70 with_shared_glapi = get_option('shared-glapi') and with_any_opengl
71
72
73 # shared-glapi is required if at least two OpenGL APIs are being built
74 if not with_shared_glapi
75 if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
76 or (with_gles2 and with_opengl))
77 error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
78 endif
79 endif
80
81 # We require OpenGL for OpenGL ES
82 if (with_gles1 or with_gles2) and not with_opengl
83 error('building OpenGL ES without OpenGL is not supported.')
84 endif
85
86 with_dri = false
87 with_dri_i915 = false
88 with_dri_i965 = false
89 with_dri_r100 = false
90 with_dri_r200 = false
91 with_dri_nouveau = false
92 with_dri_swrast = false
93 _drivers = get_option('dri-drivers')
94 if _drivers == 'auto'
95 # TODO: PPC, Sparc
96 if not ['darwin', 'windows'].contains(host_machine.system())
97 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
98 _drivers = 'i915,i965,r100,r200,nouveau'
99 else
100 error('Unknown architecture. Please pass -Ddri-drivers to set driver options. Patches gladly accepted to fix this.')
101 endif
102 else
103 error('Unknown OS. Please pass -Ddri-drivers to set driver options. Patches gladly accepted to fix this.')
104 endif
105 endif
106 if _drivers != ''
107 _split = _drivers.split(',')
108 with_dri_i915 = _split.contains('i915')
109 with_dri_i965 = _split.contains('i965')
110 with_dri_r100 = _split.contains('r100')
111 with_dri_r200 = _split.contains('r200')
112 with_dri_nouveau = _split.contains('nouveau')
113 with_dri_swrast = _split.contains('swrast')
114 with_dri = true
115 endif
116
117 with_gallium = false
118 with_gallium_pl111 = false
119 with_gallium_radeonsi = false
120 with_gallium_r300 = false
121 with_gallium_r600 = false
122 with_gallium_nouveau = false
123 with_gallium_freedreno = false
124 with_gallium_softpipe = false
125 with_gallium_vc4 = false
126 with_gallium_vc5 = false
127 with_gallium_etnaviv = false
128 with_gallium_imx = false
129 with_gallium_i915 = false
130 with_gallium_svga = false
131 with_gallium_virgl = false
132 with_gallium_swr = false
133 _drivers = get_option('gallium-drivers')
134 if _drivers == 'auto'
135 if not ['darwin', 'windows'].contains(host_machine.system())
136 # TODO: PPC, Sparc
137 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
138 _drivers = 'r300,r600,radeonsi,nouveau,virgl,svga,swrast'
139 elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
140 _drivers = 'pl111,vc4,vc5,freedreno,etnaviv,imx,virgl,svga,swrast'
141 else
142 error('Unknown architecture. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.')
143 endif
144 else
145 error('Unknown OS. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.')
146 endif
147 endif
148 if _drivers != ''
149 _split = _drivers.split(',')
150 with_gallium_pl111 = _split.contains('pl111')
151 with_gallium_radeonsi = _split.contains('radeonsi')
152 with_gallium_r300 = _split.contains('r300')
153 with_gallium_r600 = _split.contains('r600')
154 with_gallium_nouveau = _split.contains('nouveau')
155 with_gallium_freedreno = _split.contains('freedreno')
156 with_gallium_softpipe = _split.contains('swrast')
157 with_gallium_vc4 = _split.contains('vc4')
158 with_gallium_vc5 = _split.contains('vc5')
159 with_gallium_etnaviv = _split.contains('etnaviv')
160 with_gallium_imx = _split.contains('imx')
161 with_gallium_i915 = _split.contains('i915')
162 with_gallium_svga = _split.contains('svga')
163 with_gallium_virgl = _split.contains('virgl')
164 with_gallium_swr = _split.contains('swr')
165 with_gallium = true
166 endif
167
168 with_intel_vk = false
169 with_amd_vk = false
170 with_any_vk = false
171 _vulkan_drivers = get_option('vulkan-drivers')
172 if _vulkan_drivers == 'auto'
173 if not ['darwin', 'windows'].contains(host_machine.system())
174 if host_machine.cpu_family().startswith('x86')
175 _vulkan_drivers = 'amd,intel'
176 else
177 error('Unknown architecture. Please pass -Dvulkan-drivers to set driver options. Patches gladly accepted to fix this.')
178 endif
179 else
180 # No vulkan driver supports windows or macOS currently
181 _vulkan_drivers = ''
182 endif
183 endif
184 if _vulkan_drivers != ''
185 _split = _vulkan_drivers.split(',')
186 with_intel_vk = _split.contains('intel')
187 with_amd_vk = _split.contains('amd')
188 with_any_vk = with_amd_vk or with_intel_vk
189 endif
190
191 if with_dri_swrast and (with_gallium_softpipe or with_gallium_swr)
192 error('Only one swrast provider can be built')
193 endif
194 if with_dri_i915 and with_gallium_i915
195 error('Only one i915 provider can be built')
196 endif
197 if with_gallium_imx and not with_gallium_etnaviv
198 error('IMX driver requires etnaviv driver')
199 endif
200 if with_gallium_pl111 and not with_gallium_vc4
201 error('pl111 driver requires vc4 driver')
202 endif
203
204 dep_libdrm_intel = []
205 if with_dri_i915 or with_gallium_i915
206 dep_libdrm_intel = dependency('libdrm_intel', version : '>= 2.4.75')
207 endif
208
209 system_has_kms_drm = ['openbsd', 'netbsd', 'freebsd', 'dragonfly', 'linux'].contains(host_machine.system())
210
211 if host_machine.system() == 'darwin'
212 with_dri_platform = 'apple'
213 elif ['windows', 'cygwin'].contains(host_machine.system())
214 with_dri_platform = 'windows'
215 elif system_has_kms_drm
216 with_dri_platform = 'drm'
217 else
218 # FIXME: haiku doesn't use dri, and xlib doesn't use dri, probably should
219 # assert here that one of those cases has been met.
220 # FIXME: GNU (hurd) ends up here as well, but meson doesn't officially
221 # support Hurd at time of writing (2017/11)
222 # FIXME: illumos ends up here as well
223 with_dri_platform = 'none'
224 endif
225
226 with_platform_android = false
227 with_platform_wayland = false
228 with_platform_x11 = false
229 with_platform_drm = false
230 with_platform_surfaceless = false
231 egl_native_platform = ''
232 _platforms = get_option('platforms')
233 if _platforms == 'auto'
234 if system_has_kms_drm
235 _platforms = 'x11,wayland,drm,surfaceless'
236 else
237 error('Unknown OS, no platforms enabled. Patches gladly accepted to fix this.')
238 endif
239 endif
240 if _platforms != ''
241 _split = _platforms.split(',')
242 with_platform_android = _split.contains('android')
243 with_platform_x11 = _split.contains('x11')
244 with_platform_wayland = _split.contains('wayland')
245 with_platform_drm = _split.contains('drm')
246 with_platform_surfaceless = _split.contains('surfaceless')
247 egl_native_platform = _split[0]
248 endif
249
250 with_glx = get_option('glx')
251 if with_glx == 'auto'
252 if with_dri
253 with_glx = 'dri'
254 elif with_gallium
255 # Even when building just gallium drivers the user probably wants dri
256 with_glx = 'dri'
257 elif with_platform_x11 and with_any_opengl and not with_any_vk
258 # The automatic behavior should not be to turn on xlib based glx when
259 # building only vulkan drivers
260 with_glx = 'xlib'
261 else
262 with_glx = 'disabled'
263 endif
264 endif
265 if with_glx == 'dri'
266 if with_gallium
267 with_dri = true
268 endif
269 endif
270
271 if not (with_dri or with_gallium or with_glx == 'xlib' or with_glx == 'gallium-xlib')
272 with_gles1 = false
273 with_gles2 = false
274 with_opengl = false
275 with_any_opengl = false
276 with_shared_glapi = false
277 endif
278
279 with_gbm = get_option('gbm')
280 if with_gbm == 'auto' and with_dri # TODO: or gallium
281 with_gbm = system_has_kms_drm
282 elif with_gbm == 'true'
283 if not system_has_kms_drm
284 error('GBM only supports DRM/KMS platforms')
285 endif
286 with_gbm = true
287 else
288 with_gbm = false
289 endif
290
291 _egl = get_option('egl')
292 if _egl == 'auto'
293 with_egl = with_dri and with_shared_glapi and egl_native_platform != ''
294 elif _egl == 'true'
295 if not with_dri
296 error('EGL requires dri')
297 elif not with_shared_glapi
298 error('EGL requires shared-glapi')
299 elif egl_native_platform == ''
300 error('No platforms specified, consider -Dplatforms=drm,x11 at least')
301 endif
302 with_egl = true
303 else
304 with_egl = false
305 endif
306
307 if with_egl and not (with_platform_drm or with_platform_surfaceless)
308 if with_gallium_radeonsi
309 error('RadeonSI requires drm or surfaceless platform when using EGL')
310 endif
311 if with_gallium_virgl
312 error('Virgl requires drm or surfaceless platform when using EGL')
313 endif
314 endif
315
316 pre_args += '-DGLX_USE_TLS'
317 if with_glx != 'disabled'
318 if not (with_platform_x11 and with_any_opengl)
319 if with_glx == 'auto'
320 with_glx = 'disabled'
321 else
322 error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
323 endif
324 elif with_glx == 'gallium-xlib'
325 if not with_gallium
326 error('Gallium-xlib based GLX requires at least one gallium driver')
327 elif not with_gallium_softpipe
328 error('Gallium-xlib based GLX requires softpipe or llvmpipe.')
329 elif with_dri
330 error('gallium-xlib conflicts with any dri driver')
331 endif
332 elif with_glx == 'xlib'
333 if with_dri
334 error('xlib conflicts with any dri driver')
335 endif
336 elif with_glx == 'dri' and not with_dri
337 error('dri based GLX requires at least one DRI driver')
338 endif
339 endif
340
341 with_glvnd = get_option('glvnd')
342 if with_glvnd
343 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
344 error('Cannot build glvnd support for GLX that is not DRI based.')
345 elif with_glx == 'disabled' and not with_egl
346 error('glvnd requires DRI based GLX and/or EGL')
347 endif
348 endif
349
350 # TODO: toggle for this
351 with_glx_direct = true
352
353 if with_vulkan_icd_dir == ''
354 with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
355 endif
356
357 with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
358 with_dri3 = get_option('dri3')
359 if with_dri3 == 'auto'
360 with_dri3 = system_has_kms_drm and with_dri2
361 else
362 with_dri3 = with_dri3 == 'true'
363 endif
364
365 if with_any_vk and (with_platform_x11 and not with_dri3)
366 error('Vulkan drivers require dri3 for X11 support')
367 endif
368 if with_dri or with_gallium
369 if with_glx == 'disabled' and not with_egl
370 error('building dri or gallium drivers require at least one window system')
371 endif
372 endif
373
374 prog_pkgconfig = find_program('pkg-config')
375
376 _vdpau = get_option('gallium-vdpau')
377 if not system_has_kms_drm
378 if _vdpau == 'true'
379 error('VDPAU state tracker can only be build on unix-like OSes.')
380 else
381 _vdpau = 'false'
382 endif
383 elif not with_platform_x11
384 if _vdpau == 'true'
385 error('VDPAU state tracker requires X11 support.')
386 else
387 _vdpau = 'false'
388 endif
389 elif not (with_gallium_r300 or with_gallium_r600 or with_gallium_radeonsi or
390 with_gallium_nouveau)
391 if _vdpau == 'true'
392 error('VDPAU state tracker requires at least one of the following gallium drivers: r300, r600, radeonsi, nouveau.')
393 else
394 _vdpau = 'false'
395 endif
396 elif _vdpau == 'auto'
397 _vdpau = 'true'
398 endif
399 with_gallium_vdpau = _vdpau == 'true'
400 dep_vdpau = []
401 if with_gallium_vdpau
402 dep_vdpau = dependency('vdpau', version : '>= 1.1')
403 dep_vdpau = declare_dependency(
404 compile_args : run_command(prog_pkgconfig, ['vdpau', '--cflags']).stdout().split()
405 )
406 endif
407
408 if with_gallium_vdpau
409 pre_args += '-DHAVE_ST_VDPAU'
410 endif
411 vdpau_drivers_path = get_option('vdpau-libs-path')
412 if vdpau_drivers_path == ''
413 vdpau_drivers_path = join_paths(get_option('libdir'), 'vdpau')
414 endif
415
416 _xvmc = get_option('gallium-xvmc')
417 if not system_has_kms_drm
418 if _xvmc == 'true'
419 error('XVMC state tracker can only be build on unix-like OSes.')
420 else
421 _xvmc = 'false'
422 endif
423 elif not with_platform_x11
424 if _xvmc == 'true'
425 error('XVMC state tracker requires X11 support.')
426 else
427 _xvmc = 'false'
428 endif
429 elif not (with_gallium_r600 or with_gallium_nouveau)
430 if _xvmc == 'true'
431 error('XVMC state tracker requires at least one of the following gallium drivers: r600, nouveau.')
432 else
433 _xvmc = 'false'
434 endif
435 elif _xvmc == 'auto'
436 _xvmc = 'true'
437 endif
438 with_gallium_xvmc = _xvmc == 'true'
439 dep_xvmc = []
440 if with_gallium_xvmc
441 dep_xvmc = dependency('xvmc', version : '>= 1.0.6')
442 dep_xvmc = declare_dependency(
443 compile_args : run_command(prog_pkgconfig, ['xvmc', '--cflags']).stdout().split()
444 )
445 endif
446
447 xvmc_drivers_path = get_option('xvmc-libs-path')
448 if xvmc_drivers_path == ''
449 xvmc_drivers_path = get_option('libdir')
450 endif
451
452 _omx = get_option('gallium-omx')
453 if not system_has_kms_drm
454 if _omx == 'true'
455 error('OMX state tracker can only be built on unix-like OSes.')
456 else
457 _omx = 'false'
458 endif
459 elif not (with_platform_x11 or with_platform_drm)
460 if _omx == 'true'
461 error('OMX state tracker requires X11 or drm platform support.')
462 else
463 _omx = 'false'
464 endif
465 elif not (with_gallium_r600 or with_gallium_radeonsi or with_gallium_nouveau)
466 if _omx == 'true'
467 error('OMX state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau.')
468 else
469 _omx = 'false'
470 endif
471 elif _omx == 'auto'
472 _omx = 'true'
473 endif
474 with_gallium_omx = _omx == 'true'
475 dep_omx = []
476 if with_gallium_omx
477 dep_omx = dependency('libomxil-bellagio')
478 endif
479
480 omx_drivers_path = get_option('omx-libs-path')
481 if with_gallium_omx
482 # Figure out where to put the omx driver.
483 # FIXME: this could all be vastly simplified by adding a 'defined_variable'
484 # argument to meson's get_pkgconfig_variable method.
485 if omx_drivers_path == ''
486 _omx_libdir = dep_omx.get_pkgconfig_variable('libdir')
487 _omx_drivers_dir = dep_omx.get_pkgconfig_variable('pluginsdir')
488 if _omx_libdir == get_option('libdir')
489 omx_drivers_path = _omx_drivers_dir
490 else
491 _omx_base_dir = []
492 # This will fail on windows. Does OMX run on windows?
493 _omx_libdir = _omx_libdir.split('/')
494 _omx_drivers_dir = _omx_drivers_dir.split('/')
495 foreach o : _omx_drivers_dir
496 if not _omx_libdir.contains(o)
497 _omx_base_dir += o
498 endif
499 endforeach
500 omx_drivers_path = join_paths(get_option('libdir'), _omx_base_dir)
501 endif
502 endif
503 endif
504 if with_gallium_omx
505 dep_omx = declare_dependency(
506 compile_args : run_command(prog_pkgconfig, ['libomxil-bellagio', '--cflags']).stdout().split()
507 )
508 endif
509
510 _va = get_option('gallium-va')
511 if not system_has_kms_drm
512 if _va == 'true'
513 error('VA state tracker can only be built on unix-like OSes.')
514 else
515 _va = 'false'
516 endif
517 elif not (with_platform_x11 or with_platform_drm)
518 if _va == 'true'
519 error('VA state tracker requires X11 or drm or wayland platform support.')
520 else
521 _va = 'false'
522 endif
523 elif not (with_gallium_r600 or with_gallium_radeonsi or with_gallium_nouveau)
524 if _va == 'true'
525 error('VA state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau.')
526 else
527 _va = 'false'
528 endif
529 elif _va == 'auto'
530 _va = 'true'
531 endif
532 with_gallium_va = _va == 'true'
533 dep_va = []
534 if with_gallium_va
535 dep_va = dependency('libva', version : '>= 0.38.0')
536 dep_va = declare_dependency(
537 compile_args : run_command(prog_pkgconfig, ['libva', '--cflags']).stdout().split()
538 )
539 endif
540
541 va_drivers_path = get_option('va-libs-path')
542 if va_drivers_path == ''
543 va_drivers_path = join_paths(get_option('libdir'), 'dri')
544 endif
545
546 _xa = get_option('gallium-xa')
547 if not system_has_kms_drm
548 if _xa == 'true'
549 error('XA state tracker can only be built on unix-like OSes.')
550 else
551 _xa = 'false'
552 endif
553 elif not (with_gallium_nouveau or with_gallium_freedreno or with_gallium_i915
554 or with_gallium_svga)
555 if _xa == 'true'
556 error('XA state tracker requires at least one of the following gallium drivers: nouveau, freedreno, i915, svga.')
557 else
558 _xa = 'false'
559 endif
560 endif
561 with_gallium_xa = _xa != 'false'
562
563 d3d_drivers_path = get_option('d3d-drivers-path')
564 if d3d_drivers_path == ''
565 d3d_drivers_path = join_paths(get_option('libdir'), 'd3d')
566 endif
567
568 with_gallium_st_nine = get_option('gallium-nine')
569 if with_gallium_st_nine
570 if not with_gallium_softpipe
571 error('The nine state tracker requires gallium softpipe/llvmpipe.')
572 elif not (with_gallium_radeonsi or with_gallium_nouveau or with_gallium_r600
573 or with_gallium_r300 or with_gallium_svga or with_gallium_i915)
574 error('The nine state tracker requires at least on non-swrast gallium driver.')
575 endif
576 if not with_dri3
577 error('Using nine with wine requires dri3')
578 endif
579 endif
580
581 _opencl = get_option('gallium-opencl')
582 if _opencl != 'disabled'
583 if not with_gallium
584 error('OpenCL Clover implementation requires at least one gallium driver.')
585 endif
586
587 # TODO: alitvec?
588 dep_clc = dependency('libclc')
589 with_gallium_opencl = true
590 with_opencl_icd = _opencl == 'icd'
591 else
592 dep_clc = []
593 with_gallium_opencl = false
594 with_gallium_icd = false
595 endif
596
597 gl_pkgconfig_c_flags = []
598 if with_platform_x11
599 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
600 pre_args += '-DHAVE_X11_PLATFORM'
601 endif
602 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
603 pre_args += '-DUSE_XSHM'
604 else
605 pre_args += '-DGLX_INDIRECT_RENDERING'
606 if with_glx_direct
607 pre_args += '-DGLX_DIRECT_RENDERING'
608 endif
609 if with_dri_platform == 'drm'
610 pre_args += '-DGLX_USE_DRM'
611 elif with_dri_platform == 'windows'
612 pre_args += '-DGLX_USE_WINDOWSGL'
613 endif
614 endif
615 else
616 pre_args += '-DMESA_EGL_NO_X11_HEADERS'
617 gl_pkgconfig_c_flags += '-DMESA_EGL_NO_X11_HEADERS'
618 endif
619 if with_platform_drm
620 if with_egl and not with_gbm
621 error('EGL drm platform requires gbm')
622 endif
623 pre_args += '-DHAVE_DRM_PLATFORM'
624 endif
625 if with_platform_surfaceless
626 pre_args += '-DHAVE_SURFACELESS_PLATFORM'
627 endif
628 if with_platform_android
629 dep_android = [
630 dependency('cutils'),
631 dependency('hardware'),
632 dependency('sync'),
633 ]
634 pre_args += '-DHAVE_ANDROID_PLATFORM'
635 endif
636
637 prog_python2 = find_program('python2')
638 has_mako = run_command(prog_python2, '-c', 'import mako')
639 if has_mako.returncode() != 0
640 error('Python (2.x) mako module required to build mesa.')
641 endif
642
643 cc = meson.get_compiler('c')
644 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
645 error('When using GCC, version 4.4.6 or later is required.')
646 endif
647
648 # Define DEBUG for debug builds only (debugoptimized is not included on this one)
649 if get_option('buildtype') == 'debug'
650 pre_args += '-DDEBUG'
651 endif
652
653 if get_option('shader-cache')
654 pre_args += '-DENABLE_SHADER_CACHE'
655 elif with_amd_vk
656 error('Radv requires shader cache support')
657 endif
658
659 # Check for GCC style builtins
660 foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
661 'ffsll', 'popcount', 'popcountll', 'unreachable']
662 if cc.has_function(b)
663 pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
664 endif
665 endforeach
666
667 # check for GCC __attribute__
668 foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
669 'warn_unused_result', 'weak',]
670 if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
671 name : '__attribute__((@0@))'.format(a))
672 pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
673 endif
674 endforeach
675 if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
676 name : '__attribute__((format(...)))')
677 pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
678 endif
679 if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
680 name : '__attribute__((packed))')
681 pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
682 endif
683 if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
684 name : '__attribute__((returns_nonnull))')
685 pre_args += '-DHAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL'
686 endif
687 if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
688 int foo_hid(void) __attribute__((visibility("hidden")));
689 int foo_int(void) __attribute__((visibility("internal")));
690 int foo_pro(void) __attribute__((visibility("protected")));''',
691 name : '__attribute__((visibility(...)))')
692 pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISIBILITY'
693 endif
694 if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
695 name : '__attribute__((alias(...)))')
696 pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
697 endif
698 if cc.compiles('int foo(void) __attribute__((__noreturn__));',
699 name : '__attribute__((__noreturn__))')
700 pre_args += '-DHAVE_FUNC_ATTRIBUTE_NORETURN'
701 endif
702
703 # TODO: this is very incomplete
704 if ['linux', 'cygwin'].contains(host_machine.system())
705 pre_args += '-D_GNU_SOURCE'
706 endif
707
708 # Check for generic C arguments
709 c_args = []
710 foreach a : ['-Wall', '-Werror=implicit-function-declaration',
711 '-Werror=missing-prototypes', '-fno-math-errno',
712 '-fno-trapping-math', '-Qunused-arguments']
713 if cc.has_argument(a)
714 c_args += a
715 endif
716 endforeach
717 c_vis_args = []
718 if cc.has_argument('-fvisibility=hidden')
719 c_vis_args += '-fvisibility=hidden'
720 endif
721
722 # Check for generic C++ arguments
723 cpp = meson.get_compiler('cpp')
724 cpp_args = []
725 foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
726 '-Qunused-arguments']
727 if cpp.has_argument(a)
728 cpp_args += a
729 endif
730 endforeach
731
732 # For some reason, the test for -Wno-foo always succeeds with gcc, even if the
733 # option is not supported. Hence, check for -Wfoo instead.
734 if cpp.has_argument('-Wnon-virtual-dtor')
735 cpp_args += '-Wno-non-virtual-dtor'
736 endif
737
738 no_override_init_args = []
739 foreach a : ['override-init', 'initializer-overrides']
740 if cc.has_argument('-W' + a)
741 no_override_init_args += '-Wno-' + a
742 endif
743 endforeach
744
745 cpp_vis_args = []
746 if cpp.has_argument('-fvisibility=hidden')
747 cpp_vis_args += '-fvisibility=hidden'
748 endif
749
750 # Check for C and C++ arguments for MSVC2013 compatibility. These are only used
751 # in parts of the mesa code base that need to compile with old versions of
752 # MSVC, mainly common code
753 c_msvc_compat_args = []
754 cpp_msvc_compat_args = []
755 foreach a : ['-Werror=pointer-arith', '-Werror=vla']
756 if cc.has_argument(a)
757 c_msvc_compat_args += a
758 endif
759 if cpp.has_argument(a)
760 cpp_msvc_compat_args += a
761 endif
762 endforeach
763
764 if host_machine.cpu_family().startswith('x86')
765 pre_args += '-DUSE_SSE41'
766 with_sse41 = true
767 sse41_args = ['-msse4.1']
768
769 # GCC on x86 (not x86_64) with -msse* assumes a 16 byte aligned stack, but
770 # that's not guaranteed
771 if host_machine.cpu_family() == 'x86'
772 sse41_args += '-mstackrealign'
773 endif
774 else
775 with_sse41 = false
776 sse41_args = []
777 endif
778
779 # Check for GCC style atomics
780 if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',
781 name : 'GCC atomic builtins')
782 pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
783 endif
784 if not cc.links('''#include <stdint.h>
785 uint64_t v;
786 int main() {
787 return __sync_add_and_fetch(&v, (uint64_t)1);
788 }''',
789 name : 'GCC 64bit atomics')
790 pre_args += '-DMISSING_64_BIT_ATOMICS'
791 endif
792
793 # TODO: endian
794 # TODO: powr8
795 # TODO: shared/static? Is this even worth doing?
796
797 # Building x86 assembly code requires running x86 binaries. It is possible for
798 # x86_64 OSes to run x86 binaries, so don't disable asm in those cases
799 # TODO: it should be possible to use an exe_wrapper to run the binary during
800 # the build.
801 if meson.is_cross_build()
802 if not (build_machine.cpu_family() == 'x86_64' and host_machine.cpu_family() == 'x86'
803 and build_machine.system() == host_machine.system())
804 message('Cross compiling to x86 from non-x86, disabling asm')
805 with_asm = false
806 endif
807 endif
808
809 with_asm_arch = ''
810 if with_asm
811 # TODO: SPARC and PPC
812 if host_machine.cpu_family() == 'x86'
813 if system_has_kms_drm
814 with_asm_arch = 'x86'
815 pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
816 '-DUSE_SSE_ASM']
817 endif
818 elif host_machine.cpu_family() == 'x86_64'
819 if system_has_kms_drm
820 with_asm_arch = 'x86_64'
821 pre_args += ['-DUSE_X86_64_ASM']
822 endif
823 elif host_machine.cpu_family() == 'arm'
824 if system_has_kms_drm
825 with_asm_arch = 'arm'
826 pre_args += ['-DUSE_ARM_ASM']
827 endif
828 elif host_machine.cpu_family() == 'aarch64'
829 if system_has_kms_drm
830 with_asm_arch = 'aarch64'
831 pre_args += ['-DUSE_AARCH64_ASM']
832 endif
833 endif
834 endif
835
836 # Check for standard headers and functions
837 if cc.has_header_symbol('sys/sysmacros.h', 'major')
838 pre_args += '-DMAJOR_IN_SYSMACROS'
839 elif cc.has_header_symbol('sys/mkdev.h', 'major')
840 pre_args += '-DMAJOR_IN_MKDEV'
841 endif
842
843 foreach h : ['xlocale.h', 'sys/sysctl.h', 'linux/futex.h']
844 if cc.has_header(h)
845 pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
846 endif
847 endforeach
848
849 foreach f : ['strtof', 'mkostemp', 'posix_memalign', 'timespec_get', 'memfd_create']
850 if cc.has_function(f)
851 pre_args += '-DHAVE_@0@'.format(f.to_upper())
852 endif
853 endforeach
854
855 # strtod locale support
856 if cc.links('''
857 #define _GNU_SOURCE
858 #include <stdlib.h>
859 #include <locale.h>
860 #ifdef HAVE_XLOCALE_H
861 #include <xlocale.h>
862 #endif
863 int main() {
864 locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
865 const char *s = "1.0";
866 char *end;
867 double d = strtod_l(s, end, loc);
868 float f = strtof_l(s, end, loc);
869 freelocale(loc);
870 return 0;
871 }''',
872 extra_args : pre_args,
873 name : 'strtod has locale support')
874 pre_args += '-DHAVE_STRTOD_L'
875 endif
876
877 # Check for some linker flags
878 ld_args_bsymbolic = []
879 if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
880 ld_args_bsymbolic += '-Wl,-Bsymbolic'
881 endif
882 ld_args_gc_sections = []
883 if cc.links('static char unused() { return 5; } int main() { return 0; }',
884 args : '-Wl,--gc-sections', name : 'gc-sections')
885 ld_args_gc_sections += '-Wl,--gc-sections'
886 endif
887 with_ld_version_script = false
888 if cc.links('int main() { return 0; }',
889 args : '-Wl,--version-script=@0@'.format(
890 join_paths(meson.source_root(), 'build-support/conftest.map')),
891 name : 'version-script')
892 with_ld_version_script = true
893 endif
894 with_ld_dynamic_list = false
895 if cc.links('int main() { return 0; }',
896 args : '-Wl,--dynamic-list=@0@'.format(
897 join_paths(meson.source_root(), 'build-support/conftest.dyn')),
898 name : 'dynamic-list')
899 with_ld_dynamic_list = true
900 endif
901
902 # check for dl support
903 if cc.has_function('dlopen')
904 dep_dl = []
905 else
906 dep_dl = cc.find_library('dl')
907 endif
908 if cc.has_function('dladdr', dependencies : dep_dl)
909 # This is really only required for megadrivers
910 pre_args += '-DHAVE_DLADDR'
911 endif
912
913 if cc.has_function('dl_iterate_phdr')
914 pre_args += '-DHAVE_DL_ITERATE_PHDR'
915 elif with_intel_vk
916 error('Intel "Anvil" Vulkan driver requires the dl_iterate_phdr function')
917 elif with_dri_i965 and get_option('shader-cache')
918 error('Intel i965 GL driver requires dl_iterate_phdr when built with shader caching.')
919 endif
920
921 # Determine whether or not the rt library is needed for time functions
922 if cc.has_function('clock_gettime')
923 dep_clock = []
924 else
925 dep_clock = cc.find_library('rt')
926 endif
927
928 with_gallium_drisw_kms = false
929 dep_libdrm = dependency('libdrm', version : '>= 2.4.75',
930 required : with_dri2 or with_dri3)
931 if dep_libdrm.found()
932 pre_args += '-DHAVE_LIBDRM'
933 if with_dri_platform == 'drm' and with_dri
934 with_gallium_drisw_kms = true
935 endif
936 endif
937
938 # TODO: some of these may be conditional
939 dep_zlib = dependency('zlib', version : '>= 1.2.3')
940 pre_args += '-DHAVE_ZLIB'
941 dep_thread = dependency('threads')
942 if dep_thread.found() and host_machine.system() != 'windows'
943 pre_args += '-DHAVE_PTHREAD'
944 endif
945 if with_amd_vk or with_gallium_radeonsi or with_gallium_r600 or with_gallium_opencl
946 dep_elf = dependency('libelf', required : false)
947 if not dep_elf.found()
948 dep_elf = cc.find_library('elf')
949 endif
950 else
951 dep_elf = []
952 endif
953 dep_expat = dependency('expat')
954 # this only exists on linux so either this is linux and it will be found, or
955 # its not linux and and wont
956 dep_m = cc.find_library('m', required : false)
957
958 dep_libdrm_amdgpu = []
959 dep_libdrm_radeon = []
960 dep_libdrm_nouveau = []
961 dep_libdrm_etnaviv = []
962 dep_libdrm_freedreno = []
963 if with_amd_vk or with_gallium_radeonsi
964 dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.89')
965 endif
966 if (with_gallium_radeonsi or with_dri_r100 or with_dri_r200 or
967 with_gallium_r300 or with_gallium_r600)
968 dep_libdrm_radeon = dependency('libdrm_radeon', version : '>= 2.4.71')
969 endif
970 if with_gallium_nouveau or with_dri_nouveau
971 dep_libdrm_nouveau = dependency('libdrm_nouveau', version : '>= 2.4.66')
972 endif
973 if with_gallium_etnaviv
974 dep_libdrm_etnaviv = dependency('libdrm_etnaviv', version : '>= 2.4.82')
975 endif
976 if with_gallium_freedreno
977 dep_libdrm_freedreno = dependency('libdrm_freedreno', version : '>= 2.4.89')
978 endif
979
980 llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
981 if with_amd_vk or with_gallium_radeonsi or with_gallium_r600
982 llvm_modules += ['amdgpu', 'bitreader', 'ipo']
983 if with_gallium_r600
984 llvm_modules += 'asmparser'
985 endif
986 endif
987 if with_gallium_opencl
988 llvm_modules += [
989 'all-targets', 'linker', 'coverage', 'instrumentation', 'ipo', 'irreader',
990 'lto', 'option', 'objcarcopts', 'profiledata',
991 ]
992 # TODO: optional modules
993 endif
994
995 _llvm = get_option('llvm')
996 if _llvm == 'auto'
997 dep_llvm = dependency(
998 'llvm', version : '>= 3.9.0', modules : llvm_modules,
999 required : with_amd_vk or with_gallium_radeonsi or with_gallium_swr or with_gallium_opencl,
1000 )
1001 with_llvm = dep_llvm.found()
1002 elif _llvm == 'true'
1003 dep_llvm = dependency('llvm', version : '>= 3.9.0', modules : llvm_modules)
1004 with_llvm = true
1005 else
1006 dep_llvm = []
1007 with_llvm = false
1008 endif
1009 if with_llvm
1010 _llvm_version = dep_llvm.version().split('.')
1011 # Development versions of LLVM have an 'svn' or 'git' suffix, we don't want
1012 # that for our version checks.
1013 # svn suffixes are stripped by meson as of 0.43, and git suffixes are
1014 # strippped as of 0.44, but we support older meson versions.
1015 _llvm_patch = _llvm_version[2]
1016 if _llvm_patch.endswith('svn')
1017 _llvm_patch = _llvm_patch.split('s')[0]
1018 elif _llvm_patch.contains('git')
1019 _llvm_patch = _llvm_patch.split('g')[0]
1020 endif
1021 pre_args += [
1022 '-DHAVE_LLVM=0x0@0@0@1@'.format(_llvm_version[0], _llvm_version[1]),
1023 '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
1024 ]
1025 elif with_amd_vk or with_gallium_radeonsi or with_gallium_swr
1026 error('The following drivers requires LLVM: Radv, RadeonSI, SWR. One of these is enabled, but LLVM is disabled.')
1027 endif
1028
1029 dep_glvnd = []
1030 if with_glvnd
1031 dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
1032 pre_args += '-DUSE_LIBGLVND=1'
1033 endif
1034
1035 if with_valgrind != 'false'
1036 dep_valgrind = dependency('valgrind', required : with_valgrind == 'true')
1037 if dep_valgrind.found()
1038 pre_args += '-DHAVE_VALGRIND'
1039 endif
1040 else
1041 dep_valgrind = []
1042 endif
1043
1044 # pthread stubs. Lets not and say we didn't
1045
1046 prog_bison = find_program('bison', required : with_any_opengl)
1047 prog_flex = find_program('flex', required : with_any_opengl)
1048
1049 dep_selinux = []
1050 if get_option('selinux')
1051 dep_selinux = dependency('libselinux')
1052 pre_args += '-DMESA_SELINUX'
1053 endif
1054
1055 # TODO: llvm-prefix and llvm-shared-libs
1056
1057 if with_libunwind != 'false'
1058 dep_unwind = dependency('libunwind', required : with_libunwind == 'true')
1059 if dep_unwind.found()
1060 pre_args += '-DHAVE_LIBUNWIND'
1061 endif
1062 else
1063 dep_unwind = []
1064 endif
1065
1066 # TODO: gallium-hud
1067
1068 if with_osmesa != 'none'
1069 if with_osmesa == 'classic' and not with_dri_swrast
1070 error('OSMesa classic requires dri (classic) swrast.')
1071 endif
1072 if with_osmesa == 'gallium' and not with_gallium_softpipe
1073 error('OSMesa gallium requires gallium softpipe or llvmpipe.')
1074 endif
1075 osmesa_lib_name = 'OSMesa'
1076 osmesa_bits = get_option('osmesa-bits')
1077 if osmesa_bits != '8'
1078 if with_dri or with_glx != 'disabled'
1079 error('OSMesa bits must be 8 if building glx or dir based drivers')
1080 endif
1081 osmesa_lib_name = osmesa_lib_name + osmesa_bits
1082 pre_args += [
1083 '-DCHAN_BITS=@0@'.format(osmesa_bits), '-DDEFAULT_SOFTWARE_DEPTH_BITS=31'
1084 ]
1085 endif
1086 endif
1087
1088 # TODO: symbol mangling
1089
1090 if with_platform_wayland
1091 prog_wl_scanner = find_program('wayland-scanner')
1092 dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
1093 dep_wayland_client = dependency('wayland-client', version : '>=1.11')
1094 dep_wayland_server = dependency('wayland-server', version : '>=1.11')
1095 wayland_dmabuf_xml = join_paths(
1096 dep_wl_protocols.get_pkgconfig_variable('pkgdatadir'), 'unstable',
1097 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
1098 )
1099 pre_args += ['-DHAVE_WAYLAND_PLATFORM', '-DWL_HIDE_DEPRECATED']
1100 else
1101 prog_wl_scanner = []
1102 dep_wl_protocols = []
1103 dep_wayland_client = []
1104 dep_wayland_server = []
1105 wayland_dmabuf_xml = ''
1106 endif
1107
1108 dep_x11 = []
1109 dep_xext = []
1110 dep_xdamage = []
1111 dep_xfixes = []
1112 dep_x11_xcb = []
1113 dep_xcb = []
1114 dep_xcb_glx = []
1115 dep_xcb_dri2 = []
1116 dep_xcb_dri3 = []
1117 dep_dri2proto = []
1118 dep_glproto = []
1119 dep_xxf86vm = []
1120 dep_xcb_dri3 = []
1121 dep_xcb_present = []
1122 dep_xcb_sync = []
1123 dep_xcb_xfixes = []
1124 dep_xshmfence = []
1125 if with_platform_x11
1126 if with_glx == 'xlib' or with_glx == 'gallium-xlib'
1127 dep_x11 = dependency('x11')
1128 dep_xext = dependency('xext')
1129 dep_xcb = dependency('xcb')
1130 elif with_glx == 'dri'
1131 dep_x11 = dependency('x11')
1132 dep_xext = dependency('xext')
1133 dep_xdamage = dependency('xdamage', version : '>= 1.1')
1134 dep_xfixes = dependency('xfixes')
1135 dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
1136 dep_xxf86vm = dependency('xxf86vm', required : false)
1137 endif
1138 if (with_any_vk or with_glx == 'dri' or
1139 (with_gallium_vdpau or with_gallium_xvmc or with_gallium_omx or
1140 with_gallium_xa))
1141 dep_xcb = dependency('xcb')
1142 dep_x11_xcb = dependency('x11-xcb')
1143 endif
1144 if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
1145 dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
1146
1147 if with_dri3
1148 pre_args += '-DHAVE_DRI3'
1149 dep_xcb_dri3 = dependency('xcb-dri3')
1150 dep_xcb_present = dependency('xcb-present')
1151 dep_xcb_sync = dependency('xcb-sync')
1152 dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
1153 endif
1154 endif
1155 if with_glx == 'dri'
1156 if with_dri_platform == 'drm'
1157 dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
1158 endif
1159 dep_glproto = dependency('glproto', version : '>= 1.4.14')
1160 endif
1161 if with_egl
1162 dep_xcb_xfixes = dependency('xcb-xfixes')
1163 endif
1164 endif
1165
1166 if get_option('gallium-extra-hud')
1167 pre_args += '-DHAVE_GALLIUM_EXTRA_HUD=1'
1168 endif
1169
1170 _sensors = get_option('lmsensors')
1171 if _sensors != 'false'
1172 dep_lmsensors = cc.find_library('libsensors', required : _sensors == 'true')
1173 if dep_lmsensors.found()
1174 pre_args += '-DHAVE_LIBSENSORS=1'
1175 endif
1176 else
1177 dep_lmsensors = []
1178 endif
1179
1180 # TODO: gallium tests
1181
1182 # TODO: various libdirs
1183
1184 # TODO: gallium driver dirs
1185
1186 # FIXME: this is a workaround for #2326
1187 prog_touch = find_program('touch')
1188 dummy_cpp = custom_target(
1189 'dummy_cpp',
1190 output : 'dummy.cpp',
1191 command : [prog_touch, '@OUTPUT@'],
1192 )
1193
1194 foreach a : pre_args
1195 add_project_arguments(a, language : ['c', 'cpp'])
1196 endforeach
1197 foreach a : c_args
1198 add_project_arguments(a, language : ['c'])
1199 endforeach
1200 foreach a : cpp_args
1201 add_project_arguments(a, language : ['cpp'])
1202 endforeach
1203
1204 inc_include = include_directories('include')
1205
1206 gl_priv_reqs = [
1207 'x11', 'xext', 'xdamage >= 1.1', 'xfixes', 'x11-xcb', 'xcb',
1208 'xcb-glx >= 1.8.1']
1209 if dep_libdrm.found()
1210 gl_priv_reqs += 'libdrm >= 2.4.75'
1211 endif
1212 if dep_xxf86vm != [] and dep_xxf86vm.found()
1213 gl_priv_reqs += 'xxf86vm'
1214 endif
1215 if with_dri_platform == 'drm'
1216 gl_priv_reqs += 'xcb-dri2 >= 1.8'
1217 endif
1218
1219 gl_priv_libs = []
1220 if dep_thread.found()
1221 gl_priv_libs += ['-lpthread', '-pthread']
1222 endif
1223 if dep_m.found()
1224 gl_priv_libs += '-lm'
1225 endif
1226 if dep_dl != [] and dep_dl.found()
1227 gl_priv_libs += '-ldl'
1228 endif
1229
1230 pkg = import('pkgconfig')
1231
1232 subdir('include')
1233 subdir('bin')
1234 subdir('src')