1// This Blueprint file loosely follows the logic of cpu_features' 2// CMakeLists.txt and test/CMakeLists.txt files. 3 4cc_defaults { 5 name: "cpu_features-defaults", 6 host_supported: true, 7 local_include_dirs: [ 8 "include", 9 ], 10 cflags: [ 11 // Reserve 1024 bytes on the stack when reading from `/proc/cpuinfo`. 12 "-DSTACK_LINE_READER_BUFFER_SIZE=1024", 13 "-Wno-gnu-designator", 14 ], 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 ], 25 target: { 26 windows: { 27 enabled: true, 28 }, 29 }, 30} 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 ], 59 export_include_dirs: ["include"], 60 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 ], 79 cflags: [ 80 "-Wno-gnu-designator", 81 ], 82 }, 83 x86: { 84 srcs: [ 85 "src/cpuinfo_x86.c", 86 ], 87 cflags: [ 88 "-Wno-unused-variable", 89 ], 90 }, 91 x86_64: { 92 srcs: [ 93 "src/cpuinfo_x86.c", 94 ], 95 cflags: [ 96 "-Wno-unused-variable", 97 ], 98 }, 99 }, 100 target: { 101 windows: { 102 enabled: true, 103 }, 104 }, 105} 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 ], 118} 119 120// Tests. 121 122cc_defaults { 123 name: "cpu_features-test-defaults", 124 test_suites: ["device-tests"], 125 host_supported: true, 126 compile_multilib: "both", 127 local_include_dirs: [ 128 "include", 129 ], 130 cflags: [ 131 "-DCPU_FEATURES_TEST", 132 ], 133} 134 135cc_test_library { 136 name: "libcpu_features-string_view", 137 defaults: ["cpu_features-test-defaults"], 138 srcs: [ 139 "src/string_view.c", 140 ], 141} 142 143cc_test_library { 144 name: "libcpu_features-filesystem_for_testing", 145 defaults: ["cpu_features-test-defaults"], 146 cflags: [ 147 "-DCPU_FEATURES_MOCK_FILESYSTEM", 148 // TODO: Handle unused parameters in 149 // test/filesystem_for_testing.cc and remove this flag. 150 "-Wno-unused-parameter", 151 ], 152 srcs: [ 153 "test/filesystem_for_testing.cc", 154 ], 155} 156 157cc_test_library { 158 name: "libcpu_features-hwcaps_for_testing", 159 defaults: ["cpu_features-test-defaults"], 160 cflags: [ 161 "-DCPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL", 162 ], 163 srcs: [ 164 "test/hwcaps_for_testing.cc", 165 ], 166 static_libs: [ 167 "libcpu_features-string_view", 168 "libcpu_features-filesystem_for_testing", 169 ], 170} 171 172cc_defaults { 173 name: "stack_line_reader-defaults", 174 cflags: [ 175 "-DSTACK_LINE_READER_BUFFER_SIZE=1024", 176 ], 177} 178 179cc_test_library { 180 name: "libcpu_features-stack_line_reader", 181 defaults: [ 182 "cpu_features-test-defaults", 183 "stack_line_reader-defaults", 184 ], 185 srcs: [ 186 "src/stack_line_reader.c", 187 ], 188 static_libs: [ 189 "libcpu_features-filesystem_for_testing", 190 "libcpu_features-string_view", 191 ], 192} 193 194cc_test_library { 195 name: "libcpu_features-stack_line_reader_for_test", 196 defaults: ["cpu_features-test-defaults"], 197 cflags: [ 198 "-DSTACK_LINE_READER_BUFFER_SIZE=16", 199 ], 200 srcs: [ 201 "src/stack_line_reader.c", 202 ], 203 whole_static_libs: [ 204 "libcpu_features-filesystem_for_testing", 205 "libcpu_features-string_view", 206 ], 207} 208 209cc_test_library { 210 name: "libcpu_features-all_libraries", 211 defaults: [ 212 "cpu_features-test-defaults", 213 "stack_line_reader-defaults", 214 ], 215 srcs: [ 216 "src/unix_features_aggregator.c", 217 ], 218 whole_static_libs: [ 219 "libcpu_features-filesystem_for_testing", 220 "libcpu_features-hwcaps_for_testing", 221 "libcpu_features-stack_line_reader", 222 "libcpu_features-string_view", 223 ], 224} 225 226cc_test { 227 name: "cpu_features-bit_utils_test", 228 defaults: ["cpu_features-test-defaults"], 229 srcs: [ 230 "test/bit_utils_test.cc", 231 ], 232} 233 234cc_test { 235 name: "cpu_features-string_view_test", 236 defaults: ["cpu_features-test-defaults"], 237 srcs: [ 238 "test/string_view_test.cc", 239 "src/string_view.c", 240 ], 241 static_libs: [ 242 "libcpu_features-string_view", 243 ], 244} 245 246cc_test { 247 name: "cpu_features-stack_line_reader_test", 248 defaults: [ 249 "cpu_features-test-defaults", 250 "stack_line_reader-defaults", 251 ], 252 cflags: [ 253 // TODO: Handle unused funtions in 254 // test/stack_line_reader_test.cc and remove this flag. 255 "-Wno-unused-function", 256 ], 257 srcs: [ 258 "test/stack_line_reader_test.cc", 259 ], 260 static_libs: [ 261 "libcpu_features-stack_line_reader_for_test", 262 ], 263} 264 265cc_test { 266 name: "cpu_features-unix_features_aggregator_test", 267 defaults: ["cpu_features-test-defaults"], 268 srcs: [ 269 "test/unix_features_aggregator_test.cc", 270 ], 271 static_libs: [ 272 "libcpu_features-all_libraries", 273 ], 274} 275 276cc_test { 277 name: "cpu_features-cpuinfo_test", 278 defaults: [ 279 "cpu_features-test-defaults", 280 ], 281 static_libs: [ 282 "libcpu_features-all_libraries", 283 ], 284 arch: { 285 x86: { 286 cflags: [ 287 "-DCPU_FEATURES_MOCK_CPUID_X86", 288 "-Wno-unused-variable", 289 ], 290 srcs: [ 291 "test/cpuinfo_x86_test.cc", 292 "src/cpuinfo_x86.c", 293 ], 294 }, 295 x86_64: { 296 cflags: [ 297 "-DCPU_FEATURES_MOCK_CPUID_X86", 298 "-Wno-unused-variable", 299 ], 300 srcs: [ 301 "test/cpuinfo_x86_test.cc", 302 "src/cpuinfo_x86.c", 303 ], 304 }, 305 arm: { 306 cflags: [ 307 "-DSTACK_LINE_READER_BUFFER_SIZE=1024", 308 ], 309 srcs: [ 310 "test/cpuinfo_arm_test.cc", 311 "src/cpuinfo_arm.c", 312 ], 313 }, 314 arm64: { 315 cflags: [ 316 "-DSTACK_LINE_READER_BUFFER_SIZE=1024", 317 "-Wno-gnu-designator", 318 ], 319 srcs: [ 320 "test/cpuinfo_aarch64_test.cc", 321 "src/cpuinfo_aarch64.c", 322 ], 323 }, 324 }, 325} 326