-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathmeson.build
207 lines (184 loc) · 4.6 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
# Test Build Definition
libc_test_files = files(
'main.c',
'crt/crt_init_array.c',
'crt/crt_tests.c',
'ctype/ctype_tests.c',
'ctype/isalnum.c',
'ctype/isalpha.c',
'ctype/isascii.c',
'ctype/isblank.c',
'ctype/iscntrl.c',
'ctype/isdigit.c',
'ctype/isgraph.c',
'ctype/islower.c',
'ctype/isprint.c',
'ctype/ispunct.c',
'ctype/isspace.c',
'ctype/isupper.c',
'ctype/isxdigit.c',
'ctype/toascii.c',
'ctype/tolower.c',
'ctype/toupper.c',
'stdlib/abs.c',
'stdlib/atof.c',
'stdlib/atoi.c',
'stdlib/atol.c',
'stdlib/atoll.c',
'stdlib/bsearch.c',
'stdlib/calloc.c',
'stdlib/div.c',
'stdlib/heapsort.c',
'stdlib/imaxabs.c',
'stdlib/imaxdiv.c',
'stdlib/labs.c',
'stdlib/ldiv.c',
'stdlib/llabs.c',
'stdlib/lldiv.c',
'stdlib/qsort_r.c',
'stdlib/qsort.c',
'stdlib/rand.c',
'stdlib/realloc.c',
'stdlib/stdlib_tests.c',
'stdlib/strtod.c',
'stdlib/strtof.c',
'stdlib/strtol.c',
'stdlib/strtoll.c',
'stdlib/strtoul.c',
'stdlib/strtoull.c',
'string/memcmp.c',
'string/memcpy.c',
'string/memmem.c',
'string/memmove.c',
'string/memset.c',
'string/strcat.c',
'string/strchr.c',
'string/strcmp.c',
'string/strcpy.c',
'string/strdup.c',
'string/string_tests.c',
'string/strlen.c',
'string/strncat.c',
'string/strncmp.c',
'string/strncpy.c',
'string/strndup.c',
'string/strnlen.c',
'string/strnstr.c',
'string/strrchr.c',
'string/strstr.c',
'string/strtok.c',
'test/rand.c',
'test/ulpsDistance.c'
)
clangtidy_files += libc_test_files
#######################
# Test Compiler Flags #
#######################
libc_test_flags = native_c_compiler.get_supported_arguments(
'-Wno-unused-parameter',
# We intentionally run the following scenarios in our tests
'-Wno-stringop-truncation',
'-Wno-stringop-overflow',
)
optimization = get_option('optimization')
if disable_builtins == false and optimization == '0'
libc_test_flags += '-DBUILTINS_ARE_ENABLED'
else
message('Some tests are disabled when builtins and/or optimizations are enabled.')
endif
#################################
# Enable CRT Testing if on MacOS #
#################################
if build_machine.system() == 'darwin'
crt_test_dep = declare_dependency(
sources: crt_files_for_test,
compile_args: '-DENABLE_CRT_TESTING'
)
else
crt_test_dep = []
endif
###############
# Test Target #
###############
libc_tests = executable('libc_test',
libc_test_files,
dependencies: [
cmocka_native_dep,
libc_hosted_native_dep,
crt_test_dep,
],
link_args: [
native_map_file.format(meson.current_build_dir() + '/libc_test'),
],
c_args: libc_test_flags,
native: true,
build_by_default: meson.is_subproject() == false,
)
stackprotect_test = executable('stackprotect_test',
['app/stackcheck_main.c', stack_protection_file],
c_args: ['-fstack-protector-all', libc_native_stack_protect_flags],
link_args: native_map_file.format(meson.current_build_dir() + '/stackprotect_test'),
dependencies: libc_hosted_native_dep,
native: true,
build_by_default: meson.is_subproject() == false
)
################################
# Cross Compilation "Test" App #
################################
# This application is used to confirm linking behavior, primarily for cross builds
if meson.is_cross_build() and meson.is_subproject() == false
host_objcopy = find_program(meson.get_external_property('objcopy'),
required: false, disabler: true)
if host_objcopy.found() == false
message('Specified objcopy not found, .hex and .bin conversion is disabled.')
endif
sample_app = executable('sample_app',
'app/main.c',
dependencies: libc_dep,
c_args: '-fstack-protector-all',
link_args: [
linker_script_flags,
map_file.format(meson.current_build_dir()+'/sample_app'),
],
link_depends: linker_script_deps,
native: false
)
sample_app_hex = custom_target('sample_app.hex',
input: sample_app,
output: 'sample_app.hex',
command: [host_objcopy, '-O', 'ihex', '@INPUT@', '@OUTPUT@'],
build_by_default: true
)
sample_app_bin = custom_target('sample_app.bin',
input: sample_app,
output: 'sample_app.bin',
command: [host_objcopy, '-O', 'binary', '@INPUT@', '@OUTPUT@'],
build_by_default: true
)
endif
#############################
# Register Tests with Meson #
#############################
test_output_dir = 'CMOCKA_XML_FILE=' + meson.project_build_root() + '/test/%g.xml'
if meson.is_subproject() == false
test('libc_tests',
libc_tests,
env: [
'CMOCKA_MESSAGE_OUTPUT=XML',
test_output_dir
])
test('stackprotect_test',
stackprotect_test,
should_fail: true
)
run_target('libc-tests',
command: [libc_tests]
)
run_target('libc-tests-xml',
command: [
cmocka_with_env_script,
libc_tests,
cmocka_test_output_dir
],
)
endif