-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmeson.build
314 lines (276 loc) · 9.07 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
project('rtfilter', 'c',
version : '1.3',
default_options : [
'warning_level=3',
],
license : 'LGPL-3.0',
meson_version: '>= 0.49'
)
# follow semantic versionning (https://semver.org)
# * MAJOR version when you make incompatible API changes,
# * MINOR version when you add functionality in a backwards-compatible manner
# * PATCH version when you make backwards-compatible bug fixes.
major = '1'
minor = '1'
patch = '1'
version = major + '.' + minor + '.' + patch
cc = meson.get_compiler('c')
configuration_inc = include_directories('.', 'src')
# additional (optional) warnings
flags = [
'-Wshadow',
'-Wstrict-prototypes',
'-Wmissing-prototypes',
]
add_project_arguments(cc.get_supported_arguments(flags), language : 'c')
# define HAVE_CONFIG_H with compiler command line to include the generated
# config.h file (same as autotools)
add_project_arguments('-DHAVE_CONFIG_H', language : 'c')
config = configuration_data()
subdir('config/api-exports')
# Defined for compatibility with autotools
# The other such macros defined by autotools are not used and will not be added
config.set('PACKAGE_STRING', '"' + meson.project_name() + ' ' + meson.project_version() + '"')
# list of mandatory headers
check_headers = [
'complex.h',
'math.h',
]
foreach h : check_headers
cc.check_header(h)
endforeach
# sse instructions handling
sse_common_sources = files('src/filter-funcs.h', 'src/filter-internal.h')
sse_libraries = []
if cc.has_header_symbol('cpuid.h', '__get_cpuid')
config.set('HAVE_CPUID', 1)
# sse support
if cc.has_header_symbol('xmmintrin.h', '_mm_set1_ps')
config.set('SUPPORT_SSE_SET', 1)
sse_libraries += static_library('rtfilter sse filter implementation',
sse_common_sources + files('src/filter-sse.c'),
c_args : '-msse',
include_directories : configuration_inc,
)
endif
# sse2 support
if cc.has_header_symbol('emmintrin.h', '_mm_set1_pd')
config.set('SUPPORT_SSE2_SET', 1)
sse_libraries += static_library('rtfilter sse2 filter implementation',
sse_common_sources + files('src/filter-sse2.c'),
c_args : '-msse2',
include_directories : configuration_inc,
)
endif
# sse3 support
if cc.has_header_symbol('pmmintrin.h', '_mm_movehdup_ps')
config.set('SUPPORT_SSE3_SET', 1)
sse_libraries += static_library('rtfilter sse3 filter implementation',
sse_common_sources + files('src/filter-sse3.c'),
c_args : '-msse3',
include_directories : configuration_inc,
)
endif
endif
# check posix_memalign presence
if cc.has_function('posix_memalign', prefix : '#include<stdlib.h>')
config.set('HAVE_POSIX_MEMALIGN', 1)
else
config.set('HAVE_POSIX_MEMALIGN', 0)
endif
# write config file
build_cfg = 'config.h' # named as such to match autotools build system
configure_file(output : build_cfg, configuration : config)
headers = files(
'src/rtfilter.h',
'src/rtf_common.h',
)
sources = files(
'src/common-filters.c',
'src/downsampler.c',
'src/filter.c',
'src/filter-complex-double.c',
'src/filter-complex-single.c',
'src/filter-funcs.h',
'src/filter-inreal-outcomplex-double.c',
'src/filter-inreal-outcomplex-single.c',
'src/filter-internal.h',
'src/filter-real-double.c',
'src/filter-real-single.c',
'src/probesimd.h',
'src/rtf_common.h',
'src/rtfilter.h',
)
install_headers(headers)
libmath = cc.find_library('m', required : true)
rtfilter = shared_library('rtfilter',
sources,
install : true,
version : version,
include_directories : configuration_inc,
link_with : sse_libraries,
dependencies : [libmath],
)
import('pkgconfig').generate(rtfilter)
#
# TESTS
#
librt = []
perf_enabled = true
if get_option('perf').enabled()
# clock_gettime() may be provided by librt or libc depending
# on their versions.
clock_gettime_code = ''' #include <time.h>
int clock_gettime();
int main(void){return 0;} '''
if not cc.links(clock_gettime_code)
if cc.links(clock_gettime_code, args : '-lrt')
librt = cc.find_library('rt', required : get_option('perf'))
elif get_option('perf').enabled()
error('''clock_gettime() cannot be found, but is required to
build the perf-test tool !''')
else
perf_enabled = false
endif
endif
endif
if perf_enabled
# test tool to ease performance regression tests
# not run as part of unit tests
perf_test = executable('perf-test',
files('test/perf-test.c'),
include_directories : configuration_inc,
link_with : rtfilter,
dependencies : [libmath, librt],
)
endif
if get_option('tests').enabled()
checklib = dependency('check', required : get_option('tests'))
test_sources = files(
'test/float-comparison.c',
'test/float-comparison.h',
'test/lowpass_test.c',
'test/rtfilter_combine_test.c',
'test/rtfilter_test.c',
'test/testcases.h',
'test/test-common.c',
'test/test-common.h',
'test/unittests.c'
)
unittests = executable('unittests',
test_sources,
include_directories : include_directories('.', 'src', 'test'),
link_with : rtfilter,
dependencies: [libmath, checklib],
)
test('rtfilter unit tests', unittests)
endif
#
# DOC
#
# compile example as a test, only install the sources
example = executable('documentation example',
files('doc/examples/butterworth.c'),
include_directories : include_directories('.', 'src'),
link_with : rtfilter,
)
install_subdir('doc/examples',
install_dir : get_option('datadir') / 'doc' / 'rtfilter')
install_data(files('AUTHORS', 'COPYING', 'NEWS', 'README.md'),
install_dir : get_option('datadir') / 'doc' / 'rtfilter')
docs_state = 'disabled'
sphinxbuild = find_program('sphinx-build', required : get_option('docs'))
if sphinxbuild.found() and not get_option('docs').disabled()
python3 = import('python').find_installation('python3', required : true)
check_linuxdoc = run_command(python3, '-c', '"import linuxdoc"')
if check_linuxdoc.returncode() != 0 and get_option('docs').enabled()
error('python3 module "linuxdoc" is required to build documentation')
elif check_linuxdoc.returncode() == 0
docs_state = 'enabled'
endif
endif
if docs_state == 'enabled'
doc_sources = files(
'doc/index.rst',
'doc/rtfilter.rst',
)
sphinxbuild_wrapper = files('doc/sphinx-build-wrapper.sh')
gen_man_pages = custom_target('man3',
output : 'man3',
command : [
'sh',
sphinxbuild_wrapper,
sphinxbuild,
meson.source_root(),
'kernel-doc-man',
meson.source_root() / 'doc',
'man3',
],
build_by_default : true,
depend_files : [sources, doc_sources],
install : true,
install_dir : get_option('mandir'),
)
custom_target('html',
output : 'html',
command : [
'sh',
sphinxbuild_wrapper,
sphinxbuild,
meson.source_root(),
'html',
meson.source_root() / 'doc',
'html',
],
build_by_default : true,
depend_files : [sources, doc_sources],
depends : gen_man_pages, # re-use .doctree from man
install : true,
install_dir : get_option('datadir') / 'doc/rtfilter',
)
endif
#
# DEVTOOLS
#
uncrustify = find_program('uncrustify', required : false)
if uncrustify.found()
run_target('checkstyle',
command : [
uncrustify,
'-l', 'c',
'-c', join_paths(meson.source_root(), 'devtools', 'uncrustify.cfg'),
'--check',
sources,
],
)
run_target('fixstyle',
command : [
uncrustify,
'-l', 'c',
'-c', join_paths(meson.source_root(), 'devtools', 'uncrustify.cfg'),
'--replace',
sources,
],
)
endif # uncrustify
codespell = find_program('codespell', required : false)
if codespell.found()
run_target('spelling',
command : [
codespell,
sources,
]
)
endif # codespell
# test public headers for most warnings and C++ compatibility
# only test rtfilter.h and not all exported headers: $(include_HEADERS)
# "rtf_common.h" contains a #warning which would always make the test fail
# otherwise
run_target('api-compat-test',
command : [
'bash',
files('devtools/api-compat-test.sh'),
meson.current_source_dir() / 'src',
files('src/rtfilter.h'),
]
)