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

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