meson: tweak win/posix_platform.c handling
[mesa-waffle.git] / meson.build
blob4d6e02f3dba09fa4b1ac81389587e561bf129ba8
1 # Copyright © 2017 Dylan Baker
2 # Copyright © 2018-2019 Intel Corporation
3 # Copyright © 2022 Emil Velikov
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
10 # - Redistributions of source code must retain the above copyright notice, this
11 #   list of conditions and the following disclaimer.
13 # - Redistributions in binary form must reproduce the above copyright notice,
14 #   this list of conditions and the following disclaimer in the documentation
15 #   and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 project(
29   'waffle',
30   ['c'],
31   version : '1.8.90',
32   license : 'BSD2',
33   meson_version : '>= 0.53',
34   # ubproject cmocka throws a Wclobbered ... make this a level=2 once it's fixed
35   default_options : ['c_std=c99', 'warning_level=1', 'buildtype=debugoptimized'],
38 waffle_name = meson.project_name() + '-1'
39 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name() + '1')
41 build_x11_egl = false
42 build_wayland = false
43 build_glx = false
44 build_gbm = false
45 build_surfaceless = false
46 build_wgl = ['windows', 'cygwin'].contains(host_machine.system())
47 build_cgl = host_machine.system() == 'darwin'
49 if get_option('nacl')
50   error('nacl is no longer supported. use older waffle version')
51 endif
53 if build_cgl
54   add_languages('objc')
55 endif
57 cc = meson.get_compiler('c')
59 _dep_null = dependency('', required : false)
60 dep_threads = dependency('threads')
61 dep_dl = cc.find_library('dl', required : false)
62 dep_gl = _dep_null
63 dep_drm = _dep_null
64 dep_egl = _dep_null
65 dep_wayland_client = _dep_null
66 dep_wayland_egl = _dep_null
67 dep_wayland_scanner = _dep_null
68 dep_wayland_proto = _dep_null
69 dep_x11_xcb = _dep_null
70 dep_gbm = _dep_null
71 dep_cocoa = _dep_null
72 dep_core_foundation = _dep_null
73 dep_gl_headers = _dep_null
75 # Get dependencies
76 if build_wgl
77   if not cc.has_header('GL/wglext.h')
78     _sub = subproject('opengl_headers')
79     dep_gl_headers = _sub.get_variable('ext_headers')
80   endif
81   dep_gl = cc.find_library('opengl32')
82 elif build_cgl
83   dep_cocoa = dependency('cocoa')
84   dep_core_foundation = dependency('corefoundation')
85   dep_gl = dependency('gl')
86 else
87   dep_gl = dependency('gl', required : get_option('glx'))
88   dep_x11_xcb = dependency('x11-xcb', required : get_option('glx'))
89   build_glx = dep_gl.found() and dep_x11_xcb.found()
91   dep_egl = dependency('egl', required : get_option('x11_egl'))
92   dep_x11_xcb = dependency('x11-xcb', required : get_option('x11_egl'))
93   build_x11_egl = dep_egl.found() and dep_x11_xcb.found()
95   dep_drm = dependency('libdrm', required : get_option('gbm'))
96   dep_egl = dependency('egl', required : get_option('gbm'))
97   dep_gbm = dependency('gbm', required : get_option('gbm'))
98   build_gbm = dep_drm.found() and dep_egl.found() and dep_gbm.found()
100   dep_egl = dependency('egl', required : get_option('surfaceless_egl'))
101   build_surfaceless = dep_egl.found()
103   dep_egl = dependency('egl', required : get_option('wayland'))
104   dep_wayland_client = dependency(
105     'wayland-client', version : '>= 1.10', required : get_option('wayland'),
106   )
107   dep_wayland_egl = dependency(
108     'wayland-egl', version : '>= 9.1', required : get_option('wayland'),
109   )
110   dep_wayland_scanner = dependency(
111     'wayland-scanner', version : '>= 1.15', required : get_option('wayland'), native: true,
112   )
113   if dep_wayland_scanner.found()
114     prog_wayland_scanner = find_program(dep_wayland_scanner.get_variable(pkgconfig: 'wayland_scanner'))
115     wayland_core_xml = join_paths(dep_wayland_scanner.get_variable(pkgconfig: 'pkgdatadir'),
116     'wayland.xml')
117   endif
118   dep_wayland_proto = dependency(
119     'wayland-protocols', version  : '>= 1.12', required : get_option('wayland'),
120   )
121   if dep_wayland_proto.found()
122     wayland_xdg_shell_xml = join_paths(dep_wayland_proto.get_variable(pkgconfig: 'pkgdatadir'),
123     'stable/xdg-shell/xdg-shell.xml')
124   endif
125   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()
127   # We're interested only in the headers provided
128   # FINISHME: make x11_xcb compile-only dependency
129   _include_deps = [ dep_gl, dep_drm, dep_egl, dep_gbm, dep_wayland_client, dep_wayland_egl ]
130   foreach d : _include_deps
131     if d.found()
132       d = d.partial_dependency(compile_args : true)
133     endif
134   endforeach
135 endif
137 dep_bash = dependency('bash-completion', required : false)
138 bashcompletiondir = ''
139 if dep_bash.found()
140   prefixdir = get_option('prefix')
141   bash_prefix = dep_bash.get_variable(pkgconfig: 'prefix')
142   if prefixdir != bash_prefix
143     warning('User provided prefix \'@0@\' differs from bash-completion one \'@1@\'. '
144             .format(prefixdir, bash_prefix) + 'Disabling completion.')
145   else
146     bashcompletiondir = dep_bash.get_variable(pkgconfig: 'completionsdir')
147   endif
148 else
149   bashcompletiondir = join_paths(get_option('datadir'), 'bash-completion/completions')
150 endif
151 if bashcompletiondir != ''
152   install_data('shell-completion/bash/wflinfo', install_dir : bashcompletiondir)
153 endif
155 zshcompletiondir = join_paths(get_option('datadir'), 'zsh/site-functions')
156 install_data('shell-completion/zsh/_wflinfo', install_dir : zshcompletiondir)
158 backends = ''
159 # Set pre-processor flags
160 if build_wgl
161     backends += ' wgl'
162     add_project_arguments('-DWAFFLE_HAS_WGL', language : ['c'])
163 elif build_cgl
164     backends += ' cgl'
165     add_project_arguments('-DWAFFLE_HAS_CGL -DGL_SILENCE_DEPRECATION', language : ['c', 'objc'])
166 else
167   if build_x11_egl
168     backends += ' x11_egl'
169     add_project_arguments('-DWAFFLE_HAS_X11_EGL', language : ['c'])
170   endif
171   if build_glx
172     backends += ' glx'
173     add_project_arguments('-DWAFFLE_HAS_GLX', language : ['c'])
174   endif
175   if build_wayland
176     backends += ' wayland'
177     add_project_arguments('-DWAFFLE_HAS_WAYLAND', language : ['c'])
178   endif
179   if build_gbm
180     backends += ' gbm'
181     add_project_arguments('-DWAFFLE_HAS_GBM', language : ['c'])
182   endif
183   if build_surfaceless
184     backends += ' surfaceless'
185     add_project_arguments('-DWAFFLE_HAS_SURFACELESS_EGL', language : ['c'])
186   endif
187 endif
189 if host_machine.system() == 'darwin'
190   add_project_arguments('-D_DARWIN_C_SOURCE', language : ['c', 'cpp', 'objc'])
191 endif
193 if cc.get_argument_syntax() == 'gcc'
194   add_project_arguments('-D_XOPEN_SOURCE=700', language : ['c'])
196   add_project_arguments(
197     cc.get_supported_arguments([
198       '-Wno-unused-parameter',
199       '-Werror=format',
200       '-Werror=format-security',
201       '-Werror=incompatible-pointer-types',
202       '-Werror=init-self',
203       '-Werror=int-conversion',
204       '-Werror=missing-declarations',
205       '-Werror=missing-prototypes',  # TODO: breaks on MacOS?
206       '-Werror=pointer-arith',
207       '-Werror=undef',
208       '-Werror=vla',
209       '-Wsuggest-attribute=format',
210       '-Wwrite-strings',
211     ]),
212     language : ['c'],
213   )
215   # Closest thing we can get to a mingw check
216   if host_machine.system() != 'windows'
217     if cc.compiles('''
218         static __thread int x;
219         int main() {
220           x = 42;
221           return x;
222         }''',
223         args : '-Werror',
224         name : 'Thread Local Storage')
225       add_project_arguments('-DWAFFLE_HAS_TLS', language : ['c'])
226     endif
228     if cc.compiles('''
229         static __thread int x __attribute__((tls_model("initial-exec")));
230         int main() {
231           x = 42;
232           return x;
233         }''',
234         args : '-Werror',
235         name : 'TLS model "Initial Exec"')
236       add_project_arguments('-DWAFFLE_HAS_TLS_MODEL_INITIAL_EXEC', language : ['c'])
237     endif
238   else
239     if cc.has_argument('-static-libgcc')
240       add_project_link_arguments('-static-libgcc', language : ['c'])
241     endif
242   endif
243   api_c_args = [
244     '-DWAFFLE_API_VERSION=@0@'.format('0x0108'),
245     '-DWAFFLE_API_EXPERIMENTAL',
246   ]
247 elif cc.get_argument_syntax() == 'msvc'
248   add_project_arguments(
249     '/D_win32_WINNT=0x0601',
250     '/DWINVER=0x0601',
251     '/D_CRT_NONSTDC_NO_WARNINGS',
252     '/D_CRT_SECURE_NO_WARNINGS',
253     language : ['c'],
254   )
255   api_c_args = [
256     '/DWAFFLE_API_VERSION=@0@'.format('0x0108'),
257     '/DWAFFLE_API_EXPERIMENTAL',
258   ]
259 endif
261 install_data('README.md', 'LICENSE.txt', 'HACKING.txt', install_dir : docdir)
262 install_subdir('doc/release-notes', install_dir : docdir)
265 if get_option('build-tests')
266   dep_cmocka = dependency('cmocka', fallback : ['cmocka', 'dep_cmocka'])
267 else
268   dep_cmocka = _dep_null
269 endif
271 subdir('include')
272 subdir('third_party')
273 subdir('src')
274 subdir('doc')
275 subdir('man')
276 if get_option('build-tests')
277   subdir('tests')
278 endif
279 if get_option('build-examples')
280   subdir('examples')
281 endif
283 summary({
284   'Installation prefix': get_option('prefix'),
285   'Enabled backends': backends,
286   'Build tests': get_option('build-tests'),
287   'Build man pages': get_option('build-manpages'),
288   'Build html docs': get_option('build-htmldocs'),
289   'Build examples': get_option('build-examples'),
290 }, bool_yn: true)