1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
project('stela', 'c', version: '0.01',
meson_version: '>=0.63.0',
default_options: ['warning_level=2', 'c_std=c99'],
license: 'GPL-3.0-only')
compiler = meson.get_compiler('c')
cmake = import('cmake')
is_debug = get_option('debug')
is_minsize = get_option('optimization') == 's'
is_linux = host_machine.system() == 'linux'
is_windows = host_machine.system() == 'windows'
is_macos = host_machine.system() == 'darwin'
is_android = host_machine.system() == 'android'
if get_option('window') == 'null'
error('No window type selected.')
endif
if get_option('window') in ['x11', 'wayland']
if not (is_linux and not is_android)
error('Wayland is only supported on linux desktop.')
endif
endif
if get_option('window') == 'glfm' and not is_android
error('GLFM only supported on android.')
endif
alabaster = subproject('libalabaster').get_variable('alabaster')
naunet = subproject('libnaunet', default_options: ['event-loop=disabled']).get_variable('naunet')
stela_src = ['src/window.c']
stela_inc = [include_directories('include')]
stela_deps = [alabaster, naunet]
stela_args = []
if get_option('window') in ['x11', 'wayland']
stela_src += ['src/poll_common.c']
endif
if get_option('poll') == 'inline'
stela_args += ['-DSTELA_POLL_INLINE']
elif get_option('poll') == 'fd'
stela_args += ['-DSTELA_POLL_FD']
endif
if get_option('event-buffer')
stela_args += ['-DSTELA_EVENT_BUFFER']
endif
if get_option('pause')
stela_args += ['-DSTELA_PAUSE']
endif
if get_option('api') == 'null'
stela_args += ['-DSTELA_API_NULL']
elif get_option('api') in ['gl', 'gles']
use_glad = false
use_gles = get_option('api') == 'gles'
if is_linux or is_android
stela_args += ['-DSTELA_USE_EGL']
endif
if get_option('window') in ['wayland', 'x11', 'kms']
if get_option('egl-brcm')
# Raspberry Pi (legacy proprietary driver)
#brcmEGL = dependency('brcmegl')
#brcmGLESv2 = dependency('brcmglesv2')
#stela_deps += [brcmEGL, brcmGLESv2]
#use_gles = true
# Try to use Mesa VC4 instead.
endif
egl = dependency('egl')
stela_deps += [egl]
stela_src += ['src/egl_common.c']
endif
if use_glad
glad_opts = use_gles ? 'use_gles=true' : 'use_gles=false'
stela_deps += [subproject('glad', default_options: glad_opts).get_variable('glad')]
stela_args += ['-DSTELA_USE_GLAD']
elif is_windows
stela_deps += [compiler.find_library('opengl32')]
elif not is_android
stela_deps += [dependency('gl')]
endif
if use_gles
stela_args += ['-DSTELA_USE_GLES']
else
if compiler.has_header('GL/glext.h')
stela_args += ['-DSTELA_HAS_GLEXT']
endif
endif
stela_src += ['src/gl_common.c']
stela_args += ['-DSTELA_API_OPENGL']
elif get_option('api') == 'vulkan'
if not compiler.has_header('vulkan/vulkan.h')
error('Vulkan headers not found.')
endif
vulkan = dependency('vulkan')
vulkan_headers = vulkan.partial_dependency(includes: true, compile_args: true, link_args: true)
stela_src += ['src/vk_common.c']
stela_deps += [vulkan_headers]
stela_args += ['-DSTELA_API_VULKAN']
elif get_option('api') == 'dx11'
stela_args += ['-DSTELA_API_DX11']
endif
if get_option('window') == 'x11'
x11 = dependency('x11')
xext = dependency('xext')
xrandr = dependency('xrandr')
xfixes = dependency('xfixes')
xcursor = dependency('xcursor')
xkb = dependency('xkbcommon')
stela_src += ['src/window_x11.c']
stela_deps += [x11, xext, xrandr, xfixes, xcursor, xkb]
stela_args += ['-DSTELA_WINDOW_X11']
elif get_option('window') == 'wayland'
wl_client = dependency('wayland-client', default_options: [
'libraries=true',
'scanner=false',
'tests=false',
'documentation=false',
'dtd_validation=false'
], required: false, allow_fallback: false)
wl_cursor = dependency('wayland-cursor', allow_fallback: false)
wl_egl = dependency('wayland-egl', allow_fallback: false)
wl_protocols = dependency('wayland-protocols', version: '>=1.32', required: false, allow_fallback: false)
if not wl_protocols.found()
wl_protocols_datadir = subproject('wayland-protocols', default_options: [
'tests=false'
]).get_variable('wayland_protocols_srcdir')
else
wl_protocols_datadir = wl_protocols.get_variable(pkgconfig: 'pkgdatadir')
endif
wlr_protocols = dependency('wlr-protocols', required: false, allow_fallback: false)
if not wlr_protocols.found()
wlr_protocols_datadir = subproject('wlr-protocols').get_variable('wlr_protocols_srcdir')
else
wlr_protocols_datadir = wlr_protocols.get_variable(pkgconfig: 'pkgdatadir')
endif
scanner = find_program('wayland-scanner', native: true)
scanner_private_code = generator(scanner, output: '@BASENAME@-protocol.c',
arguments: ['private-code','@INPUT@', '@OUTPUT@'])
scanner_client_header = generator(scanner, output: '@BASENAME@-client-protocol.h',
arguments: ['client-header', '@INPUT@','@OUTPUT@'])
protocols_src = [
scanner_private_code.process(
wl_protocols_datadir + '/stable/xdg-shell/xdg-shell.xml'),
scanner_private_code.process(
wl_protocols_datadir + '/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'),
scanner_private_code.process(
wl_protocols_datadir + '/unstable/tablet/tablet-unstable-v2.xml'),
scanner_private_code.process(
wl_protocols_datadir + '/staging/cursor-shape/cursor-shape-v1.xml'),
scanner_private_code.process(
wl_protocols_datadir + '/staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml'),
#scanner_private_code.process(
# wl_protocols_datadir + '/unstable/xdg-output/xdg-output-unstable-v1.xml'),
scanner_private_code.process(
wl_protocols_datadir + '/stable/presentation-time/presentation-time.xml'),
scanner_private_code.process(
wlr_protocols_datadir + '/unstable/wlr-layer-shell-unstable-v1.xml'),
#scanner_private_code.process(
# wlr_protocols_datadir + '/unstable/wlr-foreign-toplevel-management-unstable-v1.xml')
]
protocols_headers = [
scanner_client_header.process(
wl_protocols_datadir + '/stable/xdg-shell/xdg-shell.xml'),
scanner_client_header.process(
wl_protocols_datadir + '/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'),
scanner_client_header.process(
wl_protocols_datadir + '/unstable/tablet/tablet-unstable-v2.xml'),
scanner_client_header.process(
wl_protocols_datadir + '/staging/cursor-shape/cursor-shape-v1.xml'),
scanner_client_header.process(
wl_protocols_datadir + '/staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml'),
#scanner_client_header.process(
# wl_protocols_datadir + '/unstable/xdg-output/xdg-output-unstable-v1.xml'),
scanner_client_header.process(
wl_protocols_datadir + '/stable/presentation-time/presentation-time.xml'),
scanner_client_header.process(
wlr_protocols_datadir + '/unstable/wlr-layer-shell-unstable-v1.xml'),
#scanner_client_header.process(
# wlr_protocols_datadir + '/unstable/wlr-foreign-toplevel-management-unstable-v1.xml')
]
lib_protocols = static_library(
'protocols', protocols_src + protocols_headers, dependencies: [wl_client, wl_cursor])
protocols = declare_dependency(link_with: lib_protocols, sources: protocols_headers)
stela_src += ['src/window_wayland.c']
stela_deps += [wl_egl, protocols]
stela_args += ['-DSTELA_WINDOW_WAYLAND']
elif get_option('window') == 'win32'
stela_src += ['src/window_win32.c']
if not get_option('win32-compat')
stela_deps += [compiler.find_library('dwmapi')]
endif
stela_args += ['-DSTELA_WINDOW_WIN32']
elif get_option('window') == 'glfw'
glfw3 = dependency('glfw3', required: false, allow_fallback: false)
if not glfw3.found()
glfw_opts = cmake.subproject_options()
reltype = is_minsize ? 'MinSizeRel' : 'Release'
glfw_opts.add_cmake_defines({ 'CMAKE_BUILD_TYPE': is_debug ? 'Debug' : reltype })
glfw_opts.add_cmake_defines({ 'GLFW_INSTALL': false })
glfw_opts.add_cmake_defines({ 'GLFW_BUILD_EXAMPLES': false })
glfw_opts.add_cmake_defines({ 'GLFW_BUILD_TESTS': false })
glfw_opts.add_cmake_defines({ 'GLFW_BUILD_DOCS': false })
glfw_opts.add_cmake_defines({ 'GLFW_BUILD_WAYLAND': is_linux })
glfw_opts.add_cmake_defines({ 'GLFW_BUILD_X11': is_linux })
glfw_opts.add_cmake_defines({ 'GLFW_BUILD_WIN32': is_windows })
glfw_opts.add_cmake_defines({ 'GLFW_BUILD_COCAO': is_macos })
glfw3 = cmake.subproject('glfw3', options: glfw_opts).dependency('glfw')
endif
stela_src += ['src/window_glfw.c']
stela_deps += [glfw3]
stela_args += ['-DSTELA_WINDOW_GLFW']
elif get_option('window') == 'glfm'
glfm = dependency('glfm', required: false, allow_fallback: false)
if not glfm.found()
glfm_opts = cmake.subproject_options()
reltype = is_minsize ? 'MinSizeRel' : 'Release'
glfm_opts.add_cmake_defines({ 'CMAKE_BUILD_TYPE': is_debug ? 'Debug' : reltype })
glfm_opts.add_cmake_defines({ 'CMAKE_POSITION_INDEPENDENT_CODE': true })
glfm = cmake.subproject('glfm', options: glfm_opts).dependency('glfm')
endif
stela_src += ['src/window_glfm.c']
stela_deps += [glfm]
stela_args += ['-DSTELA_WINDOW_GLFM']
endif
stela = declare_dependency(include_directories: stela_inc,
dependencies: stela_deps, sources: stela_src,
compile_args: stela_args)
if not meson.is_subproject()
stela_lib = shared_library('stela', dependencies: stela, install: false)
endif
if get_option('tests').allowed() and not meson.is_subproject()
subdir('tests')
endif
|