blob: 76321038435ff6a9a592ad44024293f547c6b023 [file] [log] [blame]
Roland Levillaind56de912019-06-20 20:55:26 +01001// This Blueprint file loosely follows the logic of cpu_features'
Roland Levillain18318b62019-06-21 19:56:28 +01002// CMakeLists.txt and test/CMakeLists.txt files.
Roland Levillaind56de912019-06-20 20:55:26 +01003
4cc_defaults {
5 name: "cpu_features-defaults",
6 host_supported: true,
7 local_include_dirs: [
8 "include",
Roland Levillaind56de912019-06-20 20:55:26 +01009 ],
10 cflags: [
11 // Reserve 1024 bytes on the stack when reading from `/proc/cpuinfo`.
12 "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
Haibo Huang2519d752019-07-12 18:21:31 -070013 "-Wno-gnu-designator",
Roland Levillaind56de912019-06-20 20:55:26 +010014 ],
15}
16
17cc_library {
18 name: "libcpu_features-utils",
19 defaults: ["cpu_features-defaults"],
20 srcs: [
21 "src/filesystem.c",
22 "src/stack_line_reader.c",
23 "src/string_view.c",
24 ],
Elliott Hughese39557c2019-08-05 12:23:07 -070025 target: {
26 windows: {
27 enabled: true,
28 },
29 },
Roland Levillaind56de912019-06-20 20:55:26 +010030}
31
32cc_library {
33 name: "libcpu_features-unix_based_hardware_detection",
34 defaults: ["cpu_features-defaults"],
35 srcs: [
36 "src/hwcaps.c",
37 "src/unix_features_aggregator.c",
38 ],
39 cflags: [
40 "-DHAVE_DLFCN_H",
41 ],
42 target: {
43 bionic: {
44 cflags: [
45 "-DHAVE_STRONG_GETAUXVAL",
46 ],
47 },
48 },
49 static_libs: [
50 "libcpu_features-utils",
51 ],
52}
53
54cc_library {
55 name: "libcpu_features",
56 defaults: [
57 "cpu_features-defaults",
58 ],
Elliott Hughes7f8ace62019-08-05 11:58:18 -070059 export_include_dirs: ["include"],
Roland Levillaind56de912019-06-20 20:55:26 +010060 whole_static_libs: [
61 "libcpu_features-utils",
62 ],
63 arch: {
64 arm: {
65 srcs: [
66 "src/cpuinfo_arm.c",
67 ],
68 whole_static_libs: [
69 "libcpu_features-unix_based_hardware_detection",
70 ],
71 },
72 arm64: {
73 srcs: [
74 "src/cpuinfo_aarch64.c",
75 ],
76 whole_static_libs: [
77 "libcpu_features-unix_based_hardware_detection",
78 ],
Haibo Huang2519d752019-07-12 18:21:31 -070079 cflags: [
80 "-Wno-gnu-designator",
81 ],
Roland Levillaind56de912019-06-20 20:55:26 +010082 },
83 x86: {
84 srcs: [
85 "src/cpuinfo_x86.c",
86 ],
Haibo Huang2519d752019-07-12 18:21:31 -070087 cflags: [
88 "-Wno-unused-variable",
89 ],
Roland Levillaind56de912019-06-20 20:55:26 +010090 },
91 x86_64: {
92 srcs: [
93 "src/cpuinfo_x86.c",
94 ],
Haibo Huang2519d752019-07-12 18:21:31 -070095 cflags: [
96 "-Wno-unused-variable",
97 ],
Roland Levillaind56de912019-06-20 20:55:26 +010098 },
99 },
Elliott Hughese39557c2019-08-05 12:23:07 -0700100 target: {
101 windows: {
102 enabled: true,
103 },
104 },
Roland Levillaind56de912019-06-20 20:55:26 +0100105}
106
107cc_binary {
108 name: "list_cpu_features",
109 defaults: [
110 "cpu_features-defaults",
111 ],
112 srcs: [
113 "src/utils/list_cpu_features.c",
114 ],
115 static_libs: [
116 "libcpu_features",
117 ],
Roland Levillain61cf9ac2020-09-22 10:52:15 +0100118 arch: {
119 // Function `AddCacheInfo` in `src/utils/list_cpu_features.c` is only used on x86/x86_64 and
120 // triggers an error with `-Werror and `-Wunused-function` on other architectures; disable
121 // the latter flag to avoid compilation errors on those architectures.
122 arm: {
123 cflags: [
124 "-Wno-unused-function",
125 ],
126 },
127 arm64: {
128 cflags: [
129 "-Wno-unused-function",
130 ],
131 },
132 },
Roland Levillaind56de912019-06-20 20:55:26 +0100133}
Roland Levillain18318b62019-06-21 19:56:28 +0100134
Roland Levillain18318b62019-06-21 19:56:28 +0100135// Tests.
136
137cc_defaults {
138 name: "cpu_features-test-defaults",
Roland Levillaindf048ae2019-07-23 18:02:33 +0100139 test_suites: ["device-tests"],
Roland Levillain18318b62019-06-21 19:56:28 +0100140 host_supported: true,
Roland Levillain9ae23c42019-07-24 19:25:53 +0100141 compile_multilib: "both",
Roland Levillain18318b62019-06-21 19:56:28 +0100142 local_include_dirs: [
143 "include",
144 ],
145 cflags: [
Roland Levillainaa4fc412019-07-24 19:51:11 +0100146 "-DCPU_FEATURES_TEST",
Roland Levillain18318b62019-06-21 19:56:28 +0100147 ],
148}
149
150cc_test_library {
151 name: "libcpu_features-string_view",
152 defaults: ["cpu_features-test-defaults"],
153 srcs: [
154 "src/string_view.c",
155 ],
156}
157
158cc_test_library {
159 name: "libcpu_features-filesystem_for_testing",
160 defaults: ["cpu_features-test-defaults"],
161 cflags: [
162 "-DCPU_FEATURES_MOCK_FILESYSTEM",
163 // TODO: Handle unused parameters in
164 // test/filesystem_for_testing.cc and remove this flag.
165 "-Wno-unused-parameter",
166 ],
167 srcs: [
168 "test/filesystem_for_testing.cc",
169 ],
170}
171
172cc_test_library {
173 name: "libcpu_features-hwcaps_for_testing",
174 defaults: ["cpu_features-test-defaults"],
175 cflags: [
176 "-DCPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL",
177 ],
178 srcs: [
179 "test/hwcaps_for_testing.cc",
180 ],
181 static_libs: [
182 "libcpu_features-string_view",
183 "libcpu_features-filesystem_for_testing",
184 ],
185}
186
187cc_defaults {
188 name: "stack_line_reader-defaults",
189 cflags: [
190 "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
191 ],
192}
193
194cc_test_library {
195 name: "libcpu_features-stack_line_reader",
196 defaults: [
197 "cpu_features-test-defaults",
198 "stack_line_reader-defaults",
199 ],
200 srcs: [
201 "src/stack_line_reader.c",
202 ],
203 static_libs: [
204 "libcpu_features-filesystem_for_testing",
205 "libcpu_features-string_view",
206 ],
207}
208
209cc_test_library {
210 name: "libcpu_features-stack_line_reader_for_test",
211 defaults: ["cpu_features-test-defaults"],
212 cflags: [
213 "-DSTACK_LINE_READER_BUFFER_SIZE=16",
214 ],
215 srcs: [
216 "src/stack_line_reader.c",
217 ],
218 whole_static_libs: [
219 "libcpu_features-filesystem_for_testing",
220 "libcpu_features-string_view",
221 ],
222}
223
224cc_test_library {
225 name: "libcpu_features-all_libraries",
226 defaults: [
227 "cpu_features-test-defaults",
228 "stack_line_reader-defaults",
229 ],
230 srcs: [
231 "src/unix_features_aggregator.c",
232 ],
233 whole_static_libs: [
234 "libcpu_features-filesystem_for_testing",
235 "libcpu_features-hwcaps_for_testing",
236 "libcpu_features-stack_line_reader",
237 "libcpu_features-string_view",
238 ],
239}
240
241cc_test {
242 name: "cpu_features-bit_utils_test",
243 defaults: ["cpu_features-test-defaults"],
244 srcs: [
Roland Levillainaa4fc412019-07-24 19:51:11 +0100245 "test/bit_utils_test.cc",
Roland Levillain18318b62019-06-21 19:56:28 +0100246 ],
247}
248
249cc_test {
250 name: "cpu_features-string_view_test",
251 defaults: ["cpu_features-test-defaults"],
252 srcs: [
253 "test/string_view_test.cc",
254 "src/string_view.c",
255 ],
256 static_libs: [
257 "libcpu_features-string_view",
258 ],
259}
260
261cc_test {
262 name: "cpu_features-stack_line_reader_test",
263 defaults: [
264 "cpu_features-test-defaults",
265 "stack_line_reader-defaults",
266 ],
267 cflags: [
268 // TODO: Handle unused funtions in
269 // test/stack_line_reader_test.cc and remove this flag.
270 "-Wno-unused-function",
271 ],
272 srcs: [
273 "test/stack_line_reader_test.cc",
274 ],
275 static_libs: [
276 "libcpu_features-stack_line_reader_for_test",
277 ],
278}
279
280cc_test {
281 name: "cpu_features-unix_features_aggregator_test",
282 defaults: ["cpu_features-test-defaults"],
283 srcs: [
284 "test/unix_features_aggregator_test.cc",
285 ],
286 static_libs: [
287 "libcpu_features-all_libraries",
288 ],
289}
290
Roland Levillain9f7c24e2019-07-11 20:10:02 +0100291cc_test {
292 name: "cpu_features-cpuinfo_test",
293 defaults: [
Roland Levillaind4628f12019-07-24 19:40:34 +0100294 "cpu_features-test-defaults",
295 ],
296 static_libs: [
297 "libcpu_features-all_libraries",
Roland Levillain9f7c24e2019-07-11 20:10:02 +0100298 ],
299 arch: {
300 x86: {
301 cflags: [
302 "-DCPU_FEATURES_MOCK_CPUID_X86",
303 "-Wno-unused-variable",
304 ],
305 srcs: [
306 "test/cpuinfo_x86_test.cc",
307 "src/cpuinfo_x86.c",
308 ],
309 },
310 x86_64: {
311 cflags: [
312 "-DCPU_FEATURES_MOCK_CPUID_X86",
313 "-Wno-unused-variable",
314 ],
315 srcs: [
316 "test/cpuinfo_x86_test.cc",
317 "src/cpuinfo_x86.c",
318 ],
319 },
320 arm: {
321 cflags: [
322 "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
323 ],
324 srcs: [
325 "test/cpuinfo_arm_test.cc",
326 "src/cpuinfo_arm.c",
327 ],
328 },
329 arm64: {
330 cflags: [
331 "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
332 "-Wno-gnu-designator",
333 ],
334 srcs: [
335 "test/cpuinfo_aarch64_test.cc",
336 "src/cpuinfo_aarch64.c",
337 ],
Roland Levillainaa4fc412019-07-24 19:51:11 +0100338 },
Roland Levillain9f7c24e2019-07-11 20:10:02 +0100339 },
340}