-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
meson.build
250 lines (213 loc) · 6.1 KB
/
meson.build
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
244
245
246
247
248
249
250
majorver = '0'
apiver = '6'
fixver = '0'
version = majorver + '.' + apiver + '.' + fixver
c_opts = [
'-D_ISOC99_SOURCE', '-D_GNU_SOURCE', '-D_XOPEN_SOURCE=700',
'-U__STRICT_ANSI__', '-fvisibility=hidden',
'-Wmissing-prototypes', '-Wno-pointer-sign'
]
# glslang needs c++11
cpp_opts = [
'-std=c++11', '-fvisibility=hidden',
]
# Build options mostly taken from mpv
build_opts = [
# Warnings
'-Wall', '-Wundef', '-Wshadow', '-Wparentheses', '-Wpointer-arith',
# Warnings to treat as errors
'-Werror=implicit-function-declaration',
]
cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp')
if cc.has_argument('-Wincompatible-pointer-types')
build_opts += ['-Werror=incompatible-pointer-types']
endif
# clang's version of -Wmissing-braces rejects the common {0} initializers
if cc.get_id() == 'clang'
build_opts += ['-Wno-missing-braces']
endif
# Global dependencies
build_deps = [
dependency('threads'),
cc.find_library('m', required: false),
]
vulkan = dependency('vulkan', version: '>=1.0.42', required: get_option('vulkan'))
# Source files
sources = [
'colorspace.c',
'common.c',
'context.c',
'dither.c',
'dispatch.c',
'filters.c',
'gpu.c',
'renderer.c',
'shaders.c',
'shaders/colorspace.c',
'shaders/sampling.c',
'spirv.c',
'swapchain.c',
'utils/upload.c',
# Helpers ported from mpv or other projects
'bstr/bstr.c',
'bstr/format.c',
'3rdparty/siphash.c',
'ta/ta.c',
'ta/ta_utils.c',
'ta/talloc.c',
]
tests = [
'context.c',
'colorspace.c',
'dither.c',
'filters.c',
'utils.c',
]
# Work-arounds for glslang braindeath
glslang_combined = disabler()
glslang_min_ver = 2763
glslang_req = get_option('glslang')
glslang_deps = [
cxx.find_library('glslang', required: glslang_req),
cxx.find_library('HLSL', required: glslang_req),
cxx.find_library('OGLCompiler', required: glslang_req),
cxx.find_library('OSDependent', required: glslang_req),
cxx.find_library('SPIRV', required: glslang_req),
cxx.find_library('SPVRemapper', required: glslang_req),
]
glslang_found = true
foreach d : glslang_deps
glslang_found = glslang_found and d.found()
endforeach
if glslang_found
glslang_ver = cxx.get_define('GLSLANG_PATCH_LEVEL',
prefix: '#include <glslang/Include/revision.h>'
).to_int()
if glslang_ver >= glslang_min_ver
glslang_combined = declare_dependency(dependencies: glslang_deps)
else
error('glslang revision @0@ too old! Must be at least @1@'
.format(glslang_ver, glslang_min_ver))
endif
endif
# Optional dependencies / components
components = [
{
'name': 'lcms',
'deps': dependency('lcms2', version: '>=2.6', required: get_option('lcms')),
'srcs': 'lcms.c',
}, {
'name': 'glslang',
'deps': glslang_combined,
'srcs': [ 'glsl/glslang.cc',
'spirv_glslang.c',
],
}, {
'name': 'shaderc',
'deps': cc.find_library('shaderc_shared', required: get_option('shaderc')),
'srcs': 'spirv_shaderc.c',
}, {
'name': 'vulkan',
'deps': vulkan,
'srcs': [ 'vulkan/command.c',
'vulkan/context.c',
'vulkan/formats.c',
'vulkan/gpu.c',
'vulkan/malloc.c',
'vulkan/swapchain.c',
'vulkan/utils.c',
],
'test': 'vulkan.c'
}
]
# Configuration
conf = configuration_data()
conf.set('majorver', majorver)
conf.set('apiver', apiver)
conf.set('fixver', fixver)
conf.set_quoted('version', 'v' + version)
## Update PL_VERSION with `git describe` information if available
git = find_program('git', required: false)
if git.found()
gitdesc = run_command(git, 'describe')
if gitdesc.returncode() == 0
conf.set_quoted('version', gitdesc.stdout().strip())
endif
endif
# Build process
defs = ''
comps = configuration_data()
foreach c : components
name = c['name']
deps = c['deps']
pretty = name.underscorify().to_upper()
defs += '#define PL_HAVE_@0@ @1@\n'.format(pretty, deps.found() ? 1 : 0)
if deps.found()
comps.set(name, 1)
build_deps += deps
sources += c.get('srcs', [])
tests += c.get('test', [])
endif
endforeach
# Check to see if libplacebo built this way is sane
if not comps.has('vulkan')
warning('Building without support for Vulkan. Currently, libplacebo only ' +
'supports the Vulkan graphics API. libplacebo built this way still ' +
'has some limited use (e.g. generating GLSL shaders), but most of ' +
'its functionality will be missing or impaired!')
endif
if comps.has('vulkan') and not (comps.has('shaderc') or comps.has('glslang'))
error('Building with support for Vulkan requires either `shaderc` or ' +
'`glslang` to be of any use, otherwise libplacebo would fail to ' +
'compile GLSL to SPIR-V (needed by the Vulkan API)!')
endif
# Generate the config.h file
conf.set('extra_defs', defs)
configure_file(
input: 'config.h.in',
output: 'config.h',
install_dir: 'include/libplacebo',
configuration: conf,
)
# Build process
add_project_arguments(build_opts + c_opts, language: 'c')
add_project_arguments(build_opts + cpp_opts, language: 'cpp')
inc = include_directories('./include')
lib = library('placebo', sources,
install: true,
dependencies: build_deps,
soversion: apiver,
include_directories: inc,
)
# Install process
install_subdir('include/libplacebo', install_dir: get_option('includedir'))
pkg = import('pkgconfig')
pkg.generate(
name: meson.project_name(),
description: 'Reusable library for GPU-accelerated video/image rendering',
libraries: lib,
version: version,
)
# Tests
tdeps = [ declare_dependency(link_with: lib) ]
if get_option('tests')
foreach t : tests
e = executable('test.' + t, 'tests/' + t,
dependencies: build_deps + tdeps,
objects: lib.extract_all_objects(),
include_directories: inc
)
test(t, e)
endforeach
endif
if get_option('bench')
if not vulkan.found()
error('Compiling the benchmark suite requires vulkan support!')
endif
bench = executable('bench', 'tests/bench.c',
dependencies: build_deps + tdeps,
include_directories: inc
)
test('benchmark', bench, is_parallel: false, timeout: 600)
endif