tests/gl_basic_test: undo overzealous clang-format changes
[mesa-waffle.git] / meson.build
blob78b7696cc687e6896517e1af04860ce521925e52
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
6 project(
7   'waffle',
8   ['c'],
9   version : '1.8.90',
10   license : 'BSD2',
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')
19 build_x11_egl = false
20 build_wayland = false
21 build_glx = false
22 build_gbm = false
23 build_surfaceless = false
24 build_wgl = ['windows', 'cygwin'].contains(host_machine.system())
25 build_cgl = host_machine.system() == 'darwin'
27 if get_option('nacl')
28   error('nacl is no longer supported. use older waffle version')
29 endif
31 if build_cgl
32   add_languages('objc')
33 endif
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)
40 dep_gl = _dep_null
41 dep_drm = _dep_null
42 dep_egl = _dep_null
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
48 dep_gbm = _dep_null
49 dep_cocoa = _dep_null
50 dep_core_foundation = _dep_null
51 dep_gl_headers = _dep_null
53 # Get dependencies
54 if build_wgl
55   if not cc.has_header('GL/wglext.h')
56     _sub = subproject('opengl_headers')
57     dep_gl_headers = _sub.get_variable('ext_headers')
58   endif
59   dep_gl = cc.find_library('opengl32')
60 elif build_cgl
61   dep_cocoa = dependency('cocoa')
62   dep_core_foundation = dependency('corefoundation')
63   dep_gl = dependency('gl')
64 else
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'),
84   )
85   dep_wayland_egl = dependency(
86     'wayland-egl', version : '>= 9.1', required : get_option('wayland'),
87   )
88   dep_wayland_scanner = dependency(
89     'wayland-scanner', version : '>= 1.15', required : get_option('wayland'), native: true,
90   )
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'),
94     'wayland.xml')
95   endif
96   dep_wayland_proto = dependency(
97     'wayland-protocols', version  : '>= 1.12', required : get_option('wayland'),
98   )
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')
102   endif
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
107   _include_deps = [
108     ['gl', dep_gl],
109     ['drm', dep_drm],
110     ['egl', dep_egl],
111     ['gbm', dep_gbm],
112     ['wayland_client', dep_wayland_client],
113     ['wayland_egl', dep_wayland_egl],
114   ]
115   foreach d : _include_deps
116     if d[1].found()
117       set_variable('dep_' + d[0], d[1].partial_dependency(compile_args : true))
118     endif
119   endforeach
120 endif
122 prefixdir = get_option('prefix')
124 dep_bash = dependency('bash-completion', required : false)
125 bashcompletiondir = ''
126 if dep_bash.found()
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.')
131   else
132     bashcompletiondir = dep_bash.get_variable(pkgconfig: 'completionsdir')
133   endif
134 else
135   bashcompletiondir = join_paths(get_option('datadir'), 'bash-completion/completions')
136 endif
137 if bashcompletiondir != ''
138   install_data('shell-completion/bash/wflinfo', install_dir : bashcompletiondir)
139 endif
141 dep_fish = dependency('fish', required : false)
142 fishcompletiondir = ''
143 if dep_fish.found()
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.')
148   else
149     fishcompletiondir = dep_fish.get_variable(pkgconfig: 'completionsdir')
150   endif
151 else
152   fishcompletiondir = join_paths(get_option('datadir'), 'fish/vendor_functions.d')
153 endif
154 if fishcompletiondir != ''
155   install_data('shell-completion/fish/wflinfo.fish', install_dir : fishcompletiondir)
156 endif
158 zshcompletiondir = join_paths(get_option('datadir'), 'zsh/site-functions')
159 install_data('shell-completion/zsh/_wflinfo', install_dir : zshcompletiondir)
161 backends = ''
162 # Set pre-processor flags
163 if build_wgl
164     backends += 'wgl '
165     add_project_arguments('-DWAFFLE_HAS_WGL', language : ['c'])
166 elif build_cgl
167     backends += 'cgl '
168     add_project_arguments('-DWAFFLE_HAS_CGL -DGL_SILENCE_DEPRECATION', language : ['c', 'objc'])
169 else
170   if build_x11_egl
171     backends += 'x11_egl '
172     add_project_arguments('-DWAFFLE_HAS_X11_EGL', language : ['c'])
173   endif
174   if build_glx
175     backends += 'glx '
176     add_project_arguments('-DWAFFLE_HAS_GLX', language : ['c'])
177   endif
178   if build_wayland
179     backends += 'wayland '
180     add_project_arguments('-DWAFFLE_HAS_WAYLAND', language : ['c'])
181   endif
182   if build_gbm
183     backends += 'gbm '
184     add_project_arguments('-DWAFFLE_HAS_GBM', language : ['c'])
185   endif
186   if build_surfaceless
187     backends += 'surfaceless '
188     add_project_arguments('-DWAFFLE_HAS_SURFACELESS_EGL', language : ['c'])
189   endif
190 endif
192 if host_machine.system() == 'darwin'
193   add_project_arguments('-D_DARWIN_C_SOURCE', language : ['c', 'cpp', 'objc'])
194 endif
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',
202       '-Werror=format',
203       '-Werror=format-security',
204       '-Werror=incompatible-pointer-types',
205       '-Werror=init-self',
206       '-Werror=int-conversion',
207       '-Werror=missing-declarations',
208       '-Werror=missing-prototypes',  # TODO: breaks on MacOS?
209       '-Werror=pointer-arith',
210       '-Werror=undef',
211       '-Werror=vla',
212       '-Wsuggest-attribute=format',
213       '-Wwrite-strings',
214     ]),
215     language : ['c'],
216   )
218   # Closest thing we can get to a mingw check
219   if host_machine.system() != 'windows'
220     if cc.compiles('''
221         static __thread int x;
222         int main() {
223           x = 42;
224           return x;
225         }''',
226         args : '-Werror',
227         name : 'Thread Local Storage')
228       add_project_arguments('-DWAFFLE_HAS_TLS', language : ['c'])
229     endif
231     if cc.compiles('''
232         static __thread int x __attribute__((tls_model("initial-exec")));
233         int main() {
234           x = 42;
235           return x;
236         }''',
237         args : '-Werror',
238         name : 'TLS model "Initial Exec"')
239       add_project_arguments('-DWAFFLE_HAS_TLS_MODEL_INITIAL_EXEC', language : ['c'])
240     endif
241   else
242     if cc.has_argument('-static-libgcc')
243       add_project_link_arguments('-static-libgcc', language : ['c'])
244     endif
245   endif
246   api_c_args = [
247     '-DWAFFLE_API_VERSION=@0@'.format('0x0108'),
248     '-DWAFFLE_API_EXPERIMENTAL',
249   ]
250 elif cc.get_argument_syntax() == 'msvc'
251   add_project_arguments(
252     '/D_win32_WINNT=0x0601',
253     '/DWINVER=0x0601',
254     '/D_CRT_NONSTDC_NO_WARNINGS',
255     '/D_CRT_SECURE_NO_WARNINGS',
256     language : ['c'],
257   )
258   api_c_args = [
259     '/DWAFFLE_API_VERSION=@0@'.format('0x0108'),
260     '/DWAFFLE_API_EXPERIMENTAL',
261   ]
262 endif
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'])
270 else
271   dep_cmocka = _dep_null
272 endif
274 subdir('include')
275 subdir('third_party')
276 subdir('src')
277 subdir('doc')
278 subdir('man')
279 if get_option('build-tests')
280   subdir('tests')
281 endif
282 if get_option('build-examples')
283   subdir('examples')
284 endif
286 summary({
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'),
293 }, bool_yn: true)