meson.build 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. # Copyright © 2017-2018 Intel Corporation
  2. # Permission is hereby granted, free of charge, to any person obtaining a copy
  3. # of this software and associated documentation files (the "Software"), to deal
  4. # in the Software without restriction, including without limitation the rights
  5. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6. # copies of the Software, and to permit persons to whom the Software is
  7. # furnished to do so, subject to the following conditions:
  8. # The above copyright notice and this permission notice shall be included in
  9. # all copies or substantial portions of the Software.
  10. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  14. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  15. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. # SOFTWARE.
  17. # The versioning should always stay at 2.4.x. If bumping away from this,
  18. # you must ensure that all users of patch_ver are changed such that DSO versions
  19. # continuously increment (e.g. blindly bumping from 2.4.122 to 2.5.0 would
  20. # roll the libdrm DSO versioning from libdrm.so.2.122.0 back to libdrm.so.2.0.0
  21. # which would be bad)
  22. project(
  23. 'libdrm',
  24. ['c'],
  25. version : '2.4.134',
  26. license : 'MIT',
  27. meson_version : '>= 0.59',
  28. default_options : ['buildtype=debugoptimized', 'c_std=c11'],
  29. )
  30. patch_ver = meson.project_version().split('.')[2]
  31. if ['windows', 'darwin'].contains(host_machine.system())
  32. error('unsupported OS: @0@'.format(host_machine.system()))
  33. endif
  34. pkg = import('pkgconfig')
  35. config = configuration_data()
  36. config.set10('UDEV', get_option('udev'))
  37. with_install_tests = get_option('install-test-programs')
  38. with_tests = get_option('tests')
  39. dep_threads = dependency('threads')
  40. cc = meson.get_compiler('c')
  41. config.set10('HAVE_SECURE_GETENV', cc.has_function('secure_getenv'))
  42. android = cc.compiles('''int func() { return __ANDROID__; }''')
  43. # Solaris / Illumos
  44. if host_machine.system() == 'sunos'
  45. add_global_arguments('-D__EXTENSIONS__', language : 'c')
  46. add_global_arguments('-D_POSIX_C_SOURCE=3', language : 'c')
  47. endif
  48. symbols_check = find_program('symbols-check.py')
  49. prog_nm = find_program('nm')
  50. # Check for atomics
  51. intel_atomics = false
  52. lib_atomics = false
  53. python3 = import('python').find_installation()
  54. format_mod_static_table = custom_target(
  55. 'format_mod_static_table',
  56. output : 'generated_static_table_fourcc.h',
  57. input : 'include/drm/drm_fourcc.h',
  58. command : [python3, files('gen_table_fourcc.py'), '@INPUT@', '@OUTPUT@'])
  59. dep_atomic_ops = dependency('atomic_ops', required : false)
  60. if cc.links('''
  61. int atomic_add(int *i) { return __sync_add_and_fetch (i, 1); }
  62. int atomic_cmpxchg(int *i, int j, int k) { return __sync_val_compare_and_swap (i, j, k); }
  63. int main() { }
  64. ''',
  65. name : 'Intel Atomics')
  66. intel_atomics = true
  67. with_atomics = true
  68. dep_atomic_ops = []
  69. elif dep_atomic_ops.found()
  70. lib_atomics = true
  71. with_atomics = true
  72. elif cc.has_function('atomic_cas_uint')
  73. with_atomics = true
  74. else
  75. with_atomics = false
  76. endif
  77. config.set10('HAVE_LIBDRM_ATOMIC_PRIMITIVES', intel_atomics)
  78. config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics)
  79. dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : get_option('intel'))
  80. with_intel = get_option('intel') \
  81. .require(with_atomics, error_message : 'libdrm_intel requires atomics') \
  82. .require(dep_pciaccess.found(), error_message : 'libdrm_intel requires libpciaccess') \
  83. .disable_auto_if(not host_machine.cpu_family().startswith('x86')) \
  84. .allowed()
  85. summary('Intel', with_intel)
  86. with_radeon = get_option('radeon') \
  87. .require(with_atomics, error_message : 'libdrm_radeon requires atomics') \
  88. .allowed()
  89. summary('Radeon', with_radeon)
  90. with_amdgpu = get_option('amdgpu') \
  91. .require(with_atomics, error_message : 'libdrm_amdgpu requires atomics') \
  92. .allowed()
  93. summary('AMDGPU', with_amdgpu)
  94. with_nouveau = get_option('nouveau') \
  95. .require(with_atomics, error_message : 'libdrm_nouveau requires atomics') \
  96. .allowed()
  97. summary('Nouveau', with_nouveau)
  98. with_vmwgfx = get_option('vmwgfx').allowed()
  99. summary('vmwgfx', with_vmwgfx)
  100. with_omap = get_option('omap') \
  101. .require(with_atomics, error_message : 'libdrm_omap requires atomics') \
  102. .enabled()
  103. summary('OMAP', with_omap)
  104. with_tegra = get_option('tegra') \
  105. .require(with_atomics, error_message : 'libdrm_tegra requires atomics') \
  106. .disable_auto_if(not ['arm', 'aarch64'].contains(host_machine.cpu_family())) \
  107. .enabled()
  108. summary('Tegra', with_tegra)
  109. with_etnaviv = get_option('etnaviv') \
  110. .require(with_atomics, error_message : 'libdrm_etnaviv requires atomics') \
  111. .disable_auto_if(not ['arm', 'aarch64', 'arc', 'mips', 'mips64', 'loongarch64'].contains(host_machine.cpu_family())) \
  112. .allowed()
  113. summary('Etnaviv', with_etnaviv)
  114. with_exynos = get_option('exynos').enabled()
  115. summary('EXYNOS', with_exynos)
  116. with_vc4 = get_option('vc4') \
  117. .disable_auto_if(not ['arm', 'aarch64'].contains(host_machine.cpu_family())) \
  118. .allowed()
  119. summary('VC4', with_vc4)
  120. # Among others FreeBSD does not have a separate dl library.
  121. if not cc.has_function('dlsym')
  122. dep_dl = cc.find_library('dl', required : with_nouveau)
  123. else
  124. dep_dl = []
  125. endif
  126. # clock_gettime might require -rt, or it might not. find out
  127. if not cc.has_function('clock_gettime', prefix : '#define _GNU_SOURCE\n#include <time.h>')
  128. # XXX: untested
  129. dep_rt = cc.find_library('rt')
  130. else
  131. dep_rt = []
  132. endif
  133. # The header is not required on Linux, and is in fact deprecated in glibc 2.30+
  134. if host_machine.system() == 'linux'
  135. config.set10('HAVE_SYS_SYSCTL_H', false)
  136. else
  137. # From Niclas Zeising:
  138. # FreeBSD requires sys/types.h for sys/sysctl.h, so add it as part of
  139. # the includes when checking for headers.
  140. config.set10('HAVE_SYS_SYSCTL_H',
  141. cc.compiles('#include <sys/types.h>\n#include <sys/sysctl.h>', name : 'sys/sysctl.h works'))
  142. endif
  143. foreach header : ['sys/select.h', 'alloca.h']
  144. config.set10('HAVE_' + header.underscorify().to_upper(), cc.check_header(header))
  145. endforeach
  146. if (cc.has_header_symbol('sys/sysmacros.h', 'major') and
  147. cc.has_header_symbol('sys/sysmacros.h', 'minor') and
  148. cc.has_header_symbol('sys/sysmacros.h', 'makedev'))
  149. config.set10('MAJOR_IN_SYSMACROS', true)
  150. endif
  151. if (cc.has_header_symbol('sys/mkdev.h', 'major') and
  152. cc.has_header_symbol('sys/mkdev.h', 'minor') and
  153. cc.has_header_symbol('sys/mkdev.h', 'makedev'))
  154. config.set10('MAJOR_IN_MKDEV', true)
  155. endif
  156. config.set10('HAVE_OPEN_MEMSTREAM', cc.has_function('open_memstream'))
  157. libdrm_c_args = cc.get_supported_arguments([
  158. '-Wsign-compare', '-Werror=undef', '-Werror=implicit-function-declaration',
  159. '-Wpointer-arith', '-Wwrite-strings', '-Wstrict-prototypes',
  160. '-Wmissing-prototypes', '-Wmissing-declarations', '-Wnested-externs',
  161. '-Wpacked', '-Wswitch-enum', '-Wmissing-format-attribute',
  162. '-Wstrict-aliasing=2', '-Winit-self', '-Winline', '-Wshadow',
  163. '-Wdeclaration-after-statement', '-Wold-style-definition',
  164. '-Wno-unused-parameter', '-Wno-attributes', '-Wno-long-long',
  165. '-Wno-missing-field-initializers'])
  166. dep_cairo = dependency('cairo', required : get_option('cairo-tests'))
  167. with_cairo_tests = dep_cairo.found()
  168. valgrind_version = []
  169. dep_valgrind = dependency('valgrind', required : get_option('valgrind'), version : valgrind_version)
  170. with_valgrind = dep_valgrind.found()
  171. prog_rst2man = find_program('rst2man', 'rst2man.py', required: get_option('man-pages'))
  172. with_man_pages = prog_rst2man.found()
  173. config.set10('HAVE_VISIBILITY', cc.has_function_attribute('visibility:hidden'))
  174. foreach t : [
  175. [with_exynos, 'EXYNOS'],
  176. [with_intel, 'INTEL'],
  177. [with_nouveau, 'NOUVEAU'],
  178. [with_radeon, 'RADEON'],
  179. [with_vc4, 'VC4'],
  180. [with_vmwgfx, 'VMWGFX'],
  181. [with_cairo_tests, 'CAIRO'],
  182. [with_valgrind, 'VALGRIND'],
  183. ]
  184. config.set10('HAVE_@0@'.format(t[1]), t[0])
  185. endforeach
  186. config.set10('_GNU_SOURCE', true)
  187. if target_machine.endian() == 'big'
  188. config.set('HAVE_BIG_ENDIAN', 1)
  189. endif
  190. if android
  191. config.set('BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD', 1)
  192. endif
  193. config_file = configure_file(
  194. configuration : config,
  195. output : 'config.h',
  196. )
  197. add_project_arguments('-include', meson.current_build_dir() / 'config.h', language : 'c')
  198. inc_root = include_directories('.')
  199. inc_drm = include_directories('include/drm')
  200. libdrm_files = [files(
  201. 'xf86drm.c', 'xf86drmHash.c', 'xf86drmRandom.c', 'xf86drmSL.c',
  202. 'xf86drmMode.c'
  203. ),
  204. config_file, format_mod_static_table
  205. ]
  206. # Build an unversioned so on android
  207. if android
  208. libdrm_kw = {}
  209. else
  210. libdrm_kw = { 'version' : '2.@0@.0'.format(patch_ver) }
  211. endif
  212. libdrm = library(
  213. 'drm',
  214. libdrm_files,
  215. c_args : libdrm_c_args,
  216. dependencies : [dep_valgrind, dep_rt],
  217. include_directories : inc_drm,
  218. install : true,
  219. kwargs : libdrm_kw,
  220. gnu_symbol_visibility : 'hidden',
  221. )
  222. test(
  223. 'core-symbols-check',
  224. symbols_check,
  225. args : [
  226. '--lib', libdrm,
  227. '--symbols-file', files('core-symbols.txt'),
  228. '--nm', prog_nm.full_path(),
  229. ],
  230. )
  231. ext_libdrm = declare_dependency(
  232. link_with : libdrm,
  233. include_directories : [inc_root, inc_drm],
  234. )
  235. meson.override_dependency('libdrm', ext_libdrm)
  236. install_headers('libsync.h', 'xf86drm.h', 'xf86drmMode.h')
  237. install_headers(
  238. 'include/drm/drm.h', 'include/drm/drm_fourcc.h', 'include/drm/drm_mode.h',
  239. 'include/drm/drm_sarea.h', 'include/drm/i915_drm.h',
  240. 'include/drm/mach64_drm.h', 'include/drm/mga_drm.h',
  241. 'include/drm/msm_drm.h', 'include/drm/nouveau_drm.h',
  242. 'include/drm/qxl_drm.h', 'include/drm/r128_drm.h',
  243. 'include/drm/radeon_drm.h', 'include/drm/amdgpu_drm.h',
  244. 'include/drm/savage_drm.h', 'include/drm/sis_drm.h',
  245. 'include/drm/tegra_drm.h', 'include/drm/vc4_drm.h',
  246. 'include/drm/via_drm.h', 'include/drm/virtgpu_drm.h',
  247. subdir : 'libdrm',
  248. )
  249. if with_vmwgfx
  250. install_headers('include/drm/vmwgfx_drm.h', subdir : 'libdrm')
  251. endif
  252. pkg.generate(
  253. libdrm,
  254. name : 'libdrm',
  255. subdirs : ['.', 'libdrm'],
  256. description : 'Userspace interface to kernel DRM services',
  257. )
  258. if with_intel
  259. subdir('intel')
  260. endif
  261. if with_nouveau
  262. subdir('nouveau')
  263. endif
  264. if with_radeon
  265. subdir('radeon')
  266. endif
  267. if with_amdgpu
  268. subdir('amdgpu')
  269. endif
  270. if with_omap
  271. subdir('omap')
  272. endif
  273. if with_exynos
  274. subdir('exynos')
  275. endif
  276. if with_tegra
  277. subdir('tegra')
  278. endif
  279. if with_vc4
  280. subdir('vc4')
  281. endif
  282. if with_etnaviv
  283. subdir('etnaviv')
  284. endif
  285. if with_man_pages
  286. subdir('man')
  287. endif
  288. subdir('data')
  289. if with_tests
  290. subdir('tests')
  291. endif