core/tests: correct function type
[mesa-waffle.git] / meson.build
blob95643836eb61ceeca646a69eccda0e8ef555ae82
1 # Copyright © 2017 Dylan Baker
2 # Copyright © 2018-2019 Intel Corporation
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
9 # - Redistributions of source code must retain the above copyright notice, this
10 #   list of conditions and the following disclaimer.
12 # - Redistributions in binary form must reproduce the above copyright notice,
13 #   this list of conditions and the following disclaimer in the documentation
14 #   and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 project(
28   'waffle',
29   ['c'],
30   version : '1.7.0',
31   license : 'BSD2', 
32   meson_version : '>= 0.49',
33   default_options : ['c_std=c99', 'buildtype=debugoptimized'],
36 waffle_name = meson.project_name() + '-1'
37 docdir = join_paths(get_option('datadir'), 'doc', meson.project_name() + '1')
39 build_x11_egl = false
40 build_wayland = false
41 build_glx = false
42 build_gbm = false
43 build_surfaceless = false
44 build_nacl = get_option('nacl')
45 build_wgl = ['windows', 'cygwin'].contains(host_machine.system())
46 build_cgl = host_machine.system() == 'darwin'
48 if build_nacl
49   add_languages('cpp')
50 endif
52 if build_cgl
53   add_languages('objc')
54 endif
56 cc = meson.get_compiler('c')
58 _dep_null = dependency('', required : false)
59 dep_threads = dependency('threads')
60 dep_dl = cc.find_library('dl', required : false)
61 dep_nacl = _dep_null
62 dep_gl = _dep_null
63 dep_egl = _dep_null
64 dep_wayland_client = _dep_null
65 dep_wayland_egl = _dep_null
66 dep_wayland_scanner = _dep_null
67 dep_wayland_proto = _dep_null
68 dep_x11_xcb = _dep_null
69 dep_gbm = _dep_null
70 dep_udev = _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_egl = dependency('egl', required : get_option('gbm'))
96   dep_gbm = dependency('gbm', required : get_option('gbm'))
97   dep_udev = dependency('libudev', required : get_option('gbm'))
98   build_gbm = dep_egl.found() and dep_gbm.found() and dep_udev.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   if dep_wayland_client.found()
108     wayland_core_xml = join_paths(dep_wayland_client.get_pkgconfig_variable('pkgdatadir'),
109     'wayland.xml')
110   endif
111   dep_wayland_egl = dependency(
112     'wayland-egl', version : '>= 9.1', required : get_option('wayland'),
113   )
114   dep_wayland_scanner = dependency(
115     'wayland-scanner', version : '>= 1.15', required : get_option('wayland'),
116   )
117   if dep_wayland_scanner.found()
118     prog_wayland_scanner = find_program(dep_wayland_scanner.get_pkgconfig_variable('wayland_scanner'))
119   endif
120   dep_wayland_proto = dependency(
121     'wayland-protocols', version  : '>= 1.12', required : get_option('wayland'),
122   )
123   if dep_wayland_proto.found()
124     wayland_xdg_shell_xml = join_paths(dep_wayland_proto.get_pkgconfig_variable('pkgdatadir'),
125     'stable/xdg-shell/xdg-shell.xml')
126   endif
127   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()
129   # We're interested only in the headers provided
130   # FINISHME: make x11_xcb and udev compile-only dependency
131   _include_deps = [ dep_gl, dep_egl, dep_gbm, dep_wayland_client, dep_wayland_egl ]
132   foreach d : _include_deps
133     if d.found()
134       d = d.partial_dependency(compile_args : true)
135     endif
136   endforeach
137 endif
139 dep_bash = dependency('bash-completion', required : false)
140 if dep_bash.found()
141   bashcompletiondir = dep_bash.get_pkgconfig_variable('completionsdir')
142 else
143   bashcompletiondir = join_paths(get_option('datadir'), 'bash-completion/completions')
144 endif
145 install_data('shell-completion/bash/wflinfo', install_dir : bashcompletiondir)
147 zshcompletiondir = join_paths(get_option('datadir'), 'zsh/site-functions')
148 install_data('shell-completion/zsh/_wflinfo', install_dir : zshcompletiondir)
150 # Set pre-processor flags
151 if build_wgl
152     add_project_arguments('-DWAFFLE_HAS_WGL', language : ['c', 'cpp'])
153 elif build_cgl
154     add_project_arguments('-DWAFFLE_HAS_CGL -DGL_SILENCE_DEPRECATION', language : ['c', 'obj'])
155 else
156   if build_x11_egl
157     add_project_arguments('-DWAFFLE_HAS_X11_EGL', language : ['c', 'cpp'])
158   endif
159   if build_glx
160     add_project_arguments('-DWAFFLE_HAS_GLX', language : ['c', 'cpp'])
161   endif
162   if build_wayland
163     add_project_arguments('-DWAFFLE_HAS_WAYLAND', language : ['c', 'cpp'])
164   endif
165   if build_gbm
166     add_project_arguments('-DWAFFLE_HAS_GBM', language : ['c', 'cpp'])
167   endif
168   if build_surfaceless
169     add_project_arguments('-DWAFFLE_HAS_SURFACELESS_EGL', language : ['c', 'cpp'])
170   endif
171 endif
173 if build_nacl
174   add_project_arguments('-DWAFFLE_HAS_NACL', language : ['c', 'cpp'])
175 endif
177 if cc.get_argument_syntax() == 'gcc'
178   if cc.compiles('''
179       static __thread int x;
180       int main() {
181         x = 42;
182         return x;
183       }''',
184       args : '-Werror',
185       name : 'Thread Local Storage')
186     add_project_arguments('-DWAFFLE_HAS_TLS', language : ['c', 'cpp'])
188     if cc.compiles('''
189         static __thread int x __attribute__((tls_model("initial-exec")));
190         int main() {
191           x = 42;
192           return x;
193         }''',
194         args : '-Werror',
195         name : 'TLS model "Initial Exec"')
196       add_project_arguments('-DWAFFLE_HAS_TLS_MODEL_INITIAL_EXEC', language : ['c', 'cpp'])
197     endif
198   endif
200   add_project_arguments('-D_XOPEN_SOURCE=700', language : ['c', 'cpp'])
202   if not build_nacl
203     add_project_arguments(
204       cc.get_supported_arguments([
205         '-Werror=implicit-function-declaration',
206       ]),
207       language : ['c', 'cpp'],
208     )
209   endif
211   add_project_arguments(
212     cc.get_supported_arguments([
213       '-Werror=incompatible-pointer-types',
214       '-Werror=int-conversion',
215       '-Werror=missing-prototypes',  # TODO: breaks on MacOS?
216       '-Werror=pointer-arith',
217       '-Werror=undef',
218     ]),
219     language : ['c', 'cpp'],
220   )
221   
222   if host_machine.system() == 'windows'
223     if cc.has_argument('-static-libgcc')
224       add_project_link_arguments('-static-libgcc', language : ['c', 'cpp'])
225     endif
226   endif
227   api_c_args = [
228     '-DWAFFLE_API_VERSION=@0@'.format('0x0107'),
229     '-DWAFFLE_API_EXPERIMENTAL',
230   ]
231 elif cc.get_argument_syntax() == 'msvc'
232   add_project_arguments(
233     '/D_win32_WINNT=0x0601',
234     '/DWINVER=0x0601',
235     '/D_CRT_NONSTDC_NO_WARNINGS',
236     '/D_CRT_SECURE_NO_WARNINGS',
237     language : ['c'],
238   )
239   api_c_args = [
240     '/DWAFFLE_API_VERSION=@0@'.format('0x0107'),
241     '/DWAFFLE_API_EXPERIMENTAL',
242   ]
243 endif
245 if build_nacl
246   add_project_arguments('-DWAFFLE_HAS_NACL', language : ['c', 'cpp'])
247 endif
249 install_data('README.md', 'LICENSE.txt', 'HACKING.txt', install_dir : docdir)
250 install_subdir('doc/release-notes', install_dir : docdir)
253 if get_option('build-tests')
254   dep_cmocka = dependency('cmocka', fallback : ['cmocka', 'dep_cmocka'])
255 else
256   dep_cmocka = _dep_null
257 endif
259 subdir('include')
260 subdir('third_party')
261 subdir('src')
262 subdir('doc')
263 subdir('man')
264 if get_option('build-tests')
265   subdir('tests')
266 endif
267 if get_option('build-examples')
268   subdir('examples')
269 endif