1// This Blueprint file loosely follows the logic of cpu_features'
2// CMakeLists.txt and test/CMakeLists.txt files.
3
4package {
5    default_applicable_licenses: ["external_cpu_features_license"],
6}
7
8// Added automatically by a large-scale-change that took the approach of
9// 'apply every license found to every target'. While this makes sure we respect
10// every license restriction, it may not be entirely correct.
11//
12// e.g. GPL in an MIT project might only apply to the contrib/ directory.
13//
14// Please consider splitting the single license below into multiple licenses,
15// taking care not to lose any license_kind information, and overriding the
16// default license using the 'licenses: [...]' property on targets as needed.
17//
18// For unused files, consider creating a 'fileGroup' with "//visibility:private"
19// to attach the license to, and including a comment whether the files may be
20// used in the current project.
21// See: http://go/android-license-faq
22license {
23    name: "external_cpu_features_license",
24    visibility: [":__subpackages__"],
25    license_kinds: [
26        "SPDX-license-identifier-Apache-2.0",
27        "SPDX-license-identifier-BSD",
28    ],
29    license_text: [
30        "LICENSE",
31    ],
32}
33
34cc_defaults {
35    name: "cpu_features-defaults",
36    host_supported: true,
37    local_include_dirs: [
38        "include",
39    ],
40    cflags: [
41        // Reserve 1024 bytes on the stack when reading from `/proc/cpuinfo`.
42        "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
43        "-Wno-gnu-designator",
44    ],
45    min_sdk_version: "S",
46}
47
48cc_library {
49    name: "libcpu_features-utils",
50    defaults: ["cpu_features-defaults"],
51    srcs: [
52        "src/filesystem.c",
53        "src/stack_line_reader.c",
54        "src/string_view.c",
55    ],
56    target: {
57        windows: {
58            enabled: true,
59        },
60    },
61    apex_available: [
62        "com.android.art",
63        "com.android.art.debug",
64    ],
65}
66
67cc_library {
68    name: "libcpu_features-hwcaps",
69    defaults: ["cpu_features-defaults"],
70    srcs: [
71        "src/hwcaps.c",
72    ],
73    cflags: [
74        "-DHAVE_DLFCN_H",
75    ],
76    target: {
77        bionic: {
78            cflags: [
79                "-DHAVE_STRONG_GETAUXVAL",
80            ],
81        },
82    },
83    static_libs: [
84        "libcpu_features-utils",
85    ],
86    apex_available: [
87        "com.android.art",
88        "com.android.art.debug",
89    ],
90}
91
92cc_library {
93    name: "libcpu_features",
94    defaults: [
95        "cpu_features-defaults",
96    ],
97    export_include_dirs: ["include"],
98    whole_static_libs: [
99        "libcpu_features-utils",
100    ],
101    arch: {
102        arm: {
103            srcs: [
104                "src/cpuinfo_arm.c",
105            ],
106            whole_static_libs: [
107                "libcpu_features-hwcaps",
108            ],
109        },
110        arm64: {
111            srcs: [
112                "src/cpuinfo_aarch64.c",
113            ],
114            whole_static_libs: [
115                "libcpu_features-hwcaps",
116            ],
117            cflags: [
118                "-Wno-gnu-designator",
119            ],
120        },
121        x86: {
122            srcs: [
123                "src/cpuinfo_x86.c",
124            ],
125            cflags: [
126                "-Wno-unused-variable",
127            ],
128        },
129        x86_64: {
130            srcs: [
131                "src/cpuinfo_x86.c",
132            ],
133            cflags: [
134                "-Wno-unused-variable",
135            ],
136        },
137    },
138    target: {
139        windows: {
140            enabled: true,
141        },
142    },
143    apex_available: [
144        "com.android.art",
145        "com.android.art.debug",
146    ],
147}
148
149cc_binary {
150    name: "list_cpu_features",
151    defaults: [
152        "cpu_features-defaults",
153    ],
154    srcs: [
155        "src/utils/list_cpu_features.c",
156    ],
157    static_libs: [
158        "libcpu_features",
159    ],
160    arch: {
161        // Function `AddCacheInfo` in `src/utils/list_cpu_features.c` is only used on x86/x86_64 and
162        // triggers an error with `-Werror and `-Wunused-function` on other architectures; disable
163        // the latter flag to avoid compilation errors on those architectures.
164        arm: {
165            cflags: [
166                "-Wno-unused-function",
167            ],
168        },
169        arm64: {
170            cflags: [
171                "-Wno-unused-function",
172            ],
173        },
174    },
175}
176
177// Tests.
178
179cc_defaults {
180    name: "cpu_features-test-defaults",
181    test_suites: ["device-tests"],
182    host_supported: true,
183    compile_multilib: "both",
184    local_include_dirs: [
185        "include",
186    ],
187    cflags: [
188        "-DCPU_FEATURES_TEST",
189    ],
190}
191
192cc_test_library {
193    name: "libcpu_features-string_view",
194    defaults: ["cpu_features-test-defaults"],
195    srcs: [
196        "src/string_view.c",
197    ],
198}
199
200cc_test_library {
201    name: "libcpu_features-filesystem_for_testing",
202    defaults: ["cpu_features-test-defaults"],
203    cflags: [
204        "-DCPU_FEATURES_MOCK_FILESYSTEM",
205        // TODO: Handle unused parameters in
206        // test/filesystem_for_testing.cc and remove this flag.
207        "-Wno-unused-parameter",
208    ],
209    srcs: [
210        "test/filesystem_for_testing.cc",
211    ],
212}
213
214cc_test_library {
215    name: "libcpu_features-hwcaps_for_testing",
216    defaults: ["cpu_features-test-defaults"],
217    cflags: [
218        "-DCPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL",
219        "-DCPU_FEATURES_TEST",
220    ],
221    srcs: [
222        "src/hwcaps.c",
223        "test/hwcaps_for_testing.cc",
224    ],
225    static_libs: [
226        "libcpu_features-string_view",
227        "libcpu_features-filesystem_for_testing",
228    ],
229}
230
231cc_defaults {
232    name: "stack_line_reader-defaults",
233    cflags: [
234        "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
235    ],
236}
237
238cc_test_library {
239    name: "libcpu_features-stack_line_reader",
240    defaults: [
241        "cpu_features-test-defaults",
242        "stack_line_reader-defaults",
243    ],
244    srcs: [
245        "src/stack_line_reader.c",
246    ],
247    static_libs: [
248        "libcpu_features-filesystem_for_testing",
249        "libcpu_features-string_view",
250    ],
251}
252
253cc_test_library {
254    name: "libcpu_features-stack_line_reader_for_test",
255    defaults: ["cpu_features-test-defaults"],
256    cflags: [
257        "-DSTACK_LINE_READER_BUFFER_SIZE=16",
258    ],
259    srcs: [
260        "src/stack_line_reader.c",
261    ],
262    whole_static_libs: [
263        "libcpu_features-filesystem_for_testing",
264        "libcpu_features-string_view",
265    ],
266}
267
268cc_test_library {
269    name: "libcpu_features-all_libraries",
270    defaults: [
271        "cpu_features-test-defaults",
272        "stack_line_reader-defaults",
273    ],
274    whole_static_libs: [
275        "libcpu_features-filesystem_for_testing",
276        "libcpu_features-hwcaps_for_testing",
277        "libcpu_features-stack_line_reader",
278        "libcpu_features-string_view",
279    ],
280}
281
282cc_test {
283    name: "cpu_features-bit_utils_test",
284    defaults: ["cpu_features-test-defaults"],
285    srcs: [
286        "test/bit_utils_test.cc",
287    ],
288}
289
290cc_test {
291    name: "cpu_features-string_view_test",
292    defaults: ["cpu_features-test-defaults"],
293    srcs: [
294        "test/string_view_test.cc",
295        "src/string_view.c",
296    ],
297    static_libs: [
298        "libcpu_features-string_view",
299    ],
300}
301
302cc_test {
303    name: "cpu_features-stack_line_reader_test",
304    defaults: [
305        "cpu_features-test-defaults",
306        "stack_line_reader-defaults",
307    ],
308    cflags: [
309        // TODO: Handle unused funtions in
310        // test/stack_line_reader_test.cc and remove this flag.
311        "-Wno-unused-function",
312    ],
313    srcs: [
314        "test/stack_line_reader_test.cc",
315    ],
316    static_libs: [
317        "libcpu_features-stack_line_reader_for_test",
318    ],
319}
320
321cc_test {
322    name: "cpu_features-cpuinfo_test",
323    defaults: [
324        "cpu_features-test-defaults",
325    ],
326    static_libs: [
327        "libcpu_features-all_libraries",
328    ],
329    cflags: [
330        "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
331    ],
332    arch: {
333        x86: {
334            cflags: [
335                "-DCPU_FEATURES_MOCK_CPUID_X86",
336                "-Wno-unused-variable",
337            ],
338            srcs: [
339                "test/cpuinfo_x86_test.cc",
340                "src/cpuinfo_x86.c",
341            ],
342        },
343        x86_64: {
344            cflags: [
345                "-DCPU_FEATURES_MOCK_CPUID_X86",
346                "-Wno-unused-variable",
347            ],
348            srcs: [
349                "test/cpuinfo_x86_test.cc",
350                "src/cpuinfo_x86.c",
351            ],
352        },
353        arm: {
354            srcs: [
355                "test/cpuinfo_arm_test.cc",
356                "src/cpuinfo_arm.c",
357            ],
358        },
359        arm64: {
360            cflags: [
361                "-Wno-gnu-designator",
362            ],
363            srcs: [
364                "test/cpuinfo_aarch64_test.cc",
365                "src/cpuinfo_aarch64.c",
366            ],
367        },
368    },
369}
370