• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/impl_arm_linux_or_android.c",
105            ],
106            whole_static_libs: [
107                "libcpu_features-hwcaps",
108            ],
109        },
110        arm64: {
111            srcs: [
112                "src/impl_aarch64_linux_or_android.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/impl_x86_linux_or_android.c",
124            ],
125            cflags: [
126                "-Wno-unused-variable",
127            ],
128        },
129        x86_64: {
130            srcs: [
131                "src/impl_x86_linux_or_android.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        x86: {
175            cflags: [
176                "-Wno-deprecated-declarations",
177            ],
178        },
179        x86_64: {
180            cflags: [
181                "-Wno-deprecated-declarations",
182            ],
183        },
184    },
185}
186
187// Tests.
188
189cc_defaults {
190    name: "cpu_features-test-defaults",
191    test_suites: ["device-tests"],
192    host_supported: true,
193    compile_multilib: "both",
194    local_include_dirs: [
195        "include",
196    ],
197    cflags: [
198        "-DCPU_FEATURES_TEST",
199    ],
200}
201
202cc_test_library {
203    name: "libcpu_features-string_view",
204    defaults: ["cpu_features-test-defaults"],
205    srcs: [
206        "src/string_view.c",
207    ],
208}
209
210cc_test_library {
211    name: "libcpu_features-filesystem_for_testing",
212    defaults: ["cpu_features-test-defaults"],
213    cflags: [
214        "-DCPU_FEATURES_MOCK_FILESYSTEM",
215        // TODO: Handle unused parameters in
216        // test/filesystem_for_testing.cc and remove this flag.
217        "-Wno-unused-parameter",
218    ],
219    srcs: [
220        "test/filesystem_for_testing.cc",
221    ],
222}
223
224cc_test_library {
225    name: "libcpu_features-hwcaps_for_testing",
226    defaults: ["cpu_features-test-defaults"],
227    cflags: [
228        "-DCPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL",
229        "-DCPU_FEATURES_TEST",
230    ],
231    srcs: [
232        "src/hwcaps.c",
233        "test/hwcaps_for_testing.cc",
234    ],
235    static_libs: [
236        "libcpu_features-string_view",
237        "libcpu_features-filesystem_for_testing",
238    ],
239}
240
241cc_defaults {
242    name: "stack_line_reader-defaults",
243    cflags: [
244        "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
245    ],
246}
247
248cc_test_library {
249    name: "libcpu_features-stack_line_reader",
250    defaults: [
251        "cpu_features-test-defaults",
252        "stack_line_reader-defaults",
253    ],
254    srcs: [
255        "src/stack_line_reader.c",
256    ],
257    static_libs: [
258        "libcpu_features-filesystem_for_testing",
259        "libcpu_features-string_view",
260    ],
261}
262
263cc_test_library {
264    name: "libcpu_features-stack_line_reader_for_test",
265    defaults: ["cpu_features-test-defaults"],
266    cflags: [
267        "-DSTACK_LINE_READER_BUFFER_SIZE=16",
268    ],
269    srcs: [
270        "src/stack_line_reader.c",
271    ],
272    whole_static_libs: [
273        "libcpu_features-filesystem_for_testing",
274        "libcpu_features-string_view",
275    ],
276}
277
278cc_test_library {
279    name: "libcpu_features-all_libraries",
280    defaults: [
281        "cpu_features-test-defaults",
282        "stack_line_reader-defaults",
283    ],
284    whole_static_libs: [
285        "libcpu_features-filesystem_for_testing",
286        "libcpu_features-hwcaps_for_testing",
287        "libcpu_features-stack_line_reader",
288        "libcpu_features-string_view",
289    ],
290}
291
292cc_test {
293    name: "cpu_features-bit_utils_test",
294    defaults: ["cpu_features-test-defaults"],
295    srcs: [
296        "test/bit_utils_test.cc",
297    ],
298}
299
300cc_test {
301    name: "cpu_features-string_view_test",
302    defaults: ["cpu_features-test-defaults"],
303    srcs: [
304        "test/string_view_test.cc",
305        "src/string_view.c",
306    ],
307    static_libs: [
308        "libcpu_features-string_view",
309    ],
310}
311
312cc_test {
313    name: "cpu_features-stack_line_reader_test",
314    defaults: [
315        "cpu_features-test-defaults",
316        "stack_line_reader-defaults",
317    ],
318    cflags: [
319        // TODO: Handle unused funtions in
320        // test/stack_line_reader_test.cc and remove this flag.
321        "-Wno-unused-function",
322    ],
323    srcs: [
324        "test/stack_line_reader_test.cc",
325    ],
326    static_libs: [
327        "libcpu_features-stack_line_reader_for_test",
328    ],
329}
330
331cc_test {
332    name: "cpu_features-cpuinfo_test",
333    defaults: [
334        "cpu_features-test-defaults",
335    ],
336    static_libs: [
337        "libcpu_features-all_libraries",
338    ],
339    cflags: [
340        "-DSTACK_LINE_READER_BUFFER_SIZE=1024",
341    ],
342    arch: {
343        x86: {
344            cflags: [
345                "-DCPU_FEATURES_MOCK_CPUID_X86",
346                "-Wno-unused-variable",
347                "-Wno-deprecated-declarations",
348            ],
349            srcs: [
350                "test/cpuinfo_x86_test.cc",
351                "src/impl_x86_linux_or_android.c",
352            ],
353        },
354        x86_64: {
355            cflags: [
356                "-DCPU_FEATURES_MOCK_CPUID_X86",
357                "-Wno-unused-variable",
358                "-Wno-deprecated-declarations",
359            ],
360            srcs: [
361                "test/cpuinfo_x86_test.cc",
362                "src/impl_x86_linux_or_android.c",
363            ],
364        },
365        arm: {
366            srcs: [
367                "test/cpuinfo_arm_test.cc",
368                "src/impl_arm_linux_or_android.c",
369            ],
370        },
371        arm64: {
372            cflags: [
373                "-Wno-gnu-designator",
374            ],
375            srcs: [
376                "test/cpuinfo_aarch64_test.cc",
377                "src/impl_aarch64_linux_or_android.c",
378            ],
379        },
380    },
381}
382