1# Copyright (c) 2013 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/config/compiler/compiler.gni") 6 7if (current_cpu == "arm" || current_cpu == "arm64") { 8 import("//build/config/arm.gni") 9} 10 11config("zlib_config") { 12 include_dirs = [ "." ] 13} 14 15config("zlib_internal_config") { 16 defines = [ "ZLIB_IMPLEMENTATION" ] 17} 18 19use_arm_neon_optimizations = false 20if (current_cpu == "arm" || current_cpu == "arm64") { 21 if (arm_use_neon) { 22 use_arm_neon_optimizations = true 23 } 24} 25 26use_x86_x64_optimizations = 27 (current_cpu == "x86" || current_cpu == "x64") && !is_ios 28 29config("zlib_adler32_simd_config") { 30 if (use_x86_x64_optimizations) { 31 defines = [ "ADLER32_SIMD_SSSE3" ] 32 } 33 34 if (use_arm_neon_optimizations) { 35 defines = [ "ADLER32_SIMD_NEON" ] 36 } 37} 38 39source_set("zlib_adler32_simd") { 40 visibility = [ ":*" ] 41 42 if (use_x86_x64_optimizations) { 43 sources = [ 44 "adler32_simd.c", 45 "adler32_simd.h", 46 ] 47 48 if (!is_win || is_clang) { 49 cflags = [ "-mssse3" ] 50 } 51 } 52 53 if (use_arm_neon_optimizations) { 54 sources = [ 55 "adler32_simd.c", 56 "adler32_simd.h", 57 ] 58 if (!is_debug) { 59 # Use optimize_speed (-O3) to output the _smallest_ code. 60 configs -= [ "//build/config/compiler:default_optimization" ] 61 configs += [ "//build/config/compiler:optimize_speed" ] 62 } 63 } 64 65 configs += [ ":zlib_internal_config" ] 66 67 public_configs = [ ":zlib_adler32_simd_config" ] 68} 69 70if (use_arm_neon_optimizations) { 71 config("zlib_arm_crc32_config") { 72 # Disabled for iPhone, as described in DDI0487C_a_armv8_arm: 73 # "All implementations of the ARMv8.1 architecture are required to 74 # implement the CRC32* instructions. These are optional in ARMv8.0." 75 if (!is_ios) { 76 defines = [ "CRC32_ARMV8_CRC32" ] 77 if (is_android) { 78 defines += [ "ARMV8_OS_ANDROID" ] 79 } else if (is_linux || is_chromeos) { 80 defines += [ "ARMV8_OS_LINUX" ] 81 } else if (is_fuchsia) { 82 defines += [ "ARMV8_OS_FUCHSIA" ] 83 } else if (is_win) { 84 defines += [ "ARMV8_OS_WINDOWS" ] 85 } else { 86 assert(false, "Unsupported ARM OS") 87 } 88 } 89 } 90 91 source_set("zlib_arm_crc32") { 92 visibility = [ ":*" ] 93 94 if (!is_ios) { 95 include_dirs = [ "." ] 96 97 if (is_android) { 98 import("//build/config/android/config.gni") 99 if (defined(android_ndk_root) && android_ndk_root != "") { 100 deps = [ 101 "//third_party/android_ndk:cpu_features", 102 ] 103 } else { 104 assert(false, "CPU detection requires the Android NDK") 105 } 106 } else if (!is_win && !is_clang) { 107 assert(!use_thin_lto, 108 "ThinLTO fails mixing different module-level targets") 109 cflags_c = [ "-march=armv8-a+crc" ] 110 } 111 112 sources = [ 113 "arm_features.c", 114 "arm_features.h", 115 "crc32_simd.c", 116 "crc32_simd.h", 117 ] 118 119 if (!is_debug) { 120 configs -= [ "//build/config/compiler:default_optimization" ] 121 configs += [ "//build/config/compiler:optimize_speed" ] 122 } 123 } 124 125 configs += [ ":zlib_internal_config" ] 126 127 public_configs = [ ":zlib_arm_crc32_config" ] 128 } 129} 130 131config("zlib_inflate_chunk_simd_config") { 132 if (use_x86_x64_optimizations) { 133 defines = [ "INFLATE_CHUNK_SIMD_SSE2" ] 134 135 if (current_cpu == "x64") { 136 defines += [ "INFLATE_CHUNK_READ_64LE" ] 137 } 138 } 139 140 if (use_arm_neon_optimizations) { 141 defines = [ "INFLATE_CHUNK_SIMD_NEON" ] 142 if (current_cpu == "arm64") { 143 defines += [ "INFLATE_CHUNK_READ_64LE" ] 144 } 145 } 146} 147 148source_set("zlib_inflate_chunk_simd") { 149 visibility = [ ":*" ] 150 151 if (use_x86_x64_optimizations || use_arm_neon_optimizations) { 152 include_dirs = [ "." ] 153 154 sources = [ 155 "contrib/optimizations/chunkcopy.h", 156 "contrib/optimizations/inffast_chunk.c", 157 "contrib/optimizations/inffast_chunk.h", 158 "contrib/optimizations/inflate.c", 159 ] 160 161 if (use_arm_neon_optimizations && !is_debug) { 162 # Here we trade better performance on newer/bigger ARMv8 cores 163 # for less perf on ARMv7, per crbug.com/772870#c40 164 configs -= [ "//build/config/compiler:default_optimization" ] 165 configs += [ "//build/config/compiler:optimize_speed" ] 166 } 167 } 168 169 configs -= [ "//build/config/compiler:chromium_code" ] 170 configs += [ 171 ":zlib_internal_config", 172 "//build/config/compiler:no_chromium_code", 173 ] 174 175 public_configs = [ ":zlib_inflate_chunk_simd_config" ] 176} 177 178config("zlib_crc32_simd_config") { 179 if (use_x86_x64_optimizations) { 180 defines = [ "CRC32_SIMD_SSE42_PCLMUL" ] 181 } 182} 183 184source_set("zlib_crc32_simd") { 185 visibility = [ ":*" ] 186 187 if (use_x86_x64_optimizations) { 188 sources = [ 189 "crc32_simd.c", 190 "crc32_simd.h", 191 ] 192 193 if (!is_win || is_clang) { 194 cflags = [ 195 "-msse4.2", 196 "-mpclmul", 197 ] 198 } 199 } 200 201 configs += [ ":zlib_internal_config" ] 202 203 public_configs = [ ":zlib_crc32_simd_config" ] 204} 205 206source_set("zlib_x86_simd") { 207 visibility = [ ":*" ] 208 209 if (use_x86_x64_optimizations) { 210 sources = [ 211 "crc_folding.c", 212 "fill_window_sse.c", 213 ] 214 215 if (!is_win || is_clang) { 216 cflags = [ 217 "-msse4.2", 218 "-mpclmul", 219 ] 220 } 221 } else { 222 sources = [ 223 "simd_stub.c", 224 ] 225 } 226 227 configs -= [ "//build/config/compiler:chromium_code" ] 228 configs += [ 229 ":zlib_internal_config", 230 "//build/config/compiler:no_chromium_code", 231 ] 232} 233 234config("zlib_warnings") { 235 if (is_clang && use_x86_x64_optimizations) { 236 cflags = [ "-Wno-incompatible-pointer-types" ] 237 } 238} 239 240component("zlib") { 241 if (!is_win) { 242 # Don't stomp on "libzlib" on other platforms. 243 output_name = "chrome_zlib" 244 } 245 246 sources = [ 247 "adler32.c", 248 "chromeconf.h", 249 "compress.c", 250 "contrib/optimizations/insert_string.h", 251 "crc32.c", 252 "crc32.h", 253 "deflate.c", 254 "deflate.h", 255 "gzclose.c", 256 "gzguts.h", 257 "gzlib.c", 258 "gzread.c", 259 "gzwrite.c", 260 "infback.c", 261 "inffast.c", 262 "inffast.h", 263 "inffixed.h", 264 "inflate.h", 265 "inftrees.c", 266 "inftrees.h", 267 "trees.c", 268 "trees.h", 269 "uncompr.c", 270 "x86.h", 271 "zconf.h", 272 "zlib.h", 273 "zutil.c", 274 "zutil.h", 275 ] 276 277 defines = [] 278 deps = [] 279 280 if (use_x86_x64_optimizations || use_arm_neon_optimizations) { 281 deps += [ 282 ":zlib_adler32_simd", 283 ":zlib_inflate_chunk_simd", 284 ] 285 286 if (use_x86_x64_optimizations) { 287 sources += [ "x86.c" ] 288 deps += [ ":zlib_crc32_simd" ] 289 } else if (use_arm_neon_optimizations) { 290 sources += [ "contrib/optimizations/slide_hash_neon.h" ] 291 deps += [ ":zlib_arm_crc32" ] 292 } 293 } else { 294 sources += [ "inflate.c" ] 295 } 296 297 configs -= [ "//build/config/compiler:chromium_code" ] 298 configs += [ 299 ":zlib_internal_config", 300 "//build/config/compiler:no_chromium_code", 301 302 # Must be after no_chromium_code for warning flags to be ordered correctly. 303 ":zlib_warnings", 304 ] 305 306 public_configs = [ ":zlib_config" ] 307 308 deps += [ ":zlib_x86_simd" ] 309 allow_circular_includes_from = deps 310} 311 312config("minizip_warnings") { 313 visibility = [ ":*" ] 314 315 if (is_clang) { 316 # zlib uses `if ((a == b))` for some reason. 317 cflags = [ "-Wno-parentheses-equality" ] 318 } 319} 320 321static_library("minizip") { 322 sources = [ 323 "contrib/minizip/ioapi.c", 324 "contrib/minizip/ioapi.h", 325 "contrib/minizip/iowin32.c", 326 "contrib/minizip/iowin32.h", 327 "contrib/minizip/unzip.c", 328 "contrib/minizip/unzip.h", 329 "contrib/minizip/zip.c", 330 "contrib/minizip/zip.h", 331 ] 332 333 if (!is_win) { 334 sources -= [ 335 "contrib/minizip/iowin32.c", 336 "contrib/minizip/iowin32.h", 337 ] 338 } 339 340 if (is_mac || is_ios || is_android || is_nacl) { 341 # Mac, Android and the BSDs don't have fopen64, ftello64, or fseeko64. We 342 # use fopen, ftell, and fseek instead on these systems. 343 defines = [ "USE_FILE32API" ] 344 } 345 346 deps = [ 347 ":zlib", 348 ] 349 350 configs -= [ "//build/config/compiler:chromium_code" ] 351 configs += [ 352 "//build/config/compiler:no_chromium_code", 353 354 # Must be after no_chromium_code for warning flags to be ordered correctly. 355 ":minizip_warnings", 356 ] 357 358 public_configs = [ ":zlib_config" ] 359} 360 361executable("zlib_bench") { 362 include_dirs = [ "." ] 363 364 sources = [ 365 "contrib/bench/zlib_bench.cc", 366 ] 367 368 if (!is_debug) { 369 configs -= [ "//build/config/compiler:default_optimization" ] 370 configs += [ "//build/config/compiler:optimize_speed" ] 371 } 372 373 configs -= [ "//build/config/compiler:chromium_code" ] 374 configs += [ "//build/config/compiler:no_chromium_code" ] 375 376 deps = [ 377 ":zlib", 378 ] 379} 380