1 # SPDX-FileCopyrightText: Copyright © 2017 Dylan Baker
2 # SPDX-FileCopyrightText: Copyright © 2018-2019 Intel Corporation
3 # SPDX-FileCopyrightText: Copyright © 2022 Emil Velikov
4 # SPDX-License-Identifier: BSD-2-Clause
11 meson_version : '>= 0.53',
12 # ubproject cmocka throws a Wclobbered ... make this a level=2 once it's fixed
13 default_options : ['c_std=c99', 'warning_level=1', 'buildtype=debugoptimized'],
16 waffle_name = meson.project_name() + '-1'
17 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name() + '1')
23 build_surfaceless = false
24 build_wgl = ['windows', 'cygwin'].contains(host_machine.system())
25 build_cgl = host_machine.system() == 'darwin'
28 error('nacl is no longer supported. use older waffle version')
35 cc = meson.get_compiler('c')
37 _dep_null = dependency('', required : false)
38 dep_threads = dependency('threads')
39 dep_dl = cc.find_library('dl', required : false)
43 dep_wayland_client = _dep_null
44 dep_wayland_egl = _dep_null
45 dep_wayland_scanner = _dep_null
46 dep_wayland_proto = _dep_null
47 dep_x11_xcb = _dep_null
50 dep_core_foundation = _dep_null
51 dep_gl_headers = _dep_null
55 if not cc.has_header('GL/wglext.h')
56 _sub = subproject('opengl_headers')
57 dep_gl_headers = _sub.get_variable('ext_headers')
59 dep_gl = cc.find_library('opengl32')
61 dep_cocoa = dependency('cocoa')
62 dep_core_foundation = dependency('corefoundation')
63 dep_gl = dependency('gl')
65 dep_gl = dependency('gl', required : get_option('glx'))
66 dep_x11_xcb = dependency('x11-xcb', required : get_option('glx'))
67 build_glx = dep_gl.found() and dep_x11_xcb.found()
69 dep_egl = dependency('egl', required : get_option('x11_egl'))
70 dep_x11_xcb = dependency('x11-xcb', required : get_option('x11_egl'))
71 build_x11_egl = dep_egl.found() and dep_x11_xcb.found()
73 dep_drm = dependency('libdrm', required : get_option('gbm'))
74 dep_egl = dependency('egl', required : get_option('gbm'))
75 dep_gbm = dependency('gbm', required : get_option('gbm'))
76 build_gbm = dep_drm.found() and dep_egl.found() and dep_gbm.found()
78 dep_egl = dependency('egl', required : get_option('surfaceless_egl'))
79 build_surfaceless = dep_egl.found()
81 dep_egl = dependency('egl', required : get_option('wayland'))
82 dep_wayland_client = dependency(
83 'wayland-client', version : '>= 1.10', required : get_option('wayland'),
85 dep_wayland_egl = dependency(
86 'wayland-egl', version : '>= 9.1', required : get_option('wayland'),
88 dep_wayland_scanner = dependency(
89 'wayland-scanner', version : '>= 1.15', required : get_option('wayland'), native: true,
91 if dep_wayland_scanner.found()
92 prog_wayland_scanner = find_program(dep_wayland_scanner.get_variable(pkgconfig: 'wayland_scanner'))
93 wayland_core_xml = join_paths(dep_wayland_scanner.get_variable(pkgconfig: 'pkgdatadir'),
96 dep_wayland_proto = dependency(
97 'wayland-protocols', version : '>= 1.12', required : get_option('wayland'),
99 if dep_wayland_proto.found()
100 wayland_xdg_shell_xml = join_paths(dep_wayland_proto.get_variable(pkgconfig: 'pkgdatadir'),
101 'stable/xdg-shell/xdg-shell.xml')
103 build_wayland = dep_egl.found() and dep_wayland_client.found() and dep_wayland_egl.found() and dep_wayland_scanner.found() and dep_wayland_proto.found()
105 # We're interested only in the headers provided
106 # FINISHME: make x11_xcb compile-only dependency
112 ['wayland_client', dep_wayland_client],
113 ['wayland_egl', dep_wayland_egl],
115 foreach d : _include_deps
117 set_variable('dep_' + d[0], d[1].partial_dependency(compile_args : true))
122 prefixdir = get_option('prefix')
124 dep_bash = dependency('bash-completion', required : false)
125 bashcompletiondir = ''
127 bash_prefix = dep_bash.get_variable(pkgconfig: 'prefix')
128 if prefixdir != bash_prefix
129 warning('User provided prefix \'@0@\' differs from bash-completion one \'@1@\'. '
130 .format(prefixdir, bash_prefix) + 'Disabling completion.')
132 bashcompletiondir = dep_bash.get_variable(pkgconfig: 'completionsdir')
135 bashcompletiondir = join_paths(get_option('datadir'), 'bash-completion/completions')
137 if bashcompletiondir != ''
138 install_data('shell-completion/bash/wflinfo', install_dir : bashcompletiondir)
141 dep_fish = dependency('fish', required : false)
142 fishcompletiondir = ''
144 fish_prefix = dep_fish.get_variable(pkgconfig: 'prefix')
145 if prefixdir != fish_prefix
146 warning('User provided prefix \'@0@\' differs from fish one \'@1@\'. '
147 .format(prefixdir, fish_prefix) + 'Disabling completion.')
149 fishcompletiondir = dep_fish.get_variable(pkgconfig: 'completionsdir')
152 fishcompletiondir = join_paths(get_option('datadir'), 'fish/vendor_functions.d')
154 if fishcompletiondir != ''
155 install_data('shell-completion/fish/wflinfo.fish', install_dir : fishcompletiondir)
158 zshcompletiondir = join_paths(get_option('datadir'), 'zsh/site-functions')
159 install_data('shell-completion/zsh/_wflinfo', install_dir : zshcompletiondir)
162 # Set pre-processor flags
165 add_project_arguments('-DWAFFLE_HAS_WGL', language : ['c'])
168 add_project_arguments('-DWAFFLE_HAS_CGL -DGL_SILENCE_DEPRECATION', language : ['c', 'objc'])
171 backends += 'x11_egl '
172 add_project_arguments('-DWAFFLE_HAS_X11_EGL', language : ['c'])
176 add_project_arguments('-DWAFFLE_HAS_GLX', language : ['c'])
179 backends += 'wayland '
180 add_project_arguments('-DWAFFLE_HAS_WAYLAND', language : ['c'])
184 add_project_arguments('-DWAFFLE_HAS_GBM', language : ['c'])
187 backends += 'surfaceless '
188 add_project_arguments('-DWAFFLE_HAS_SURFACELESS_EGL', language : ['c'])
192 if host_machine.system() == 'darwin'
193 add_project_arguments('-D_DARWIN_C_SOURCE', language : ['c', 'cpp', 'objc'])
196 if cc.get_argument_syntax() == 'gcc'
197 add_project_arguments('-D_XOPEN_SOURCE=700', language : ['c'])
199 add_project_arguments(
200 cc.get_supported_arguments([
201 '-Wno-unused-parameter',
203 '-Werror=format-security',
204 '-Werror=incompatible-pointer-types',
206 '-Werror=int-conversion',
207 '-Werror=missing-declarations',
208 '-Werror=missing-prototypes', # TODO: breaks on MacOS?
209 '-Werror=pointer-arith',
212 '-Wsuggest-attribute=format',
218 # Closest thing we can get to a mingw check
219 if host_machine.system() != 'windows'
221 static __thread int x;
227 name : 'Thread Local Storage')
228 add_project_arguments('-DWAFFLE_HAS_TLS', language : ['c'])
232 static __thread int x __attribute__((tls_model("initial-exec")));
238 name : 'TLS model "Initial Exec"')
239 add_project_arguments('-DWAFFLE_HAS_TLS_MODEL_INITIAL_EXEC', language : ['c'])
242 if cc.has_argument('-static-libgcc')
243 add_project_link_arguments('-static-libgcc', language : ['c'])
247 '-DWAFFLE_API_VERSION=@0@'.format('0x0108'),
248 '-DWAFFLE_API_EXPERIMENTAL',
250 elif cc.get_argument_syntax() == 'msvc'
251 add_project_arguments(
252 '/D_win32_WINNT=0x0601',
254 '/D_CRT_NONSTDC_NO_WARNINGS',
255 '/D_CRT_SECURE_NO_WARNINGS',
259 '/DWAFFLE_API_VERSION=@0@'.format('0x0108'),
260 '/DWAFFLE_API_EXPERIMENTAL',
264 install_data('README.md', 'LICENSE.txt', 'HACKING.txt', install_dir : docdir)
265 install_subdir('doc/release-notes', install_dir : docdir)
268 if get_option('build-tests')
269 dep_cmocka = dependency('cmocka', fallback : ['cmocka', 'dep_cmocka'])
271 dep_cmocka = _dep_null
275 subdir('third_party')
279 if get_option('build-tests')
282 if get_option('build-examples')
287 'Installation prefix': get_option('prefix'),
288 'Enabled backends': backends,
289 'Build tests': get_option('build-tests'),
290 'Build man pages': get_option('build-manpages'),
291 'Build html docs': get_option('build-htmldocs'),
292 'Build examples': get_option('build-examples'),