-
-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathmeson.build
435 lines (385 loc) · 12 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
project(
'tomlplusplus',
'cpp',
version: '3.2.0',
meson_version: '>=0.54.0',
license: 'MIT',
default_options: [ # https://mesonbuild.com/Builtin-options.html
# core options
'buildtype=release',
'warning_level=3',
'werror=true',
# base options
'b_lto=true',
'b_ndebug=if-release',
# compiler options
'cpp_std=c++17'
]
)
#######################################################################################################################
# compiler management
#######################################################################################################################
compiler = meson.get_compiler('cpp')
message('target cpu_family: @0@'.format(host_machine.cpu_family()))
message('target cpu: @0@'.format(host_machine.cpu()))
message('target system: @0@'.format(host_machine.system()))
message('target endian: @0@'.format(host_machine.endian()))
is_gcc = compiler.get_id() == 'gcc'
is_clang = compiler.get_id() == 'clang'
is_msvc = compiler.get_id() == 'msvc'
is_icc_cl = compiler.get_id() == 'intel-cl'
is_icc = is_icc_cl or compiler.get_id() == 'intel'
is_lld = compiler.get_linker_id() == 'ld.lld'
is_debug = get_option('debug')
is_release = not is_debug
is_pedantic = get_option('pedantic')
is_windows = host_machine.system() == 'windows'
is_x64 = host_machine.cpu_family() == 'x86_64'
is_subproject = meson.is_subproject()
has_exceptions = get_option('cpp_eh') != 'none'
include_dir = include_directories('include')
overrides = []
universal_args = [] # args used in tests, examples, lib, everything
devel_args = [] # args used in everything *but* the lib
message('is_release: @0@'.format(is_release))
message('is_windows: @0@'.format(is_windows))
message('is_x64: @0@'.format(is_x64))
message('has_exceptions: @0@'.format(has_exceptions))
# compiler argument references:
# msvc: https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically?view=vs-2019
# intel and intel-cl: https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-oneapi-dev-guide-and-reference/top/compiler-reference/compiler-options/alphabetical-list-of-compiler-options.html
# gcc:
# clang:
# GCC or Clang
if is_gcc or is_clang
devel_args += '-march=native'
endif
# GCC
if is_gcc
universal_args += [
'-fmax-errors=5',
'-Wno-init-list-lifetime',
]
if is_pedantic
universal_args += [
'-Wcast-align',
'-Wcast-qual',
'-Wctor-dtor-privacy',
'-Wdisabled-optimization',
'-Wfloat-equal',
'-Wimport',
'-Winit-self',
'-Wlogical-op',
'-Wmissing-declarations',
'-Wmissing-field-initializers',
'-Wmissing-format-attribute',
'-Wmissing-include-dirs',
'-Wmissing-noreturn',
'-Wold-style-cast',
'-Woverloaded-virtual',
'-Wpacked',
'-Wpadded',
'-Wpointer-arith',
'-Wredundant-decls',
'-Wshadow',
'-Wsign-conversion',
'-Wsign-promo',
'-Wstack-protector',
'-Wstrict-null-sentinel',
'-Wswitch-default',
'-Wswitch-enum',
'-Wundef',
'-Wunreachable-code',
'-Wunused',
'-Wunused-parameter',
'-Wuseless-cast',
'-Wvariadic-macros',
'-Wwrite-strings',
'-Wmissing-noreturn',
]
endif
if is_release and is_pedantic
universal_args += [
'-Wsuggest-attribute=const',
'-Wsuggest-attribute=pure',
]
endif
endif
# Clang
if is_clang
if is_pedantic
universal_args += '-Weverything'
endif
universal_args += [
'-ferror-limit=5',
'-Wno-unused-command-line-argument',
# flags from here down are disabling stupidly pedantic warnings that only appear with -Weverything
'-Wno-c++98-compat',
'-Wno-c++98-compat-pedantic',
'-Wno-documentation',
'-Wno-documentation-unknown-command',
'-Wno-switch-enum',
'-Wno-covered-switch-default',
]
if get_option('time_trace')
universal_args += ['-ftime-trace']
endif
endif
# MSVC or icc-cl
if is_msvc or is_icc_cl
universal_args += [
'/bigobj',
'/fp:except-', # disable floating-point exceptions
'/Gy', # function-level linking
'/GF', # string pooling
'/openmp-',
'/permissive-',
'/utf-8',
'/Zc:inline'
]
if has_exceptions
universal_args += '/Zc:throwingNew'
endif
if is_release
universal_args += [
'/GL', # whole program optimization
'/Gw', # Optimize Global Data
'/Ob3', # aggressive inlining
'/Oy', # omit frame pointers
'/Oi', # generate intrinsics
]
add_project_link_arguments('/ltcg', language: 'cpp')
endif
if is_pedantic
universal_args += '/W4'
endif
endif
# icc-cl
if is_icc_cl
universal_args += [
'/wd82', # storage class is not first
'/wd177', # unreferenced var
'/wd280', # selector expression is constant (why the fuck is that a warning?)
'/wd411', # class provides no constructor (duh, it's an aggregate)
'/wd869', # parameter "blah" was never referenced
'/wd1011', # missing return statement (false negative)
'/wd1628', # function marked [[noreturn]] returns (false positive)
'/wd2261', # assume with side effects discarded
'/wd2557', # mismatched sign compare
'/wd3280', # declaration hides member (triggered in Catch2)
]
endif
# icc (any)
if is_icc
universal_args += [
'/Qdiag-error-limit:5',
'/Qoption,cpp,--unicode_source_kind,UTF-8',
'/D__builtin_bit_cast(T, v)=([&]()noexcept{ T val; memcpy(&val, &v, sizeof(T)); return val; })()', # __builtin_bit_cast workaround
]
endif
# windows stuff
if is_windows
universal_args += has_exceptions ? '-D_HAS_EXCEPTIONS=1' : '-D_HAS_EXCEPTIONS=0'
elif is_release
overrides += 'strip=true'
endif
# LTO
if is_lld or is_debug or (is_windows and is_clang)
overrides += 'b_lto=false'
endif
#######################################################################################################################
# c++ 20 check
#######################################################################################################################
compiler_supports_cpp20_args = []
if is_gcc or is_clang
compiler_supports_cpp20_args += '-std=c++2a'
elif is_icc
compiler_supports_cpp20_args += '/Qstd=c++2a'
elif is_msvc
compiler_supports_cpp20_args += '/std:c++latest'
endif
compiler_supports_cpp20 = compiler_supports_cpp20_args.length() > 0 and compiler.links('''
#include <version>
#include <string>
#include <iostream>
#include <cstdint>
#include <cstddef>
#include <cstring>
#include <cfloat>
#include <climits>
#include <cmath>
#include <limits>
#include <memory>
#include <iosfwd>
#include <type_traits>
int main()
{
std::string s = "kek";
std::cout << s << std::endl;
return 0;
}
''',
name: 'supports c++20',
args: compiler_supports_cpp20_args
)
#######################################################################################################################
# char8_t check
#######################################################################################################################
compiler_supports_char8_args = []
if is_gcc or is_clang
compiler_supports_char8_args += '-fchar8_t'
endif
compiler_supports_char8 = compiler_supports_cpp20 and compiler.links('''
#include <version>
#include <string_view>
#include <string>
#include <type_traits>
using namespace std::string_view_literals;
#if !defined(__cpp_char8_t) || __cpp_char8_t < 201811 || !defined(__cpp_lib_char8_t) || __cpp_lib_char8_t < 201907
#error oh noes
#endif
static_assert(!std::is_same_v<char, char8_t>);
static_assert(!std::is_same_v<std::string, std::u8string>);
std::u8string func()
{
return std::u8string{ u8"this is a test."sv };
}
int main()
{
return 0;
}
''',
name: 'supports char8_t',
args: [ compiler_supports_cpp20_args, compiler_supports_char8_args ]
)
#######################################################################################################################
# consteval check
# (this doesn't inform the build in any way; it's just so i can see who supports it properly)
#######################################################################################################################
compiler_supports_consteval = compiler_supports_cpp20 and compiler.compiles('''
consteval int test() noexcept
{
return 42;
}
int main()
{
constexpr auto val = test(); // test() should be compiletime-callable
return val;
}
''',
name: 'supports consteval keyword',
args: compiler_supports_cpp20_args
)
compiler_supports_consteval_properly = compiler_supports_consteval and not compiler.compiles('''
consteval int test(int i) noexcept
{
return 42 + i;
}
int get_value() noexcept;
int main()
{
return test(get_value()); // test() should not be runtime-callable
}
''',
name: 'consteval is just renamed constexpr',
args: compiler_supports_cpp20_args
)
#######################################################################################################################
# _Float16 checks
#######################################################################################################################
compiler_supports_float16_args = compiler.get_supported_arguments('-mfp16-format=ieee')
compiler_supports_float16 = get_option('float16') and compiler.links('''
int main()
{
static_assert(sizeof(_Float16) == 2);
_Float16 f = static_cast<_Float16>(1);
const auto f2 = static_cast<float>(f);
const auto f3 = static_cast<_Float16>(0.2L);
return 0;
}
''',
name: 'supports _Float16',
args: compiler_supports_float16_args
)
if compiler_supports_float16
devel_args += compiler_supports_float16_args
endif
#######################################################################################################################
# int128 check
#######################################################################################################################
compiler_supports_int128 = compiler.links('''
#ifndef __SIZEOF_INT128__
#error __SIZEOF_INT128__ wasn't defined!
#endif
#include <cstdint>
int main()
{
static_assert(__SIZEOF_INT128__ == 16);
static_assert(sizeof(__int128_t) == 16);
static_assert(sizeof(__uint128_t) == 16);
__int128_t i = static_cast<__int128_t>(1);
const auto i2 = static_cast<int64_t>(i);
const auto i3 = static_cast<int32_t>(i);
return 0;
}
''',
name: 'supports __int128_t'
)
#######################################################################################################################
# float128 check
#######################################################################################################################
compiler_supports_float128 = compiler.links('''
#ifndef __SIZEOF_FLOAT128__
#error __SIZEOF_FLOAT128__ wasn't defined!
#endif
#ifndef __FLT128_MANT_DIG__
#error __FLT128_MANT_DIG__ wasn't defined!
#endif
#ifndef __LDBL_MANT_DIG__
#error __LDBL_MANT_DIG__ wasn't defined!
#endif
#if __FLT128_MANT_DIG__ <= __LDBL_MANT_DIG__
#error __FLT128_MANT_DIG__ was <= __LDBL_MANT_DIG__
#endif
int main()
{
static_assert(__SIZEOF_FLOAT128__ == 16);
static_assert(sizeof(__float128) == 16);
__float128 f = static_cast<__float128>(1);
const auto f2 = static_cast<long double>(f);
const auto f3 = static_cast<double>(f);
return 0;
}
''',
name: 'supports __float128'
)
if compiler_supports_float16 or compiler_supports_float128 or compiler_supports_int128
devel_args += compiler.get_supported_arguments('-fext-numeric-literals')
endif
#######################################################################################################################
# subdirectories
#######################################################################################################################
# Empty dependency that will be filled either in src/ or include/
tomlplusplus_dep = dependency('', required: false)
if get_option('compile_library')
subdir('src')
else
subdir('include')
endif
build_tests = get_option('build_tests') and not is_subproject
if build_tests
subdir('tests')
endif
build_examples = get_option('build_examples') and not is_subproject
if build_examples
subdir('examples')
endif
build_tt = (get_option('build_tt_encoder') or get_option('build_tt_encoder')) and not is_subproject
if build_tt
subdir('toml-test')
endif
if not is_subproject
install_subdir('include'/'toml++', install_dir: get_option('includedir'))
endif
# Allow subproject usage
meson.override_dependency(meson.project_name(), tomlplusplus_dep)