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 gbm_dep = dependency('gbm', version: '>= ' + _gbm_ver, required: require_egl) 209 have_egl = gbm_dep.found() 210 if (have_egl) 211 conf_data.set('HAVE_EPOXY_EGL_H', 1) 212 else 213 assert(not require_egl, 214 'egl was explicitely requested which requires gbm, and this is not available') 215 endif 216 else 217 assert(not require_egl, 218 'egl was explicitely requested but it is not supported by epoxy') 219 endif 220endif 221 222if with_glx 223 if cc.has_header('epoxy/glx.h', dependencies: epoxy_dep) and epoxy_dep.get_pkgconfig_variable('epoxy_has_glx') == '1' 224 glx_dep = dependency('x11', required: require_glx) 225 have_glx = glx_dep.found() 226 conf_data.set('HAVE_EPOXY_GLX_H', 1) 227 else 228 assert(not require_glx, 229 'glx was explicitely requested but it is not supported by epoxy') 230 endif 231endif 232 233with_venus = get_option('venus-experimental') 234with_venus_validate = get_option('venus-validate') 235if with_venus 236 venus_dep = dependency('vulkan') 237 conf_data.set('ENABLE_VENUS', 1) 238 239 if with_venus_validate 240 conf_data.set('ENABLE_VENUS_VALIDATE', 1) 241 endif 242endif 243 244have_vla = not cc.has_header_symbol('stdlib.h', '__STDC_NO_VLA__') 245 246# drm/msm support requires the compiler to support VLA: 247with_drm_msm = have_vla and get_option('drm-msm-experimental') 248if with_drm_msm 249 conf_data.set('ENABLE_DRM', 1) 250 conf_data.set('ENABLE_DRM_MSM', 1) 251endif 252with_drm = with_drm_msm 253 254with_check_gl_errors = get_option('check-gl-errors') 255if with_check_gl_errors 256 conf_data.set('CHECK_GL_ERRORS', 1) 257endif 258 259with_render_server = get_option('render-server') 260with_render_server_worker = get_option('render-server-worker') 261render_server_install_dir = get_option('prefix') / get_option('libexecdir') 262if with_render_server 263 if not with_venus 264 error('render server makes no sense without venus currently') 265 endif 266 267 conf_data.set('ENABLE_RENDER_SERVER', 1) 268 conf_data.set('RENDER_SERVER_EXEC_PATH', 269 '"' + render_server_install_dir / 'virgl_render_server' + '"') 270 271 if with_render_server_worker == 'process' 272 conf_data.set('ENABLE_RENDER_SERVER_WORKER_PROCESS', 1) 273 elif with_render_server_worker == 'thread' 274 conf_data.set('ENABLE_RENDER_SERVER_WORKER_THREAD', 1) 275 elif with_render_server_worker == 'minijail' 276 conf_data.set('ENABLE_RENDER_SERVER_WORKER_MINIJAIL', 1) 277 minijail_dep = dependency('libminijail') 278 else 279 error('unknown render server worker ' + with_render_server_worker) 280 endif 281endif 282 283with_video = get_option('video') 284if with_video 285 conf_data.set('ENABLE_VIDEO', 1) 286 libva_dep = dependency('libva') 287 libvadrm_dep = dependency('libva-drm') 288endif 289 290configure_file(input : 'config.h.meson', 291 output : 'config.h', 292 configuration : conf_data) 293 294add_project_arguments('-imacros', meson.build_root() / 'config.h', language : 'c') 295add_project_arguments('-DHAVE_CONFIG_H=1', language : 'c') 296 297inc_configuration = include_directories(['.', 'src']) 298 299with_fuzzer = get_option('fuzzer') 300with_tests = get_option('tests') 301with_valgrind = get_option('valgrind') 302 303subdir('src') 304subdir('vtest') 305 306if with_render_server 307subdir('server') 308endif 309 310if with_tests 311 assert(have_egl, 'Tests require EGL, but it is not available') 312 subdir('tests') 313endif 314 315summary({'prefix': get_option('prefix'), 316 'libdir': get_option('libdir'), 317 }, section: 'Directories') 318summary({'c_args': (' ').join(get_option('c_args')), 319 'egl': have_egl, 320 'glx': have_glx, 321 'minigbm_alloc': with_minigbm_allocation, 322 'venus': with_venus, 323 'drm-msm': with_drm_msm, 324 'render server': with_render_server, 325 'render server worker': with_render_server ? with_render_server_worker : 'none', 326 'video': with_video, 327 'tests': with_tests, 328 'fuzzer': with_fuzzer, 329 'tracing': with_tracing, 330 }, section: 'Configuration') 331