Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

meson.build 46KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  1. # Copyright © 2017-2018 Intel Corporation
  2. # Permission is hereby granted, free of charge, to any person obtaining a copy
  3. # of this software and associated documentation files (the "Software"), to deal
  4. # in the Software without restriction, including without limitation the rights
  5. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6. # copies of the Software, and to permit persons to whom the Software is
  7. # furnished to do so, subject to the following conditions:
  8. # The above copyright notice and this permission notice shall be included in
  9. # all copies or substantial portions of the Software.
  10. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  14. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  15. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. # SOFTWARE.
  17. project(
  18. 'mesa',
  19. ['c', 'cpp'],
  20. version : run_command(
  21. [find_program('python', 'python2', 'python3'), 'bin/meson_get_version.py']
  22. ).stdout(),
  23. license : 'MIT',
  24. meson_version : '>= 0.45',
  25. default_options : ['buildtype=debugoptimized', 'b_ndebug=if-release', 'c_std=c99', 'cpp_std=c++11']
  26. )
  27. cc = meson.get_compiler('c')
  28. cpp = meson.get_compiler('cpp')
  29. null_dep = dependency('', required : false)
  30. # Arguments for the preprocessor, put these in a separate array from the C and
  31. # C++ (cpp in meson terminology) arguments since they need to be added to the
  32. # default arguments for both C and C++.
  33. pre_args = [
  34. '-D__STDC_CONSTANT_MACROS',
  35. '-D__STDC_FORMAT_MACROS',
  36. '-D__STDC_LIMIT_MACROS',
  37. '-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
  38. '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
  39. ]
  40. with_vulkan_icd_dir = get_option('vulkan-icd-dir')
  41. with_tests = get_option('build-tests')
  42. with_valgrind = get_option('valgrind')
  43. with_libunwind = get_option('libunwind')
  44. with_asm = get_option('asm')
  45. with_glx_read_only_text = get_option('glx-read-only-text')
  46. with_glx_direct = get_option('glx-direct')
  47. with_osmesa = get_option('osmesa')
  48. with_swr_arches = get_option('swr-arches')
  49. with_tools = get_option('tools')
  50. if with_tools.contains('all')
  51. with_tools = ['etnaviv', 'freedreno', 'glsl', 'intel', 'nir', 'nouveau', 'xvmc']
  52. endif
  53. dri_drivers_path = get_option('dri-drivers-path')
  54. if dri_drivers_path == ''
  55. dri_drivers_path = join_paths(get_option('libdir'), 'dri')
  56. endif
  57. dri_search_path = get_option('dri-search-path')
  58. if dri_search_path == ''
  59. dri_search_path = join_paths(get_option('prefix'), dri_drivers_path)
  60. endif
  61. with_gles1 = get_option('gles1')
  62. with_gles2 = get_option('gles2')
  63. with_opengl = get_option('opengl')
  64. with_any_opengl = with_opengl or with_gles1 or with_gles2
  65. # Only build shared_glapi if at least one OpenGL API is enabled
  66. with_shared_glapi = get_option('shared-glapi') and with_any_opengl
  67. # shared-glapi is required if at least two OpenGL APIs are being built
  68. if not with_shared_glapi
  69. if ((with_gles1 and with_gles2) or (with_gles1 and with_opengl)
  70. or (with_gles2 and with_opengl))
  71. error('shared-glapi required for building two or more of OpenGL, OpenGL ES 1.x, OpenGL ES 2.x')
  72. endif
  73. endif
  74. # We require OpenGL for OpenGL ES
  75. if (with_gles1 or with_gles2) and not with_opengl
  76. error('building OpenGL ES without OpenGL is not supported.')
  77. endif
  78. system_has_kms_drm = ['openbsd', 'netbsd', 'freebsd', 'dragonfly', 'linux'].contains(host_machine.system())
  79. _drivers = get_option('dri-drivers')
  80. if _drivers.contains('auto')
  81. if system_has_kms_drm
  82. # TODO: PPC, Sparc
  83. if ['x86', 'x86_64'].contains(host_machine.cpu_family())
  84. _drivers = ['i915', 'i965', 'r100', 'r200', 'nouveau']
  85. elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
  86. _drivers = []
  87. else
  88. error('Unknown architecture @0@. Please pass -Ddri-drivers to set driver options. Patches gladly accepted to fix this.'.format(
  89. host_machine.cpu_family()))
  90. endif
  91. elif ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
  92. # only swrast would make sense here, but gallium swrast is a much better default
  93. _drivers = []
  94. else
  95. error('Unknown OS @0@. Please pass -Ddri-drivers to set driver options. Patches gladly accepted to fix this.'.format(
  96. host_machine.system()))
  97. endif
  98. endif
  99. with_dri_i915 = _drivers.contains('i915')
  100. with_dri_i965 = _drivers.contains('i965')
  101. with_dri_r100 = _drivers.contains('r100')
  102. with_dri_r200 = _drivers.contains('r200')
  103. with_dri_nouveau = _drivers.contains('nouveau')
  104. with_dri_swrast = _drivers.contains('swrast')
  105. with_dri = _drivers.length() != 0 and _drivers != ['']
  106. _drivers = get_option('gallium-drivers')
  107. if _drivers.contains('auto')
  108. if system_has_kms_drm
  109. # TODO: PPC, Sparc
  110. if ['x86', 'x86_64'].contains(host_machine.cpu_family())
  111. _drivers = [
  112. 'r300', 'r600', 'radeonsi', 'nouveau', 'virgl', 'svga', 'swrast'
  113. ]
  114. elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
  115. _drivers = [
  116. 'pl111', 'v3d', 'vc4', 'freedreno', 'etnaviv', 'imx', 'nouveau',
  117. 'tegra', 'virgl', 'swrast',
  118. ]
  119. else
  120. error('Unknown architecture @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
  121. host_machine.cpu_family()))
  122. endif
  123. elif ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
  124. _drivers = ['swrast']
  125. else
  126. error('Unknown OS @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
  127. host_machine.system()))
  128. endif
  129. endif
  130. with_gallium_pl111 = _drivers.contains('pl111')
  131. with_gallium_radeonsi = _drivers.contains('radeonsi')
  132. with_gallium_r300 = _drivers.contains('r300')
  133. with_gallium_r600 = _drivers.contains('r600')
  134. with_gallium_nouveau = _drivers.contains('nouveau')
  135. with_gallium_freedreno = _drivers.contains('freedreno')
  136. with_gallium_softpipe = _drivers.contains('swrast')
  137. with_gallium_vc4 = _drivers.contains('vc4')
  138. with_gallium_v3d = _drivers.contains('v3d')
  139. with_gallium_etnaviv = _drivers.contains('etnaviv')
  140. with_gallium_imx = _drivers.contains('imx')
  141. with_gallium_tegra = _drivers.contains('tegra')
  142. with_gallium_i915 = _drivers.contains('i915')
  143. with_gallium_svga = _drivers.contains('svga')
  144. with_gallium_virgl = _drivers.contains('virgl')
  145. with_gallium_swr = _drivers.contains('swr')
  146. with_gallium = _drivers.length() != 0 and _drivers != ['']
  147. if with_gallium and system_has_kms_drm
  148. _glx = get_option('glx')
  149. _egl = get_option('egl')
  150. if _glx == 'dri' or _egl == 'true' or (_glx == 'disabled' and _egl != 'false')
  151. with_dri = true
  152. endif
  153. endif
  154. _vulkan_drivers = get_option('vulkan-drivers')
  155. if _vulkan_drivers.contains('auto')
  156. if system_has_kms_drm
  157. if host_machine.cpu_family().startswith('x86')
  158. _vulkan_drivers = ['amd', 'intel']
  159. elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
  160. _vulkan_drivers = []
  161. else
  162. error('Unknown architecture @0@. Please pass -Dvulkan-drivers to set driver options. Patches gladly accepted to fix this.'.format(
  163. host_machine.cpu_family()))
  164. endif
  165. elif ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
  166. # No vulkan driver supports windows or macOS currently
  167. _vulkan_drivers = []
  168. else
  169. error('Unknown OS @0@. Please pass -Dvulkan-drivers to set driver options. Patches gladly accepted to fix this.'.format(
  170. host_machine.system()))
  171. endif
  172. endif
  173. with_intel_vk = _vulkan_drivers.contains('intel')
  174. with_amd_vk = _vulkan_drivers.contains('amd')
  175. with_any_vk = _vulkan_drivers.length() != 0 and _vulkan_drivers != ['']
  176. if with_dri_swrast and (with_gallium_softpipe or with_gallium_swr)
  177. error('Only one swrast provider can be built')
  178. endif
  179. if with_dri_i915 and with_gallium_i915
  180. error('Only one i915 provider can be built')
  181. endif
  182. if with_gallium_imx and not with_gallium_etnaviv
  183. error('IMX driver requires etnaviv driver')
  184. endif
  185. if with_gallium_pl111 and not with_gallium_vc4
  186. error('pl111 driver requires vc4 driver')
  187. endif
  188. if with_gallium_tegra and not with_gallium_nouveau
  189. error('tegra driver requires nouveau driver')
  190. endif
  191. if host_machine.system() == 'darwin'
  192. with_dri_platform = 'apple'
  193. elif ['windows', 'cygwin'].contains(host_machine.system())
  194. with_dri_platform = 'windows'
  195. elif system_has_kms_drm
  196. with_dri_platform = 'drm'
  197. else
  198. # FIXME: haiku doesn't use dri, and xlib doesn't use dri, probably should
  199. # assert here that one of those cases has been met.
  200. # FIXME: illumos ends up here as well
  201. with_dri_platform = 'none'
  202. endif
  203. _platforms = get_option('platforms')
  204. if _platforms.contains('auto')
  205. if system_has_kms_drm
  206. _platforms = ['x11', 'wayland', 'drm', 'surfaceless']
  207. elif ['darwin', 'windows', 'cygwin'].contains(host_machine.system())
  208. _platforms = ['x11', 'surfaceless']
  209. elif ['haiku'].contains(host_machine.system())
  210. _platforms = ['haiku']
  211. else
  212. error('Unknown OS @0@. Please pass -Dplatforms to set platforms. Patches gladly accepted to fix this.'.format(
  213. host_machine.system()))
  214. endif
  215. endif
  216. with_platform_android = _platforms.contains('android')
  217. with_platform_x11 = _platforms.contains('x11')
  218. with_platform_wayland = _platforms.contains('wayland')
  219. with_platform_drm = _platforms.contains('drm')
  220. with_platform_haiku = _platforms.contains('haiku')
  221. with_platform_surfaceless = _platforms.contains('surfaceless')
  222. with_platforms = false
  223. if _platforms.length() != 0 and _platforms != ['']
  224. with_platforms = true
  225. egl_native_platform = _platforms[0]
  226. endif
  227. _xlib_lease = get_option('xlib-lease')
  228. if _xlib_lease == 'auto'
  229. with_xlib_lease = with_platform_x11 and with_platform_drm
  230. else
  231. with_xlib_lease = _xlib_lease == 'true'
  232. endif
  233. with_glx = get_option('glx')
  234. if with_glx == 'auto'
  235. if with_dri
  236. with_glx = 'dri'
  237. elif with_platform_haiku
  238. with_glx = 'disabled'
  239. elif with_gallium
  240. # Even when building just gallium drivers the user probably wants dri
  241. with_glx = 'dri'
  242. elif with_platform_x11 and with_any_opengl and not with_any_vk
  243. # The automatic behavior should not be to turn on xlib based glx when
  244. # building only vulkan drivers
  245. with_glx = 'xlib'
  246. else
  247. with_glx = 'disabled'
  248. endif
  249. endif
  250. if with_glx == 'dri'
  251. if with_gallium
  252. with_dri = true
  253. endif
  254. endif
  255. if not (with_dri or with_gallium or with_glx == 'xlib' or with_glx == 'gallium-xlib')
  256. with_gles1 = false
  257. with_gles2 = false
  258. with_opengl = false
  259. with_any_opengl = false
  260. with_shared_glapi = false
  261. endif
  262. _gbm = get_option('gbm')
  263. if _gbm == 'auto'
  264. with_gbm = system_has_kms_drm and with_dri
  265. else
  266. with_gbm = _gbm == 'true'
  267. endif
  268. if with_gbm and not system_has_kms_drm
  269. error('GBM only supports DRM/KMS platforms')
  270. endif
  271. _egl = get_option('egl')
  272. if _egl == 'auto'
  273. with_egl = (
  274. not ['darwin', 'windows'].contains(host_machine.system()) and
  275. with_dri and with_shared_glapi and with_platforms
  276. )
  277. elif _egl == 'true'
  278. if not with_dri
  279. error('EGL requires dri')
  280. elif not with_shared_glapi
  281. error('EGL requires shared-glapi')
  282. elif not with_platforms
  283. error('No platforms specified, consider -Dplatforms=drm,x11,surfaceless at least')
  284. elif not ['disabled', 'dri'].contains(with_glx)
  285. error('EGL requires dri, but a GLX is being built without dri')
  286. elif ['darwin', 'windows'].contains(host_machine.system())
  287. error('EGL is not available on Windows or MacOS')
  288. endif
  289. with_egl = true
  290. else
  291. with_egl = false
  292. endif
  293. if with_egl and not (with_platform_drm or with_platform_surfaceless)
  294. if with_gallium_radeonsi
  295. error('RadeonSI requires drm or surfaceless platform when using EGL')
  296. endif
  297. if with_gallium_virgl
  298. error('Virgl requires drm or surfaceless platform when using EGL')
  299. endif
  300. endif
  301. pre_args += '-DGLX_USE_TLS'
  302. if with_glx != 'disabled'
  303. if not (with_platform_x11 and with_any_opengl)
  304. error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
  305. elif with_glx == 'gallium-xlib'
  306. if not with_gallium
  307. error('Gallium-xlib based GLX requires at least one gallium driver')
  308. elif not with_gallium_softpipe
  309. error('Gallium-xlib based GLX requires softpipe or llvmpipe.')
  310. elif with_dri
  311. error('gallium-xlib conflicts with any dri driver')
  312. endif
  313. elif with_glx == 'xlib'
  314. if with_dri
  315. error('xlib conflicts with any dri driver')
  316. endif
  317. elif with_glx == 'dri'
  318. if not with_dri
  319. error('dri based GLX requires at least one DRI driver')
  320. elif not with_shared_glapi
  321. error('dri based GLX requires shared-glapi')
  322. endif
  323. endif
  324. endif
  325. with_glvnd = get_option('glvnd')
  326. if with_glvnd
  327. if with_glx == 'xlib' or with_glx == 'gallium-xlib'
  328. error('Cannot build glvnd support for GLX that is not DRI based.')
  329. elif with_glx == 'disabled' and not with_egl
  330. error('glvnd requires DRI based GLX and/or EGL')
  331. endif
  332. endif
  333. if with_vulkan_icd_dir == ''
  334. with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
  335. endif
  336. with_dri2 = (with_dri or with_any_vk) and with_dri_platform == 'drm'
  337. _dri3 = get_option('dri3')
  338. if _dri3 == 'auto'
  339. with_dri3 = system_has_kms_drm and with_dri2
  340. else
  341. with_dri3 = _dri3 == 'true'
  342. endif
  343. if with_any_vk and (with_platform_x11 and not with_dri3)
  344. error('Vulkan drivers require dri3 for X11 support')
  345. endif
  346. if with_dri
  347. if with_glx == 'disabled' and not with_egl and not with_gbm
  348. error('building dri drivers require at least one windowing system')
  349. endif
  350. endif
  351. prog_pkgconfig = find_program('pkg-config')
  352. _vdpau = get_option('gallium-vdpau')
  353. if not system_has_kms_drm
  354. if _vdpau == 'true'
  355. error('VDPAU state tracker can only be build on unix-like OSes.')
  356. else
  357. _vdpau = 'false'
  358. endif
  359. elif not with_platform_x11
  360. if _vdpau == 'true'
  361. error('VDPAU state tracker requires X11 support.')
  362. else
  363. _vdpau = 'false'
  364. endif
  365. elif not (with_gallium_r300 or with_gallium_r600 or with_gallium_radeonsi or
  366. with_gallium_nouveau)
  367. if _vdpau == 'true'
  368. error('VDPAU state tracker requires at least one of the following gallium drivers: r300, r600, radeonsi, nouveau.')
  369. else
  370. _vdpau = 'false'
  371. endif
  372. endif
  373. dep_vdpau = null_dep
  374. with_gallium_vdpau = false
  375. if _vdpau != 'false'
  376. dep_vdpau = dependency('vdpau', version : '>= 1.1', required : _vdpau == 'true')
  377. if dep_vdpau.found()
  378. dep_vdpau = declare_dependency(
  379. compile_args : run_command(prog_pkgconfig, ['vdpau', '--cflags']).stdout().split()
  380. )
  381. with_gallium_vdpau = true
  382. endif
  383. endif
  384. if with_gallium_vdpau
  385. pre_args += '-DHAVE_ST_VDPAU'
  386. endif
  387. vdpau_drivers_path = get_option('vdpau-libs-path')
  388. if vdpau_drivers_path == ''
  389. vdpau_drivers_path = join_paths(get_option('libdir'), 'vdpau')
  390. endif
  391. _xvmc = get_option('gallium-xvmc')
  392. if not system_has_kms_drm
  393. if _xvmc == 'true'
  394. error('XVMC state tracker can only be build on unix-like OSes.')
  395. else
  396. _xvmc = 'false'
  397. endif
  398. elif not with_platform_x11
  399. if _xvmc == 'true'
  400. error('XVMC state tracker requires X11 support.')
  401. else
  402. _xvmc = 'false'
  403. endif
  404. elif not (with_gallium_r600 or with_gallium_nouveau)
  405. if _xvmc == 'true'
  406. error('XVMC state tracker requires at least one of the following gallium drivers: r600, nouveau.')
  407. else
  408. _xvmc = 'false'
  409. endif
  410. endif
  411. dep_xvmc = null_dep
  412. with_gallium_xvmc = false
  413. if _xvmc != 'false'
  414. dep_xvmc = dependency('xvmc', version : '>= 1.0.6', required : _xvmc == 'true')
  415. with_gallium_xvmc = dep_xvmc.found()
  416. endif
  417. xvmc_drivers_path = get_option('xvmc-libs-path')
  418. if xvmc_drivers_path == ''
  419. xvmc_drivers_path = get_option('libdir')
  420. endif
  421. _omx = get_option('gallium-omx')
  422. if not system_has_kms_drm
  423. if ['auto', 'disabled'].contains(_omx)
  424. _omx = 'disabled'
  425. else
  426. error('OMX state tracker can only be built on unix-like OSes.')
  427. endif
  428. elif not (with_platform_x11 or with_platform_drm)
  429. if ['auto', 'disabled'].contains(_omx)
  430. _omx = 'disabled'
  431. else
  432. error('OMX state tracker requires X11 or drm platform support.')
  433. endif
  434. elif not (with_gallium_r600 or with_gallium_radeonsi or with_gallium_nouveau)
  435. if ['auto', 'disabled'].contains(_omx)
  436. _omx = 'disabled'
  437. else
  438. error('OMX state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau.')
  439. endif
  440. endif
  441. with_gallium_omx = _omx
  442. dep_omx = null_dep
  443. dep_omx_other = []
  444. if ['auto', 'bellagio'].contains(_omx)
  445. dep_omx = dependency(
  446. 'libomxil-bellagio', required : _omx == 'bellagio'
  447. )
  448. if dep_omx.found()
  449. with_gallium_omx = 'bellagio'
  450. endif
  451. endif
  452. if ['auto', 'tizonia'].contains(_omx)
  453. if with_dri and with_egl
  454. dep_omx = dependency(
  455. 'libtizonia', version : '>= 0.10.0',
  456. required : _omx == 'tizonia',
  457. )
  458. dep_omx_other = [
  459. dependency('libtizplatform', required : _omx == 'tizonia'),
  460. dependency('tizilheaders', required : _omx == 'tizonia'),
  461. ]
  462. if dep_omx.found() and dep_omx_other[0].found() and dep_omx_other[1].found()
  463. with_gallium_omx = 'tizonia'
  464. endif
  465. elif _omx == 'tizonia'
  466. error('OMX-Tizonia state tracker requires dri and egl')
  467. endif
  468. endif
  469. if _omx == 'auto'
  470. with_gallium_omx = 'disabled'
  471. else
  472. with_gallium_omx = _omx
  473. endif
  474. pre_args += [
  475. '-DENABLE_ST_OMX_BELLAGIO=' + (with_gallium_omx == 'bellagio' ? '1' : '0'),
  476. '-DENABLE_ST_OMX_TIZONIA=' + (with_gallium_omx == 'tizonia' ? '1' : '0'),
  477. ]
  478. omx_drivers_path = get_option('omx-libs-path')
  479. if with_gallium_omx != 'disabled'
  480. # Figure out where to put the omx driver.
  481. # FIXME: this could all be vastly simplified by adding a 'defined_variable'
  482. # argument to meson's get_pkgconfig_variable method.
  483. if omx_drivers_path == ''
  484. _omx_libdir = dep_omx.get_pkgconfig_variable('libdir')
  485. _omx_drivers_dir = dep_omx.get_pkgconfig_variable('pluginsdir')
  486. if _omx_libdir == get_option('libdir')
  487. omx_drivers_path = _omx_drivers_dir
  488. else
  489. _omx_base_dir = []
  490. # This will fail on windows. Does OMX run on windows?
  491. _omx_libdir = _omx_libdir.split('/')
  492. _omx_drivers_dir = _omx_drivers_dir.split('/')
  493. foreach o : _omx_drivers_dir
  494. if not _omx_libdir.contains(o)
  495. _omx_base_dir += o
  496. endif
  497. endforeach
  498. omx_drivers_path = join_paths(get_option('libdir'), _omx_base_dir)
  499. endif
  500. endif
  501. endif
  502. _va = get_option('gallium-va')
  503. if not system_has_kms_drm
  504. if _va == 'true'
  505. error('VA state tracker can only be built on unix-like OSes.')
  506. else
  507. _va = 'false'
  508. endif
  509. elif not (with_platform_x11 or with_platform_drm)
  510. if _va == 'true'
  511. error('VA state tracker requires X11 or drm or wayland platform support.')
  512. else
  513. _va = 'false'
  514. endif
  515. elif not (with_gallium_r600 or with_gallium_radeonsi or with_gallium_nouveau)
  516. if _va == 'true'
  517. error('VA state tracker requires at least one of the following gallium drivers: r600, radeonsi, nouveau.')
  518. else
  519. _va = 'false'
  520. endif
  521. endif
  522. with_gallium_va = false
  523. dep_va = null_dep
  524. if _va != 'false'
  525. dep_va = dependency('libva', version : '>= 0.38.0', required : _va == 'true')
  526. if dep_va.found()
  527. dep_va_headers = declare_dependency(
  528. compile_args : run_command(prog_pkgconfig, ['libva', '--cflags']).stdout().split()
  529. )
  530. with_gallium_va = true
  531. endif
  532. endif
  533. va_drivers_path = get_option('va-libs-path')
  534. if va_drivers_path == ''
  535. va_drivers_path = join_paths(get_option('libdir'), 'dri')
  536. endif
  537. _xa = get_option('gallium-xa')
  538. if not system_has_kms_drm
  539. if _xa == 'true'
  540. error('XA state tracker can only be built on unix-like OSes.')
  541. else
  542. _xa = 'false'
  543. endif
  544. elif not (with_gallium_nouveau or with_gallium_freedreno or with_gallium_i915
  545. or with_gallium_svga)
  546. if _xa == 'true'
  547. error('XA state tracker requires at least one of the following gallium drivers: nouveau, freedreno, i915, svga.')
  548. else
  549. _xa = 'false'
  550. endif
  551. endif
  552. with_gallium_xa = _xa != 'false'
  553. d3d_drivers_path = get_option('d3d-drivers-path')
  554. if d3d_drivers_path == ''
  555. d3d_drivers_path = join_paths(get_option('libdir'), 'd3d')
  556. endif
  557. with_gallium_st_nine = get_option('gallium-nine')
  558. if with_gallium_st_nine
  559. if not with_gallium_softpipe
  560. error('The nine state tracker requires gallium softpipe/llvmpipe.')
  561. elif not (with_gallium_radeonsi or with_gallium_nouveau or with_gallium_r600
  562. or with_gallium_r300 or with_gallium_svga or with_gallium_i915)
  563. error('The nine state tracker requires at least one non-swrast gallium driver.')
  564. endif
  565. if not with_dri3
  566. error('Using nine with wine requires dri3')
  567. endif
  568. endif
  569. if get_option('power8') != 'false'
  570. # on old versions of meson the cpu family would return as ppc64le on little
  571. # endian power8, this was changed in 0.48 such that the family would always
  572. # be ppc64 regardless of endianness, and the the machine.endian() value
  573. # should be checked. Since we support versions < 0.48 we need to use
  574. # startswith.
  575. if host_machine.cpu_family().startswith('ppc64') and host_machine.endian() == 'little'
  576. if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.8')
  577. error('Altivec is not supported with gcc version < 4.8.')
  578. endif
  579. if cc.compiles('''
  580. #include <altivec.h>
  581. int main() {
  582. vector unsigned char r;
  583. vector unsigned int v = vec_splat_u32 (1);
  584. r = __builtin_vec_vgbbd ((vector unsigned char) v);
  585. return 0;
  586. }''',
  587. args : '-mpower8-vector',
  588. name : 'POWER8 intrinsics')
  589. pre_args += ['-D_ARCH_PWR8', '-mpower8-vector']
  590. elif get_option('power8') == 'true'
  591. error('POWER8 intrinsic support required but not found.')
  592. endif
  593. endif
  594. endif
  595. _opencl = get_option('gallium-opencl')
  596. clover_cpp_std = []
  597. if _opencl != 'disabled'
  598. if not with_gallium
  599. error('OpenCL Clover implementation requires at least one gallium driver.')
  600. endif
  601. dep_clc = dependency('libclc')
  602. with_gallium_opencl = true
  603. with_opencl_icd = _opencl == 'icd'
  604. if host_machine.cpu_family().startswith('ppc') and cpp.compiles('''
  605. #if !defined(__VEC__) || !defined(__ALTIVEC__)
  606. #error "AltiVec not enabled"
  607. #endif''',
  608. name : 'Altivec')
  609. clover_cpp_std += ['cpp_std=gnu++11']
  610. endif
  611. else
  612. dep_clc = null_dep
  613. with_gallium_opencl = false
  614. with_opencl_icd = false
  615. endif
  616. gl_pkgconfig_c_flags = []
  617. if with_platform_x11
  618. if with_any_vk or with_egl or (with_glx == 'dri' and with_dri_platform == 'drm')
  619. pre_args += '-DHAVE_X11_PLATFORM'
  620. endif
  621. if with_glx == 'xlib' or with_glx == 'gallium-xlib'
  622. pre_args += '-DUSE_XSHM'
  623. else
  624. pre_args += '-DGLX_INDIRECT_RENDERING'
  625. if with_glx_direct
  626. pre_args += '-DGLX_DIRECT_RENDERING'
  627. endif
  628. if with_dri_platform == 'drm'
  629. pre_args += '-DGLX_USE_DRM'
  630. elif with_dri_platform == 'apple'
  631. pre_args += '-DGLX_USE_APPLEGL'
  632. elif with_dri_platform == 'windows'
  633. pre_args += '-DGLX_USE_WINDOWSGL'
  634. endif
  635. endif
  636. else
  637. pre_args += '-DMESA_EGL_NO_X11_HEADERS'
  638. gl_pkgconfig_c_flags += '-DMESA_EGL_NO_X11_HEADERS'
  639. endif
  640. if with_platform_drm
  641. if with_egl and not with_gbm
  642. error('EGL drm platform requires gbm')
  643. endif
  644. pre_args += '-DHAVE_DRM_PLATFORM'
  645. endif
  646. if with_platform_surfaceless
  647. pre_args += '-DHAVE_SURFACELESS_PLATFORM'
  648. endif
  649. if with_platform_android
  650. dep_android = [
  651. dependency('cutils'),
  652. dependency('hardware'),
  653. dependency('sync'),
  654. ]
  655. pre_args += '-DHAVE_ANDROID_PLATFORM'
  656. endif
  657. if with_platform_haiku
  658. pre_args += '-DHAVE_HAIKU_PLATFORM'
  659. endif
  660. prog_python = import('python3').find_python()
  661. has_mako = run_command(
  662. prog_python, '-c',
  663. '''
  664. from distutils.version import StrictVersion
  665. import mako
  666. assert StrictVersion(mako.__version__) > StrictVersion("0.8.0")
  667. ''')
  668. if has_mako.returncode() != 0
  669. error('Python (3.x) mako module >= 0.8.0 required to build mesa.')
  670. endif
  671. if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
  672. error('When using GCC, version 4.4.6 or later is required.')
  673. endif
  674. # Define DEBUG for debug builds only (debugoptimized is not included on this one)
  675. if get_option('buildtype') == 'debug'
  676. pre_args += '-DDEBUG'
  677. endif
  678. if get_option('shader-cache')
  679. pre_args += '-DENABLE_SHADER_CACHE'
  680. elif with_amd_vk
  681. error('Radv requires shader cache support')
  682. endif
  683. # Check for GCC style builtins
  684. foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
  685. 'ffsll', 'popcount', 'popcountll', 'unreachable']
  686. if cc.has_function(b)
  687. pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
  688. endif
  689. endforeach
  690. # check for GCC __attribute__
  691. foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
  692. 'warn_unused_result', 'weak',]
  693. if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
  694. name : '__attribute__((@0@))'.format(a))
  695. pre_args += '-DHAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper())
  696. endif
  697. endforeach
  698. if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
  699. name : '__attribute__((format(...)))')
  700. pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
  701. endif
  702. if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
  703. name : '__attribute__((packed))')
  704. pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
  705. endif
  706. if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
  707. name : '__attribute__((returns_nonnull))')
  708. pre_args += '-DHAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL'
  709. endif
  710. if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
  711. int foo_hid(void) __attribute__((visibility("hidden")));
  712. int foo_int(void) __attribute__((visibility("internal")));
  713. int foo_pro(void) __attribute__((visibility("protected")));''',
  714. name : '__attribute__((visibility(...)))')
  715. pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISIBILITY'
  716. endif
  717. if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
  718. name : '__attribute__((alias(...)))')
  719. pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
  720. endif
  721. if cc.compiles('int foo(void) __attribute__((__noreturn__));',
  722. name : '__attribute__((__noreturn__))')
  723. pre_args += '-DHAVE_FUNC_ATTRIBUTE_NORETURN'
  724. endif
  725. # TODO: this is very incomplete
  726. if ['linux', 'cygwin', 'gnu'].contains(host_machine.system())
  727. pre_args += '-D_GNU_SOURCE'
  728. endif
  729. # Check for generic C arguments
  730. c_args = []
  731. foreach a : ['-Werror=implicit-function-declaration',
  732. '-Werror=missing-prototypes', '-Werror=return-type',
  733. '-fno-math-errno',
  734. '-fno-trapping-math', '-Qunused-arguments']
  735. if cc.has_argument(a)
  736. c_args += a
  737. endif
  738. endforeach
  739. foreach a : ['missing-field-initializers', 'format-truncation']
  740. if cc.has_argument('-W' + a)
  741. c_args += '-Wno-' + a
  742. endif
  743. endforeach
  744. c_vis_args = []
  745. if cc.has_argument('-fvisibility=hidden')
  746. c_vis_args += '-fvisibility=hidden'
  747. endif
  748. # Check for generic C++ arguments
  749. cpp_args = []
  750. foreach a : ['-Werror=return-type',
  751. '-fno-math-errno', '-fno-trapping-math',
  752. '-Qunused-arguments']
  753. if cpp.has_argument(a)
  754. cpp_args += a
  755. endif
  756. endforeach
  757. # For some reason, the test for -Wno-foo always succeeds with gcc, even if the
  758. # option is not supported. Hence, check for -Wfoo instead.
  759. foreach a : ['non-virtual-dtor', 'missing-field-initializers', 'format-truncation']
  760. if cpp.has_argument('-W' + a)
  761. cpp_args += '-Wno-' + a
  762. endif
  763. endforeach
  764. no_override_init_args = []
  765. foreach a : ['override-init', 'initializer-overrides']
  766. if cc.has_argument('-W' + a)
  767. no_override_init_args += '-Wno-' + a
  768. endif
  769. endforeach
  770. cpp_vis_args = []
  771. if cpp.has_argument('-fvisibility=hidden')
  772. cpp_vis_args += '-fvisibility=hidden'
  773. endif
  774. # Check for C and C++ arguments for MSVC2013 compatibility. These are only used
  775. # in parts of the mesa code base that need to compile with old versions of
  776. # MSVC, mainly common code
  777. c_msvc_compat_args = []
  778. cpp_msvc_compat_args = []
  779. foreach a : ['-Werror=pointer-arith', '-Werror=vla']
  780. if cc.has_argument(a)
  781. c_msvc_compat_args += a
  782. endif
  783. if cpp.has_argument(a)
  784. cpp_msvc_compat_args += a
  785. endif
  786. endforeach
  787. if host_machine.cpu_family().startswith('x86')
  788. pre_args += '-DUSE_SSE41'
  789. with_sse41 = true
  790. sse41_args = ['-msse4.1']
  791. # GCC on x86 (not x86_64) with -msse* assumes a 16 byte aligned stack, but
  792. # that's not guaranteed
  793. if host_machine.cpu_family() == 'x86'
  794. sse41_args += '-mstackrealign'
  795. endif
  796. else
  797. with_sse41 = false
  798. sse41_args = []
  799. endif
  800. # Check for GCC style atomics
  801. dep_atomic = null_dep
  802. if cc.compiles('''#include <stdint.h>
  803. int main() {
  804. struct {
  805. uint64_t *v;
  806. } x;
  807. return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
  808. (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
  809. }''',
  810. name : 'GCC atomic builtins')
  811. pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
  812. # Not all atomic calls can be turned into lock-free instructions, in which
  813. # GCC will make calls into the libatomic library. Check whether we need to
  814. # link with -latomic.
  815. #
  816. # This can happen for 64-bit atomic operations on 32-bit architectures such
  817. # as ARM.
  818. if not cc.links('''#include <stdint.h>
  819. int main() {
  820. struct {
  821. uint64_t *v;
  822. } x;
  823. return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
  824. (int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
  825. }''',
  826. name : 'GCC atomic builtins required -latomic')
  827. dep_atomic = cc.find_library('atomic')
  828. endif
  829. endif
  830. if not cc.links('''#include <stdint.h>
  831. uint64_t v;
  832. int main() {
  833. return __sync_add_and_fetch(&v, (uint64_t)1);
  834. }''',
  835. dependencies : dep_atomic,
  836. name : 'GCC 64bit atomics')
  837. pre_args += '-DMISSING_64BIT_ATOMICS'
  838. endif
  839. # TODO: shared/static? Is this even worth doing?
  840. # When cross compiling we generally need to turn off the use of assembly,
  841. # because mesa's assembly relies on building an executable for the host system,
  842. # and running it to get information about struct sizes. There is at least one
  843. # case of cross compiling where we can use asm, and that's x86_64 -> x86 when
  844. # host OS == build OS, since in that case the build machine can run the host's
  845. # binaries.
  846. if with_asm and meson.is_cross_build()
  847. if build_machine.system() != host_machine.system()
  848. # TODO: It may be possible to do this with an exe_wrapper (like wine).
  849. message('Cross compiling from one OS to another, disabling assembly.')
  850. with_asm = false
  851. elif not (build_machine.cpu_family().startswith('x86') and host_machine.cpu_family() == 'x86')
  852. # FIXME: Gentoo always sets -m32 for x86_64 -> x86 builds, resulting in an
  853. # x86 -> x86 cross compile. We use startswith rather than == to handle this
  854. # case.
  855. # TODO: There may be other cases where the 64 bit version of the
  856. # architecture can run 32 bit binaries (aarch64 and armv7 for example)
  857. message('''
  858. Cross compiling to different architectures, and the host cannot run
  859. the build machine's binaries. Disabling assembly.
  860. ''')
  861. with_asm = false
  862. endif
  863. endif
  864. with_asm_arch = ''
  865. if with_asm
  866. if host_machine.cpu_family() == 'x86'
  867. if system_has_kms_drm or host_machine.system() == 'gnu'
  868. with_asm_arch = 'x86'
  869. pre_args += ['-DUSE_X86_ASM', '-DUSE_MMX_ASM', '-DUSE_3DNOW_ASM',
  870. '-DUSE_SSE_ASM']
  871. if with_glx_read_only_text
  872. pre_args += ['-DGLX_X86_READONLY_TEXT']
  873. endif
  874. endif
  875. elif host_machine.cpu_family() == 'x86_64'
  876. if system_has_kms_drm
  877. with_asm_arch = 'x86_64'
  878. pre_args += ['-DUSE_X86_64_ASM']
  879. endif
  880. elif host_machine.cpu_family() == 'arm'
  881. if system_has_kms_drm
  882. with_asm_arch = 'arm'
  883. pre_args += ['-DUSE_ARM_ASM']
  884. endif
  885. elif host_machine.cpu_family() == 'aarch64'
  886. if system_has_kms_drm
  887. with_asm_arch = 'aarch64'
  888. pre_args += ['-DUSE_AARCH64_ASM']
  889. endif
  890. elif host_machine.cpu_family() == 'sparc64'
  891. if system_has_kms_drm
  892. with_asm_arch = 'sparc'
  893. pre_args += ['-DUSE_SPARC_ASM']
  894. endif
  895. elif host_machine.cpu_family().startswith('ppc64') and host_machine.endian() == 'little'
  896. if system_has_kms_drm
  897. with_asm_arch = 'ppc64le'
  898. pre_args += ['-DUSE_PPC64LE_ASM']
  899. endif
  900. endif
  901. endif
  902. # Check for standard headers and functions
  903. if cc.has_header_symbol('sys/sysmacros.h', 'major')
  904. pre_args += '-DMAJOR_IN_SYSMACROS'
  905. elif cc.has_header_symbol('sys/mkdev.h', 'major')
  906. pre_args += '-DMAJOR_IN_MKDEV'
  907. endif
  908. foreach h : ['xlocale.h', 'sys/sysctl.h', 'linux/futex.h', 'endian.h', 'dlfcn.h']
  909. if cc.compiles('#include <@0@>'.format(h), name : '@0@'.format(h))
  910. pre_args += '-DHAVE_@0@'.format(h.to_upper().underscorify())
  911. endif
  912. endforeach
  913. foreach f : ['strtof', 'mkostemp', 'posix_memalign', 'timespec_get', 'memfd_create']
  914. if cc.has_function(f)
  915. pre_args += '-DHAVE_@0@'.format(f.to_upper())
  916. endif
  917. endforeach
  918. # strtod locale support
  919. if cc.links('''
  920. #define _GNU_SOURCE
  921. #include <stdlib.h>
  922. #include <locale.h>
  923. #ifdef HAVE_XLOCALE_H
  924. #include <xlocale.h>
  925. #endif
  926. int main() {
  927. locale_t loc = newlocale(LC_CTYPE_MASK, "C", NULL);
  928. const char *s = "1.0";
  929. char *end;
  930. double d = strtod_l(s, end, loc);
  931. float f = strtof_l(s, end, loc);
  932. freelocale(loc);
  933. return 0;
  934. }''',
  935. args : pre_args,
  936. name : 'strtod has locale support')
  937. pre_args += '-DHAVE_STRTOD_L'
  938. endif
  939. # Check for some linker flags
  940. ld_args_bsymbolic = []
  941. if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic')
  942. ld_args_bsymbolic += '-Wl,-Bsymbolic'
  943. endif
  944. ld_args_gc_sections = []
  945. if cc.links('static char unused() { return 5; } int main() { return 0; }',
  946. args : '-Wl,--gc-sections', name : 'gc-sections')
  947. ld_args_gc_sections += '-Wl,--gc-sections'
  948. endif
  949. with_ld_version_script = false
  950. if cc.links('int main() { return 0; }',
  951. args : '-Wl,--version-script=@0@'.format(
  952. join_paths(meson.source_root(), 'build-support/conftest.map')),
  953. name : 'version-script')
  954. with_ld_version_script = true
  955. endif
  956. with_ld_dynamic_list = false
  957. if cc.links('int main() { return 0; }',
  958. args : '-Wl,--dynamic-list=@0@'.format(
  959. join_paths(meson.source_root(), 'build-support/conftest.dyn')),
  960. name : 'dynamic-list')
  961. with_ld_dynamic_list = true
  962. endif
  963. ld_args_build_id = []
  964. if build_machine.system() != 'darwin'
  965. ld_args_build_id += '-Wl,--build-id=sha1'
  966. endif
  967. # check for dl support
  968. if cc.has_function('dlopen')
  969. dep_dl = null_dep
  970. else
  971. dep_dl = cc.find_library('dl')
  972. endif
  973. if cc.has_function('dladdr', dependencies : dep_dl)
  974. # This is really only required for megadrivers
  975. pre_args += '-DHAVE_DLADDR'
  976. endif
  977. if cc.has_function('dl_iterate_phdr')
  978. pre_args += '-DHAVE_DL_ITERATE_PHDR'
  979. elif with_intel_vk
  980. error('Intel "Anvil" Vulkan driver requires the dl_iterate_phdr function')
  981. elif with_dri_i965 and get_option('shader-cache')
  982. error('Intel i965 GL driver requires dl_iterate_phdr when built with shader caching.')
  983. endif
  984. # Determine whether or not the rt library is needed for time functions
  985. if cc.has_function('clock_gettime')
  986. dep_clock = null_dep
  987. else
  988. dep_clock = cc.find_library('rt')
  989. endif
  990. # TODO: some of these may be conditional
  991. dep_zlib = dependency('zlib', version : '>= 1.2.3')
  992. pre_args += '-DHAVE_ZLIB'
  993. dep_thread = dependency('threads')
  994. if dep_thread.found() and host_machine.system() != 'windows'
  995. pre_args += '-DHAVE_PTHREAD'
  996. if cc.has_function(
  997. 'pthread_setaffinity_np',
  998. dependencies : dep_thread,
  999. prefix : '#include <pthread.h>',
  1000. args : '-D_GNU_SOURCE')
  1001. pre_args += '-DHAVE_PTHREAD_SETAFFINITY'
  1002. endif
  1003. endif
  1004. dep_expat = dependency('expat')
  1005. # this only exists on linux so either this is linux and it will be found, or
  1006. # its not linux and and wont
  1007. dep_m = cc.find_library('m', required : false)
  1008. # Check for libdrm. various drivers have different libdrm version requirements,
  1009. # but we always want to use the same version for all libdrm modules. That means
  1010. # even if driver foo requires 2.4.0 and driver bar requires 2.4.3, if foo and
  1011. # bar are both on use 2.4.3 for both of them
  1012. dep_libdrm_amdgpu = null_dep
  1013. dep_libdrm_radeon = null_dep
  1014. dep_libdrm_nouveau = null_dep
  1015. dep_libdrm_etnaviv = null_dep
  1016. dep_libdrm_intel = null_dep
  1017. _drm_amdgpu_ver = '2.4.95'
  1018. _drm_radeon_ver = '2.4.71'
  1019. _drm_nouveau_ver = '2.4.66'
  1020. _drm_etnaviv_ver = '2.4.89'
  1021. _drm_intel_ver = '2.4.75'
  1022. _drm_ver = '2.4.75'
  1023. _libdrm_checks = [
  1024. ['intel', with_dri_i915 or with_gallium_i915],
  1025. ['amdgpu', with_amd_vk or with_gallium_radeonsi],
  1026. ['radeon', (with_gallium_radeonsi or with_dri_r100 or with_dri_r200 or
  1027. with_gallium_r300 or with_gallium_r600)],
  1028. ['nouveau', (with_gallium_nouveau or with_dri_nouveau)],
  1029. ['etnaviv', with_gallium_etnaviv],
  1030. ]
  1031. # VC4 only needs core libdrm support of this version, not a libdrm_vc4
  1032. # library.
  1033. if with_gallium_vc4
  1034. _drm_ver = '2.4.89'
  1035. endif
  1036. # Loop over the enables versions and get the highest libdrm requirement for all
  1037. # active drivers.
  1038. _drm_blame = ''
  1039. foreach d : _libdrm_checks
  1040. ver = get_variable('_drm_@0@_ver'.format(d[0]))
  1041. if d[1] and ver.version_compare('>' + _drm_ver)
  1042. _drm_ver = ver
  1043. _drm_blame = d[0]
  1044. endif
  1045. endforeach
  1046. if _drm_blame != ''
  1047. message('libdrm @0@ needed because @1@ has the highest requirement'.format(_drm_ver, _drm_blame))
  1048. endif
  1049. # Then get each libdrm module
  1050. foreach d : _libdrm_checks
  1051. if d[1]
  1052. set_variable(
  1053. 'dep_libdrm_' + d[0],
  1054. dependency('libdrm_' + d[0], version : '>=' + _drm_ver)
  1055. )
  1056. endif
  1057. endforeach
  1058. with_gallium_drisw_kms = false
  1059. dep_libdrm = dependency(
  1060. 'libdrm', version : '>=' + _drm_ver,
  1061. required : with_dri2 or with_dri3
  1062. )
  1063. if dep_libdrm.found()
  1064. pre_args += '-DHAVE_LIBDRM'
  1065. if with_dri_platform == 'drm' and with_dri
  1066. with_gallium_drisw_kms = true
  1067. endif
  1068. endif
  1069. llvm_modules = ['bitwriter', 'engine', 'mcdisassembler', 'mcjit']
  1070. llvm_optional_modules = []
  1071. if with_amd_vk or with_gallium_radeonsi or with_gallium_r600
  1072. llvm_modules += ['amdgpu', 'native', 'bitreader', 'ipo']
  1073. if with_gallium_r600
  1074. llvm_modules += 'asmparser'
  1075. endif
  1076. endif
  1077. if with_gallium_opencl
  1078. llvm_modules += [
  1079. 'all-targets', 'linker', 'coverage', 'instrumentation', 'ipo', 'irreader',
  1080. 'lto', 'option', 'objcarcopts', 'profiledata',
  1081. ]
  1082. llvm_optional_modules += ['coroutines']
  1083. endif
  1084. if with_amd_vk or with_gallium_radeonsi
  1085. _llvm_version = '>= 7.0.0'
  1086. elif with_gallium_swr
  1087. _llvm_version = '>= 6.0.0'
  1088. elif with_gallium_opencl or with_gallium_r600
  1089. _llvm_version = '>= 3.9.0'
  1090. else
  1091. _llvm_version = '>= 3.3.0'
  1092. endif
  1093. _shared_llvm = get_option('shared-llvm')
  1094. _llvm = get_option('llvm')
  1095. dep_llvm = null_dep
  1096. with_llvm = false
  1097. if _llvm != 'false'
  1098. dep_llvm = dependency(
  1099. 'llvm',
  1100. version : _llvm_version,
  1101. modules : llvm_modules,
  1102. optional_modules : llvm_optional_modules,
  1103. required : (
  1104. with_amd_vk or with_gallium_radeonsi or with_gallium_swr or
  1105. with_gallium_opencl or _llvm == 'true'
  1106. ),
  1107. static : not _shared_llvm,
  1108. )
  1109. with_llvm = dep_llvm.found()
  1110. endif
  1111. if with_llvm
  1112. _llvm_version = dep_llvm.version().split('.')
  1113. # 3 digits versions in LLVM only started from 3.4.1 on
  1114. if dep_llvm.version().version_compare('>= 3.4.1')
  1115. _llvm_patch = _llvm_version[2]
  1116. else
  1117. _llvm_patch = '0'
  1118. endif
  1119. pre_args += [
  1120. '-DHAVE_LLVM=0x0@0@0@1@'.format(_llvm_version[0], _llvm_version[1]),
  1121. '-DMESA_LLVM_VERSION_PATCH=@0@'.format(_llvm_patch),
  1122. ]
  1123. # LLVM can be built without rtti, turning off rtti changes the ABI of C++
  1124. # programs, so we need to build all C++ code in mesa without rtti as well to
  1125. # ensure that linking works.
  1126. if dep_llvm.get_configtool_variable('has-rtti') == 'NO'
  1127. if with_gallium_nouveau
  1128. error('The Nouveau driver requires rtti. You either need to turn off nouveau or use an LLVM built with LLVM_ENABLE_RTTI.')
  1129. endif
  1130. cpp_args += '-fno-rtti'
  1131. endif
  1132. elif with_amd_vk or with_gallium_radeonsi or with_gallium_swr
  1133. error('The following drivers require LLVM: Radv, RadeonSI, SWR. One of these is enabled, but LLVM is disabled.')
  1134. endif
  1135. if (with_amd_vk or with_gallium_radeonsi or with_gallium_opencl or
  1136. (with_gallium_r600 and with_llvm))
  1137. dep_elf = dependency('libelf', required : false)
  1138. if not dep_elf.found()
  1139. dep_elf = cc.find_library('elf')
  1140. endif
  1141. else
  1142. dep_elf = null_dep
  1143. endif
  1144. dep_glvnd = null_dep
  1145. if with_glvnd
  1146. dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
  1147. pre_args += '-DUSE_LIBGLVND=1'
  1148. endif
  1149. if with_valgrind != 'false'
  1150. dep_valgrind = dependency('valgrind', required : with_valgrind == 'true')
  1151. if dep_valgrind.found()
  1152. pre_args += '-DHAVE_VALGRIND'
  1153. endif
  1154. else
  1155. dep_valgrind = null_dep
  1156. endif
  1157. # pthread stubs. Lets not and say we didn't
  1158. prog_bison = find_program('bison', required : with_any_opengl)
  1159. prog_flex = find_program('flex', required : with_any_opengl)
  1160. dep_selinux = null_dep
  1161. if get_option('selinux')
  1162. dep_selinux = dependency('libselinux')
  1163. pre_args += '-DMESA_SELINUX'
  1164. endif
  1165. if with_libunwind != 'false'
  1166. dep_unwind = dependency('libunwind', required : with_libunwind == 'true')
  1167. if dep_unwind.found()
  1168. pre_args += '-DHAVE_LIBUNWIND'
  1169. endif
  1170. else
  1171. dep_unwind = null_dep
  1172. endif
  1173. if with_osmesa != 'none'
  1174. if with_osmesa == 'classic' and not with_dri_swrast
  1175. error('OSMesa classic requires dri (classic) swrast.')
  1176. endif
  1177. if with_osmesa == 'gallium' and not with_gallium_softpipe
  1178. error('OSMesa gallium requires gallium softpipe or llvmpipe.')
  1179. endif
  1180. osmesa_lib_name = 'OSMesa'
  1181. osmesa_bits = get_option('osmesa-bits')
  1182. if osmesa_bits != '8'
  1183. if with_dri or with_glx != 'disabled'
  1184. error('OSMesa bits must be 8 if building glx or dir based drivers')
  1185. endif
  1186. osmesa_lib_name = osmesa_lib_name + osmesa_bits
  1187. pre_args += [
  1188. '-DCHAN_BITS=@0@'.format(osmesa_bits), '-DDEFAULT_SOFTWARE_DEPTH_BITS=31'
  1189. ]
  1190. endif
  1191. endif
  1192. # TODO: symbol mangling
  1193. if with_platform_wayland
  1194. dep_wl_scanner = dependency('wayland-scanner', native: true)
  1195. prog_wl_scanner = find_program(dep_wl_scanner.get_pkgconfig_variable('wayland_scanner'))
  1196. if dep_wl_scanner.version().version_compare('>= 1.15')
  1197. wl_scanner_arg = 'private-code'
  1198. else
  1199. wl_scanner_arg = 'code'
  1200. endif
  1201. dep_wl_protocols = dependency('wayland-protocols', version : '>= 1.8')
  1202. dep_wayland_client = dependency('wayland-client', version : '>=1.11')
  1203. dep_wayland_server = dependency('wayland-server', version : '>=1.11')
  1204. if with_egl
  1205. dep_wayland_egl = dependency('wayland-egl-backend', version : '>= 3')
  1206. dep_wayland_egl_headers = declare_dependency(
  1207. compile_args : run_command(prog_pkgconfig, ['wayland-egl-backend', '--cflags']).stdout().split())
  1208. endif
  1209. wayland_dmabuf_xml = join_paths(
  1210. dep_wl_protocols.get_pkgconfig_variable('pkgdatadir'), 'unstable',
  1211. 'linux-dmabuf', 'linux-dmabuf-unstable-v1.xml'
  1212. )
  1213. pre_args += ['-DHAVE_WAYLAND_PLATFORM', '-DWL_HIDE_DEPRECATED']
  1214. endif
  1215. dep_x11 = null_dep
  1216. dep_xext = null_dep
  1217. dep_xdamage = null_dep
  1218. dep_xfixes = null_dep
  1219. dep_x11_xcb = null_dep
  1220. dep_xcb = null_dep
  1221. dep_xcb_glx = null_dep
  1222. dep_xcb_dri2 = null_dep
  1223. dep_xcb_dri3 = null_dep
  1224. dep_dri2proto = null_dep
  1225. dep_glproto = null_dep
  1226. dep_xxf86vm = null_dep
  1227. dep_xcb_dri3 = null_dep
  1228. dep_xcb_present = null_dep
  1229. dep_xcb_sync = null_dep
  1230. dep_xcb_xfixes = null_dep
  1231. dep_xshmfence = null_dep
  1232. dep_xcb_xrandr = null_dep
  1233. dep_xlib_xrandr = null_dep
  1234. if with_platform_x11
  1235. if with_glx == 'xlib' or with_glx == 'gallium-xlib'
  1236. dep_x11 = dependency('x11')
  1237. dep_xext = dependency('xext')
  1238. dep_xcb = dependency('xcb')
  1239. elif with_glx == 'dri'
  1240. dep_x11 = dependency('x11')
  1241. dep_xext = dependency('xext')
  1242. dep_xdamage = dependency('xdamage', version : '>= 1.1')
  1243. dep_xfixes = dependency('xfixes')
  1244. dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
  1245. endif
  1246. if (with_any_vk or with_glx == 'dri' or with_egl or
  1247. (with_gallium_vdpau or with_gallium_xvmc or with_gallium_va or
  1248. with_gallium_omx != 'disabled'))
  1249. dep_xcb = dependency('xcb')
  1250. dep_x11_xcb = dependency('x11-xcb')
  1251. endif
  1252. if with_any_vk or with_egl or (with_glx == 'dri' and with_dri_platform == 'drm')
  1253. dep_xcb_dri2 = dependency('xcb-dri2', version : '>= 1.8')
  1254. if with_dri3
  1255. pre_args += '-DHAVE_DRI3'
  1256. dep_xcb_dri3 = dependency('xcb-dri3')
  1257. dep_xcb_present = dependency('xcb-present')
  1258. # until xcb-dri3 has been around long enough to make a hard-dependency:
  1259. if (dep_xcb_dri3.version().version_compare('>= 1.13') and
  1260. dep_xcb_present.version().version_compare('>= 1.13'))
  1261. pre_args += '-DHAVE_DRI3_MODIFIERS'
  1262. endif
  1263. dep_xcb_sync = dependency('xcb-sync')
  1264. dep_xshmfence = dependency('xshmfence', version : '>= 1.1')
  1265. endif
  1266. endif
  1267. if with_glx == 'dri'
  1268. if with_dri_platform == 'drm'
  1269. dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
  1270. dep_xxf86vm = dependency('xxf86vm')
  1271. endif
  1272. dep_glproto = dependency('glproto', version : '>= 1.4.14')
  1273. endif
  1274. if (with_egl or (
  1275. with_gallium_vdpau or with_gallium_xvmc or with_gallium_xa or
  1276. with_gallium_omx != 'disabled'))
  1277. dep_xcb_xfixes = dependency('xcb-xfixes')
  1278. endif
  1279. if with_xlib_lease
  1280. dep_xcb_xrandr = dependency('xcb-randr', version : '>= 1.12')
  1281. dep_xlib_xrandr = dependency('xrandr', version : '>= 1.3')
  1282. endif
  1283. endif
  1284. if get_option('gallium-extra-hud')
  1285. pre_args += '-DHAVE_GALLIUM_EXTRA_HUD=1'
  1286. endif
  1287. _sensors = get_option('lmsensors')
  1288. if _sensors != 'false'
  1289. dep_lmsensors = cc.find_library('sensors', required : _sensors == 'true')
  1290. if dep_lmsensors.found()
  1291. pre_args += '-DHAVE_LIBSENSORS=1'
  1292. endif
  1293. else
  1294. dep_lmsensors = null_dep
  1295. endif
  1296. foreach a : pre_args
  1297. add_project_arguments(a, language : ['c', 'cpp'])
  1298. endforeach
  1299. foreach a : c_args
  1300. add_project_arguments(a, language : ['c'])
  1301. endforeach
  1302. foreach a : cpp_args
  1303. add_project_arguments(a, language : ['cpp'])
  1304. endforeach
  1305. inc_include = include_directories('include')
  1306. gl_priv_reqs = []
  1307. if with_glx == 'xlib' or with_glx == 'gallium-xlib'
  1308. gl_priv_reqs += ['x11', 'xext', 'xcb']
  1309. elif with_glx == 'dri'
  1310. gl_priv_reqs += [
  1311. 'x11', 'xext', 'xdamage >= 1.1', 'xfixes', 'x11-xcb', 'xcb',
  1312. 'xcb-glx >= 1.8.1']
  1313. if with_dri_platform == 'drm'
  1314. gl_priv_reqs += 'xcb-dri2 >= 1.8'
  1315. gl_priv_reqs += 'xxf86vm'
  1316. endif
  1317. endif
  1318. if dep_libdrm.found()
  1319. gl_priv_reqs += 'libdrm >= 2.4.75'
  1320. endif
  1321. gl_priv_libs = []
  1322. if dep_thread.found()
  1323. gl_priv_libs += ['-lpthread', '-pthread']
  1324. endif
  1325. if dep_m.found()
  1326. gl_priv_libs += '-lm'
  1327. endif
  1328. if dep_dl.found()
  1329. gl_priv_libs += '-ldl'
  1330. endif
  1331. pkg = import('pkgconfig')
  1332. env_test = environment()
  1333. env_test.set('NM', find_program('nm').path())
  1334. subdir('include')
  1335. subdir('bin')
  1336. subdir('src')