meson.build revision f71742df
1project('libepoxy', 'c', version: '1.4.3', 2 default_options: [ 3 'buildtype=debugoptimized', 4 'c_std=gnu99', 5 'warning_level=1', 6 ], 7 license: 'MIT', 8 meson_version: '>= 0.39.1') 9 10epoxy_version = meson.project_version().split('.') 11epoxy_major_version = epoxy_version[0].to_int() 12epoxy_minor_version = epoxy_version[1].to_int() 13epoxy_micro_version = epoxy_version[2].to_int() 14 15epoxy_prefix = get_option('prefix') 16epoxy_libdir = join_paths(epoxy_prefix, get_option('libdir')) 17epoxy_datadir = join_paths(epoxy_prefix, get_option('datadir')) 18epoxy_includedir = join_paths(epoxy_prefix, get_option('includedir')) 19 20cc = meson.get_compiler('c') 21host_system = host_machine.system() 22 23conf = configuration_data() 24conf.set_quoted('PACKAGE_NAME', meson.project_name()) 25conf.set_quoted('PACKAGE_VERSION', meson.project_version()) 26conf.set_quoted('PACKAGE_STRING', '@0@-@1@'.format(meson.project_name(), meson.project_version())) 27conf.set_quoted('PACKAGE_DATADIR', join_paths(get_option('prefix'), get_option('datadir'))) 28conf.set_quoted('PACKAGE_LIBDIR', join_paths(get_option('prefix'), get_option('libdir'))) 29conf.set_quoted('PACKAGE_LOCALEDIR', join_paths(get_option('prefix'), get_option('datadir'), 'locale')) 30conf.set_quoted('PACKAGE_LIBEXECDIR', join_paths(get_option('prefix'), get_option('libexecdir'))) 31conf.set('HAVE_KHRPLATFORM_H', cc.has_header('KHR/khrplatform.h', required: false)) 32 33# GLX can be used on different platforms, so we expose a 34# configure time switch to enable or disable it; in case 35# the "auto" default value is set, we only enable GLX 36# support on Linux and Unix 37enable_glx = get_option('enable-glx') 38if enable_glx == 'auto' 39 if host_system == 'windows' 40 build_glx = false 41 elif host_system == 'darwin' 42 build_glx = false 43 elif host_system == 'android' 44 build_glx = false 45 elif host_system == 'haiku' 46 build_glx = false 47 else 48 build_glx = true 49 endif 50elif enable_glx == 'yes' 51 build_glx = true 52elif enable_glx == 'no' 53 build_glx = false 54endif 55 56enable_egl = get_option('enable-egl') 57if enable_egl == 'auto' 58 if host_system == 'windows' 59 build_egl = false 60 elif host_system == 'darwin' 61 build_egl = false 62 elif host_system == 'android' 63 build_egl = true 64 else 65 build_egl = true 66 endif 67elif enable_egl == 'yes' 68 build_egl = true 69elif enable_egl == 'no' 70 build_egl = false 71endif 72 73# The remaining platform specific API for GL/GLES are enabled 74# depending on the platform we're building for 75if host_system == 'windows' 76 build_apple = false 77 build_wgl = true 78 has_znow = true 79elif host_system == 'darwin' 80 build_apple = true 81 build_wgl = false 82 has_znow = false 83else 84 build_apple = false 85 build_wgl = false 86 has_znow = true 87endif 88 89conf.set10('ENABLE_GLX', build_glx) 90conf.set10('ENABLE_EGL', build_egl) 91 92# Compiler flags, taken from the Xorg macros 93if cc.get_id() == 'msvc' 94 # Compiler options taken from msvc_recommended_pragmas.h 95 # in GLib, based on _Win32_Programming_ by Rector and Newcomer 96 test_cflags = [ 97 '-we4002', # too many actual parameters for macro 98 '-we4003', # not enough actual parameters for macro 99 '-w14010', # single-line comment contains line-continuation character 100 '-we4013', # 'function' undefined; assuming extern returning int 101 '-w14016', # no function return type; using int as default 102 '-we4020', # too many actual parameters 103 '-we4021', # too few actual parameters 104 '-we4027', # function declared without formal parameter list 105 '-we4029', # declared formal parameter list different from definition 106 '-we4033', # 'function' must return a value 107 '-we4035', # 'function' : no return value 108 '-we4045', # array bounds overflow 109 '-we4047', # different levels of indirection 110 '-we4049', # terminating line number emission 111 '-we4053', # an expression of type void was used as an operand 112 '-we4071', # no function prototype given 113 '-we4819', # the file contains a character that cannot be represented in the current code page 114 ] 115elif cc.get_id() == 'gcc' or cc.get_id() == 'clang' 116 test_cflags = [ 117 '-Wpointer-arith', 118 '-Wmissing-declarations', 119 '-Wformat=2', 120 '-Wstrict-prototypes', 121 '-Wmissing-prototypes', 122 '-Wnested-externs', 123 '-Wbad-function-cast', 124 '-Wold-style-definition', 125 '-Wdeclaration-after-statement', 126 '-Wunused', 127 '-Wuninitialized', 128 '-Wshadow', 129 '-Wmissing-noreturn', 130 '-Wmissing-format-attribute', 131 '-Wredundant-decls', 132 '-Wlogical-op', 133 '-Werror=implicit', 134 '-Werror=nonnull', 135 '-Werror=init-self', 136 '-Werror=main', 137 '-Werror=missing-braces', 138 '-Werror=sequence-point', 139 '-Werror=return-type', 140 '-Werror=trigraphs', 141 '-Werror=array-bounds', 142 '-Werror=write-strings', 143 '-Werror=address', 144 '-Werror=int-to-pointer-cast', 145 '-Werror=pointer-to-int-cast', 146 '-fno-strict-aliasing', 147 '-Wno-int-conversion', 148 ] 149else 150 test_cflags = [] 151endif 152 153common_cflags = [] 154foreach cflag: test_cflags 155 if cc.has_argument(cflag) 156 common_cflags += cflag 157 endif 158endforeach 159 160libtype = get_option('default_library') 161 162# Visibility compiler flags; we only use this for shared libraries 163if libtype == 'shared' 164 visibility_cflags = [] 165 if host_system == 'windows' 166 conf.set('DLL_EXPORT', true) 167 conf.set('EPOXY_PUBLIC', '__declspec(dllexport) extern') 168 if cc.get_id() != 'msvc' 169 visibility_cflags += [ '-fvisibility=hidden' ] 170 endif 171 else 172 conf.set('EPOXY_PUBLIC', '__attribute__((visibility("default"))) extern') 173 visibility_cflags += [ '-fvisibility=hidden' ] 174 endif 175endif 176 177# The inline keyword is available only for C++ in MSVC. 178# So we need to use Microsoft specific __inline. 179if host_system == 'windows' 180 if cc.get_id() == 'msvc' 181 conf.set('inline', '__inline') 182 endif 183endif 184 185# Dependencies 186dl_dep = cc.find_library('dl', required: false) 187gl_dep = dependency('gl', required: false) 188egl_dep = dependency('egl', required: false) 189 190# Optional dependencies for tests 191x11_dep = dependency('x11', required: false) 192 193# GLES v2 and v1 may have pkg-config files, courtesy of downstream 194# packagers; let's check those first, and fall back to find_library() 195# if we fail 196gles2_dep = dependency('glesv2', required: false) 197if not gles2_dep.found() 198 gles2_dep = cc.find_library('libGLESv2', required: false) 199endif 200 201gles1_dep = dependency('glesv1_cm', required: false) 202if not gles1_dep.found() 203 gles1_dep = cc.find_library('libGLESv1_CM', required: false) 204endif 205 206# On windows, the DLL has to have all of its functions 207# resolved at link time, so we have to link directly aginst 208# opengl32. But that's the only GL provider, anyway. 209if host_system == 'windows' 210 opengl32_dep = cc.find_library('opengl32', required: true) 211 212 # When building against static libraries, we need to control 213 # the order of the dependencies, and gdi32 provides symbols 214 # needed when using opengl32, like SetPixelFormat and 215 # ChoosePixelFormat. This is mostly a workaround for older 216 # versions of Meson. 217 gdi32_dep = cc.find_library('gdi32', required: true) 218endif 219 220# PkgConfig file 221pkgconf = configuration_data() 222pkgconf.set('prefix', epoxy_prefix) 223pkgconf.set('exec_prefix', epoxy_prefix) 224pkgconf.set('libdir', epoxy_libdir) 225pkgconf.set('includedir', epoxy_includedir) 226pkgconf.set10('epoxy_has_glx', build_glx) 227pkgconf.set10('epoxy_has_egl', build_egl) 228pkgconf.set10('epoxy_has_wgl', build_wgl) 229pkgconf.set('PACKAGE_VERSION', meson.project_version()) 230if dl_dep.found() 231 pkgconf.set('DLOPEN_LIBS', '-ldl') 232endif 233 234configure_file(input: 'epoxy.pc.in', 235 output: 'epoxy.pc', 236 configuration: pkgconf, 237 install: true, 238 install_dir: join_paths(epoxy_libdir, 'pkgconfig')) 239 240# Python 241python = import('python3').find_python() 242if not python.found() 243 python = find_program('python', required: true) 244endif 245 246# Generates the dispatch tables 247gen_dispatch_py = files('src/gen_dispatch.py') 248 249gl_registry = files('registry/gl.xml') 250egl_registry = files('registry/egl.xml') 251glx_registry = files('registry/glx.xml') 252wgl_registry = files('registry/wgl.xml') 253 254libepoxy_inc = [ 255 include_directories('include'), 256 include_directories('src'), 257] 258 259subdir('include/epoxy') 260subdir('src') 261subdir('test') 262 263if get_option('enable-docs') 264 doxygen = find_program('doxygen', required: false) 265 if doxygen.found() 266 subdir('doc') 267 else 268 message('Documentation disabled without doxygen') 269 endif 270endif 271