Roland Levillain | d56de91 | 2019-06-20 20:55:26 +0100 | [diff] [blame] | 1 | // This Blueprint file loosely follows the logic of cpu_features' |
Roland Levillain | 18318b6 | 2019-06-21 19:56:28 +0100 | [diff] [blame] | 2 | // CMakeLists.txt and test/CMakeLists.txt files. |
Roland Levillain | d56de91 | 2019-06-20 20:55:26 +0100 | [diff] [blame] | 3 | |
| 4 | cc_defaults { |
| 5 | name: "cpu_features-defaults", |
| 6 | host_supported: true, |
| 7 | local_include_dirs: [ |
| 8 | "include", |
Roland Levillain | d56de91 | 2019-06-20 20:55:26 +0100 | [diff] [blame] | 9 | ], |
| 10 | cflags: [ |
| 11 | // Reserve 1024 bytes on the stack when reading from `/proc/cpuinfo`. |
| 12 | "-DSTACK_LINE_READER_BUFFER_SIZE=1024", |
Haibo Huang | 2519d75 | 2019-07-12 18:21:31 -0700 | [diff] [blame] | 13 | "-Wno-gnu-designator", |
Roland Levillain | d56de91 | 2019-06-20 20:55:26 +0100 | [diff] [blame] | 14 | ], |
| 15 | } |
| 16 | |
| 17 | cc_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 Hughes | e39557c | 2019-08-05 12:23:07 -0700 | [diff] [blame] | 25 | target: { |
| 26 | windows: { |
| 27 | enabled: true, |
| 28 | }, |
| 29 | }, |
Roland Levillain | d56de91 | 2019-06-20 20:55:26 +0100 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | cc_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 | |
| 54 | cc_library { |
| 55 | name: "libcpu_features", |
| 56 | defaults: [ |
| 57 | "cpu_features-defaults", |
| 58 | ], |
Elliott Hughes | 7f8ace6 | 2019-08-05 11:58:18 -0700 | [diff] [blame] | 59 | export_include_dirs: ["include"], |
Roland Levillain | d56de91 | 2019-06-20 20:55:26 +0100 | [diff] [blame] | 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 | ], |
Haibo Huang | 2519d75 | 2019-07-12 18:21:31 -0700 | [diff] [blame] | 79 | cflags: [ |
| 80 | "-Wno-gnu-designator", |
| 81 | ], |
Roland Levillain | d56de91 | 2019-06-20 20:55:26 +0100 | [diff] [blame] | 82 | }, |
| 83 | x86: { |
| 84 | srcs: [ |
| 85 | "src/cpuinfo_x86.c", |
| 86 | ], |
Haibo Huang | 2519d75 | 2019-07-12 18:21:31 -0700 | [diff] [blame] | 87 | cflags: [ |
| 88 | "-Wno-unused-variable", |
| 89 | ], |
Roland Levillain | d56de91 | 2019-06-20 20:55:26 +0100 | [diff] [blame] | 90 | }, |
| 91 | x86_64: { |
| 92 | srcs: [ |
| 93 | "src/cpuinfo_x86.c", |
| 94 | ], |
Haibo Huang | 2519d75 | 2019-07-12 18:21:31 -0700 | [diff] [blame] | 95 | cflags: [ |
| 96 | "-Wno-unused-variable", |
| 97 | ], |
Roland Levillain | d56de91 | 2019-06-20 20:55:26 +0100 | [diff] [blame] | 98 | }, |
| 99 | }, |
Elliott Hughes | e39557c | 2019-08-05 12:23:07 -0700 | [diff] [blame] | 100 | target: { |
| 101 | windows: { |
| 102 | enabled: true, |
| 103 | }, |
| 104 | }, |
Roland Levillain | d56de91 | 2019-06-20 20:55:26 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | cc_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 Levillain | 61cf9ac | 2020-09-22 10:52:15 +0100 | [diff] [blame^] | 118 | 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 Levillain | d56de91 | 2019-06-20 20:55:26 +0100 | [diff] [blame] | 133 | } |
Roland Levillain | 18318b6 | 2019-06-21 19:56:28 +0100 | [diff] [blame] | 134 | |
Roland Levillain | 18318b6 | 2019-06-21 19:56:28 +0100 | [diff] [blame] | 135 | // Tests. |
| 136 | |
| 137 | cc_defaults { |
| 138 | name: "cpu_features-test-defaults", |
Roland Levillain | df048ae | 2019-07-23 18:02:33 +0100 | [diff] [blame] | 139 | test_suites: ["device-tests"], |
Roland Levillain | 18318b6 | 2019-06-21 19:56:28 +0100 | [diff] [blame] | 140 | host_supported: true, |
Roland Levillain | 9ae23c4 | 2019-07-24 19:25:53 +0100 | [diff] [blame] | 141 | compile_multilib: "both", |
Roland Levillain | 18318b6 | 2019-06-21 19:56:28 +0100 | [diff] [blame] | 142 | local_include_dirs: [ |
| 143 | "include", |
| 144 | ], |
| 145 | cflags: [ |
Roland Levillain | aa4fc41 | 2019-07-24 19:51:11 +0100 | [diff] [blame] | 146 | "-DCPU_FEATURES_TEST", |
Roland Levillain | 18318b6 | 2019-06-21 19:56:28 +0100 | [diff] [blame] | 147 | ], |
| 148 | } |
| 149 | |
| 150 | cc_test_library { |
| 151 | name: "libcpu_features-string_view", |
| 152 | defaults: ["cpu_features-test-defaults"], |
| 153 | srcs: [ |
| 154 | "src/string_view.c", |
| 155 | ], |
| 156 | } |
| 157 | |
| 158 | cc_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 | |
| 172 | cc_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 | |
| 187 | cc_defaults { |
| 188 | name: "stack_line_reader-defaults", |
| 189 | cflags: [ |
| 190 | "-DSTACK_LINE_READER_BUFFER_SIZE=1024", |
| 191 | ], |
| 192 | } |
| 193 | |
| 194 | cc_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 | |
| 209 | cc_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 | |
| 224 | cc_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 | |
| 241 | cc_test { |
| 242 | name: "cpu_features-bit_utils_test", |
| 243 | defaults: ["cpu_features-test-defaults"], |
| 244 | srcs: [ |
Roland Levillain | aa4fc41 | 2019-07-24 19:51:11 +0100 | [diff] [blame] | 245 | "test/bit_utils_test.cc", |
Roland Levillain | 18318b6 | 2019-06-21 19:56:28 +0100 | [diff] [blame] | 246 | ], |
| 247 | } |
| 248 | |
| 249 | cc_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 | |
| 261 | cc_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 | |
| 280 | cc_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 Levillain | 9f7c24e | 2019-07-11 20:10:02 +0100 | [diff] [blame] | 291 | cc_test { |
| 292 | name: "cpu_features-cpuinfo_test", |
| 293 | defaults: [ |
Roland Levillain | d4628f1 | 2019-07-24 19:40:34 +0100 | [diff] [blame] | 294 | "cpu_features-test-defaults", |
| 295 | ], |
| 296 | static_libs: [ |
| 297 | "libcpu_features-all_libraries", |
Roland Levillain | 9f7c24e | 2019-07-11 20:10:02 +0100 | [diff] [blame] | 298 | ], |
| 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 Levillain | aa4fc41 | 2019-07-24 19:51:11 +0100 | [diff] [blame] | 338 | }, |
Roland Levillain | 9f7c24e | 2019-07-11 20:10:02 +0100 | [diff] [blame] | 339 | }, |
| 340 | } |