Clone of mesa.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

meson.build 47KB

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