1############################################################################# 2# 3# Copyright (C) 2019 Collabora Ltd 4# 5# Permission is hereby granted, free of charge, to any person obtaining a 6# copy of this software and associated documentation files (the "Software"), 7# to deal in the Software without restriction, including without limitation 8# the rights to use, copy, modify, merge, publish, distribute, sublicense, 9# and/or sell copies of the Software, and to permit persons to whom the 10# Software is furnished to do so, subject to the following conditions: 11# 12# The above copyright notice and this permission notice shall be included 13# in all copies or substantial portions of the Software. 14# 15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 19# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21# OTHER DEALINGS IN THE SOFTWARE. 22# 23 24project( 25 'virglrenderer', 'c', 26 version: '0.10.4', 27 license : 'MIT', 28 meson_version : '>= 0.53', 29 default_options : ['buildtype=release', 'b_ndebug=if-release', 30 'warning_level=3', 'c_std=gnu11'] 31) 32 33# To change only before doing a release: 34# 35# 1. Incrememnt the revision 36# 2. If the interface was changed in an compatible way increment the 37# interface age 38# 3. If the ABI has changed in an incompatible way increment the binary_age 39# and set revision and interface_age to zero 40binary_age = 1 41interface_age = 7 42revision = 7 43 44cc = meson.get_compiler('c') 45 46if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.1') 47 error('When using GCC, version 4.1 or later is required.') 48endif 49 50warnings = [ 51 '-Werror=implicit-function-declaration', 52 '-Werror=missing-prototypes', 53 '-Wmissing-prototypes', 54 '-Werror=incompatible-pointer-types', 55 '-Werror=int-to-pointer-cast', 56 '-Wno-overlength-strings', 57] 58 59add_project_arguments(cc.get_supported_arguments(warnings), language : 'c') 60 61flags = [ 62 '-fvisibility=hidden', 63] 64 65add_project_arguments(cc.get_supported_arguments(flags), language : 'c') 66 67prog_python = import('python').find_installation('python3') 68 69libdrm_dep = dependency('libdrm', version : '>=2.4.50') 70thread_dep = dependency('threads') 71epoxy_dep = dependency('epoxy', version: '>= 1.5.4') 72m_dep = cc.find_library('m', required : false) 73 74conf_data = configuration_data() 75conf_data.set('VERSION', meson.project_version()) 76conf_data.set('_GNU_SOURCE', 1) 77conf_data.set('VIRGL_RENDERER_UNSTABLE_APIS', 1) 78 79with_tracing = get_option('tracing') 80 81if with_tracing != 'none' 82 if not cc.compiles('void f(void* v){} int main () { void *dummy __attribute__((cleanup (f))) = 0;}') 83 error('Tracing requires compiler support for __attribute__((cleanup))') 84 endif 85endif 86 87if with_tracing == 'percetto' 88 # percetto uses C++ internally, so we need to link with C++. 89 # TODO: remove -lstdc++ when percetto is a shared library. 90 add_project_link_arguments('-lstdc++', language : 'c') 91 percetto_dep = dependency('percetto', version : '>=0.0.8') 92 conf_data.set('ENABLE_TRACING', 'TRACE_WITH_PERCETTO') 93endif 94 95if with_tracing == 'perfetto' 96 vperfetto_min_dep = dependency('vperfetto_min') 97 conf_data.set('ENABLE_TRACING', 'TRACE_WITH_PERFETTO') 98endif 99 100if with_tracing == 'stderr' 101 conf_data.set('ENABLE_TRACING', 'TRACE_WITH_STDERR') 102endif 103 104if cc.has_header('sys/uio.h') 105 conf_data.set('HAVE_SYS_UIO_H', 1) 106endif 107 108if cc.has_header('dlfcn.h') 109 conf_data.set('HAVE_DLFCN_H', 1) 110endif 111 112if thread_dep.found() and host_machine.system() != 'windows' 113 conf_data.set('HAVE_PTHREAD', 1) 114 if host_machine.system() != 'netbsd' and cc.has_function( 115 'pthread_setaffinity_np', 116 dependencies : thread_dep, 117 prefix : '#include <pthread.h>', 118 args : '-D_GNU_SOURCE') 119 conf_data.set('HAVE_PTHREAD_SETAFFINITY', 1) 120 endif 121endif 122 123if cc.has_header('sys/eventfd.h') 124 conf_data.set('HAVE_EVENTFD_H', 1) 125endif 126 127if cc.has_header('sys/select.h') 128 conf_data.set('HAVE_SYS_SELECT_H', 1) 129endif 130 131foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'expect', 'ffs', 'ffsll', 132 'popcount', 'popcountll', 'types_compatible_p', 'unreachable'] 133 if cc.has_function(b) 134 conf_data.set('HAVE___BUILTIN_@0@'.format(b.to_upper()), 1) 135 endif 136endforeach 137 138supported_function_attributes = cc.get_supported_function_attributes([ 139 'const', 'flatten', 'format', 'malloc', 'noreturn', 'packed', 'pure', 140 'returns_nonnull', 'unused', 'warn_unused_result', 'weak', 141]) 142foreach a : supported_function_attributes 143 conf_data.set('HAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper()), 1) 144endforeach 145 146foreach f : ['memfd_create', 'strtok_r', 'timespec_get'] 147 if cc.has_function(f) 148 conf_data.set('HAVE_@0@'.format(f.to_upper()), 1) 149 endif 150endforeach 151 152if host_machine.endian() == 'little' 153 conf_data.set('UTIL_ARCH_LITTLE_ENDIAN', 1) 154 conf_data.set('UTIL_ARCH_BIG_ENDIAN', 0) 155elif host_machine.endian() == 'big' 156 conf_data.set('UTIL_ARCH_LITTLE_ENDIAN', 0) 157 conf_data.set('UTIL_ARCH_BIG_ENDIAN', 1) 158else 159 error('It wasn\'t possible to figure out the endianess of the machine') 160endif 161 162pipe_arch = host_machine.cpu_family() 163 164if pipe_arch == 'x86' 165 conf_data.set('PIPE_ARCH_X86', true) 166elif pipe_arch == 'x86_64' 167 conf_data.set('PIPE_ARCH_X86_64', true) 168elif pipe_arch == 'ppc' 169 conf_data.set('PIPE_ARCH_PPC', true) 170elif pipe_arch == 'ppc64' 171 conf_data.set('PIPE_ARCH_PPC_64', true) 172elif pipe_arch == 's390x' 173 conf_data.set('PIPE_ARCH_S390', true) 174elif pipe_arch == 'arm' 175 conf_data.set('PIPE_ARCH_ARM', true) 176elif pipe_arch == 'aarch64' 177 conf_data.set('PIPE_ARCH_AARCH64', true) 178else 179 warning('Arch used is not supported') 180endif 181 182if get_option('buildtype') == 'debug' 183 add_global_arguments('-DDEBUG=1', language : 'c') 184endif 185 186platforms = get_option('platforms') 187 188require_egl = platforms.contains('egl') 189require_glx = platforms.contains('glx') 190auto_egl_glx = platforms.contains('auto') 191 192with_egl = require_egl or auto_egl_glx 193with_glx = require_glx or auto_egl_glx 194 195have_egl = false 196have_glx = false 197 198with_minigbm_allocation = get_option('minigbm_allocation') 199if with_minigbm_allocation 200 conf_data.set('ENABLE_MINIGBM_ALLOCATION', 1) 201 _gbm_ver = '18.0.0' 202else 203 _gbm_ver = '0.0.0' 204endif 205 206if with_egl 207 if cc.has_header('epoxy/egl.h', dependencies: epoxy_dep) and epoxy_dep.get_pkgconfig_variable('epoxy_has_egl') == '1' 208 have_egl = true 209 if (have_egl) 210 conf_data.set('HAVE_EPOXY_EGL_H', 1) 211 else 212 assert(not require_egl, 213 'egl was explicitely requested which requires gbm, and this is not available') 214 endif 215 else 216 assert(not require_egl, 217 'egl was explicitely requested but it is not supported by epoxy') 218 endif 219endif 220 221if with_glx 222 if cc.has_header('epoxy/glx.h', dependencies: epoxy_dep) and epoxy_dep.get_pkgconfig_variable('epoxy_has_glx') == '1' 223 glx_dep = dependency('x11', required: require_glx) 224 have_glx = glx_dep.found() 225 conf_data.set('HAVE_EPOXY_GLX_H', 1) 226 else 227 assert(not require_glx, 228 'glx was explicitely requested but it is not supported by epoxy') 229 endif 230endif 231 232with_venus = get_option('venus-experimental') 233with_venus_validate = get_option('venus-validate') 234if with_venus 235 venus_dep = dependency('vulkan') 236 conf_data.set('ENABLE_VENUS', 1) 237 238 if with_venus_validate 239 conf_data.set('ENABLE_VENUS_VALIDATE', 1) 240 endif 241endif 242 243have_vla = not cc.has_header_symbol('stdlib.h', '__STDC_NO_VLA__') 244 245# drm/msm support requires the compiler to support VLA: 246with_drm_msm = have_vla and get_option('drm-msm-experimental') 247if with_drm_msm 248 conf_data.set('ENABLE_DRM', 1) 249 conf_data.set('ENABLE_DRM_MSM', 1) 250endif 251with_drm = with_drm_msm 252 253with_check_gl_errors = get_option('check-gl-errors') 254if with_check_gl_errors 255 conf_data.set('CHECK_GL_ERRORS', 1) 256endif 257 258with_render_server = get_option('render-server') 259with_render_server_worker = get_option('render-server-worker') 260render_server_install_dir = get_option('prefix') / get_option('libexecdir') 261if with_render_server 262 if not with_venus 263 error('render server makes no sense without venus currently') 264 endif 265 266 conf_data.set('ENABLE_RENDER_SERVER', 1) 267 conf_data.set('RENDER_SERVER_EXEC_PATH', 268 '"' + render_server_install_dir / 'virgl_render_server' + '"') 269 270 if with_render_server_worker == 'process' 271 conf_data.set('ENABLE_RENDER_SERVER_WORKER_PROCESS', 1) 272 elif with_render_server_worker == 'thread' 273 conf_data.set('ENABLE_RENDER_SERVER_WORKER_THREAD', 1) 274 elif with_render_server_worker == 'minijail' 275 conf_data.set('ENABLE_RENDER_SERVER_WORKER_MINIJAIL', 1) 276 minijail_dep = dependency('libminijail') 277 else 278 error('unknown render server worker ' + with_render_server_worker) 279 endif 280endif 281 282with_video = get_option('video') 283if with_video 284 conf_data.set('ENABLE_VIDEO', 1) 285 libva_dep = dependency('libva') 286 libvadrm_dep = dependency('libva-drm') 287endif 288 289configure_file(input : 'config.h.meson', 290 output : 'config.h', 291 configuration : conf_data) 292 293add_project_arguments('-imacros', meson.build_root() / 'config.h', language : 'c') 294add_project_arguments('-DHAVE_CONFIG_H=1', language : 'c') 295 296inc_configuration = include_directories(['.', 'src']) 297 298with_fuzzer = get_option('fuzzer') 299with_tests = get_option('tests') 300with_valgrind = get_option('valgrind') 301 302subdir('src') 303subdir('vtest') 304 305if with_render_server 306subdir('server') 307endif 308 309if with_tests 310 assert(have_egl, 'Tests require EGL, but it is not available') 311 subdir('tests') 312endif 313 314summary({'prefix': get_option('prefix'), 315 'libdir': get_option('libdir'), 316 }, section: 'Directories') 317summary({'c_args': (' ').join(get_option('c_args')), 318 'egl': have_egl, 319 'glx': have_glx, 320 'minigbm_alloc': with_minigbm_allocation, 321 'venus': with_venus, 322 'drm-msm': with_drm_msm, 323 'render server': with_render_server, 324 'render server worker': with_render_server ? with_render_server_worker : 'none', 325 'video': with_video, 326 'tests': with_tests, 327 'fuzzer': with_fuzzer, 328 'tracing': with_tracing, 329 }, section: 'Configuration') 330