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 47KB

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