blob: 0f59c0aaf2ac1c82bf766bd44d1601cd5a97cdd7 [file] [log] [blame]
brettw@chromium.org069e2b82014-04-30 16:47:24 +00001# 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
Tomasz Śniatowskiabd51832019-06-24 17:52:19 +00005import("//build/config/compiler/compiler.gni")
6
Adenilson Cavalcanti3060dcb2017-09-29 03:24:52 +00007if (current_cpu == "arm" || current_cpu == "arm64") {
8 import("//build/config/arm.gni")
9}
10
brettw@chromium.org069e2b82014-04-30 16:47:24 +000011config("zlib_config") {
12 include_dirs = [ "." ]
13}
14
Tom Anderson20c7ae12019-04-08 20:51:48 +000015config("zlib_internal_config") {
16 defines = [ "ZLIB_IMPLEMENTATION" ]
17}
18
Daniel Bratelldde5ce52018-10-31 11:39:12 +000019use_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
Noel Gordon17bbb3d2017-09-29 19:44:25 +000029config("zlib_adler32_simd_config") {
Daniel Bratelldde5ce52018-10-31 11:39:12 +000030 if (use_x86_x64_optimizations) {
Noel Gordon17bbb3d2017-09-29 19:44:25 +000031 defines = [ "ADLER32_SIMD_SSSE3" ]
32 }
33
Daniel Bratelldde5ce52018-10-31 11:39:12 +000034 if (use_arm_neon_optimizations) {
35 defines = [ "ADLER32_SIMD_NEON" ]
Noel Gordon17bbb3d2017-09-29 19:44:25 +000036 }
37}
38
39source_set("zlib_adler32_simd") {
40 visibility = [ ":*" ]
41
Daniel Bratelldde5ce52018-10-31 11:39:12 +000042 if (use_x86_x64_optimizations) {
Noel Gordon17bbb3d2017-09-29 19:44:25 +000043 sources = [
44 "adler32_simd.c",
45 "adler32_simd.h",
46 ]
47
48 if (!is_win || is_clang) {
49 cflags = [ "-mssse3" ]
50 }
51 }
52
Daniel Bratelldde5ce52018-10-31 11:39:12 +000053 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" ]
Noel Gordon17bbb3d2017-09-29 19:44:25 +000062 }
63 }
64
Tom Anderson20c7ae12019-04-08 20:51:48 +000065 configs += [ ":zlib_internal_config" ]
66
Noel Gordon17bbb3d2017-09-29 19:44:25 +000067 public_configs = [ ":zlib_adler32_simd_config" ]
68}
69
Daniel Bratelldde5ce52018-10-31 11:39:12 +000070if (use_arm_neon_optimizations) {
71 config("zlib_arm_crc32_config") {
Noel Gordon4bda75a2019-04-15 06:52:31 +000072 # 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) {
Adenilson Cavalcanti72356722018-02-16 03:41:14 +000076 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" ]
Noel Gordon4bda75a2019-04-15 06:52:31 +000081 } else if (is_fuchsia) {
82 defines += [ "ARMV8_OS_FUCHSIA" ]
Richard Townsend8f2b9d42019-04-18 16:45:43 +000083 } else if (is_win) {
84 defines += [ "ARMV8_OS_WINDOWS" ]
85 } else {
Noel Gordon4bda75a2019-04-15 06:52:31 +000086 assert(false, "Unsupported ARM OS")
Adenilson Cavalcanti72356722018-02-16 03:41:14 +000087 }
88 }
89 }
Adenilson Cavalcanti72356722018-02-16 03:41:14 +000090
Adenilson Cavalcanti72356722018-02-16 03:41:14 +000091 source_set("zlib_arm_crc32") {
92 visibility = [ ":*" ]
93
Jose Dapena Pazbbacb132019-06-10 09:16:22 +000094 if (!is_ios) {
Adenilson Cavalcanti72356722018-02-16 03:41:14 +000095 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 = [
Sam Maier0044d042019-08-27 18:09:00 +0000101 "//third_party/android_ndk:cpu_features",
Adenilson Cavalcanti72356722018-02-16 03:41:14 +0000102 ]
Noel Gordon4bda75a2019-04-15 06:52:31 +0000103 } else {
104 assert(false, "CPU detection requires the Android NDK")
Adenilson Cavalcanti72356722018-02-16 03:41:14 +0000105 }
Jose Dapena Pazbbacb132019-06-10 09:16:22 +0000106 } else if (!is_win && !is_clang) {
Tomasz Śniatowskiabd51832019-06-24 17:52:19 +0000107 assert(!use_thin_lto,
Jose Dapena Pazbbacb132019-06-10 09:16:22 +0000108 "ThinLTO fails mixing different module-level targets")
109 cflags_c = [ "-march=armv8-a+crc" ]
Adenilson Cavalcanti72356722018-02-16 03:41:14 +0000110 }
111
112 sources = [
113 "arm_features.c",
114 "arm_features.h",
115 "crc32_simd.c",
116 "crc32_simd.h",
117 ]
118
Adenilson Cavalcanti72356722018-02-16 03:41:14 +0000119 if (!is_debug) {
120 configs -= [ "//build/config/compiler:default_optimization" ]
121 configs += [ "//build/config/compiler:optimize_speed" ]
122 }
123 }
124
Tom Anderson20c7ae12019-04-08 20:51:48 +0000125 configs += [ ":zlib_internal_config" ]
126
Adenilson Cavalcanti72356722018-02-16 03:41:14 +0000127 public_configs = [ ":zlib_arm_crc32_config" ]
128 }
129}
130
Noel Gordon64ffef02017-12-08 11:39:34 +0000131config("zlib_inflate_chunk_simd_config") {
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000132 if (use_x86_x64_optimizations) {
Noel Gordonbedc29e2018-02-12 01:46:01 +0000133 defines = [ "INFLATE_CHUNK_SIMD_SSE2" ]
134
135 if (current_cpu == "x64") {
136 defines += [ "INFLATE_CHUNK_READ_64LE" ]
137 }
Noel Gordon64ffef02017-12-08 11:39:34 +0000138 }
139
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000140 if (use_arm_neon_optimizations) {
141 defines = [ "INFLATE_CHUNK_SIMD_NEON" ]
Adenilson Cavalcanti9972c362019-01-31 21:39:02 +0000142 if (current_cpu == "arm64") {
143 defines += [ "INFLATE_CHUNK_READ_64LE" ]
144 }
Noel Gordon64ffef02017-12-08 11:39:34 +0000145 }
146}
147
148source_set("zlib_inflate_chunk_simd") {
149 visibility = [ ":*" ]
150
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000151 if (use_x86_x64_optimizations || use_arm_neon_optimizations) {
Noel Gordon64ffef02017-12-08 11:39:34 +0000152 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 ]
Noel Gordon64ffef02017-12-08 11:39:34 +0000160
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000161 if (use_arm_neon_optimizations && !is_debug) {
162 # Here we trade better performance on newer/bigger ARMv8 cores
Noel Gordon4bda75a2019-04-15 06:52:31 +0000163 # for less perf on ARMv7, per crbug.com/772870#c40
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000164 configs -= [ "//build/config/compiler:default_optimization" ]
165 configs += [ "//build/config/compiler:optimize_speed" ]
Noel Gordon64ffef02017-12-08 11:39:34 +0000166 }
167 }
168
169 configs -= [ "//build/config/compiler:chromium_code" ]
Tom Anderson20c7ae12019-04-08 20:51:48 +0000170 configs += [
171 ":zlib_internal_config",
172 "//build/config/compiler:no_chromium_code",
173 ]
Noel Gordon64ffef02017-12-08 11:39:34 +0000174
175 public_configs = [ ":zlib_inflate_chunk_simd_config" ]
176}
177
Noel Gordon8e904b32018-01-04 12:10:08 +1100178config("zlib_crc32_simd_config") {
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000179 if (use_x86_x64_optimizations) {
Noel Gordon8e904b32018-01-04 12:10:08 +1100180 defines = [ "CRC32_SIMD_SSE42_PCLMUL" ]
181 }
182}
183
184source_set("zlib_crc32_simd") {
185 visibility = [ ":*" ]
186
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000187 if (use_x86_x64_optimizations) {
Noel Gordon8e904b32018-01-04 12:10:08 +1100188 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
Tom Anderson20c7ae12019-04-08 20:51:48 +0000201 configs += [ ":zlib_internal_config" ]
202
Noel Gordon8e904b32018-01-04 12:10:08 +1100203 public_configs = [ ":zlib_crc32_simd_config" ]
204}
205
Tom Anderson20c7ae12019-04-08 20:51:48 +0000206source_set("zlib_x86_simd") {
Noel Gordon8e904b32018-01-04 12:10:08 +1100207 visibility = [ ":*" ]
208
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000209 if (use_x86_x64_optimizations) {
scottmgb8135bf2014-12-02 23:28:00 -0800210 sources = [
211 "crc_folding.c",
212 "fill_window_sse.c",
213 ]
Noel Gordon8e904b32018-01-04 12:10:08 +1100214
Nico Weber0f60cc52014-11-18 15:21:17 -0800215 if (!is_win || is_clang) {
scottmgb8135bf2014-12-02 23:28:00 -0800216 cflags = [
217 "-msse4.2",
218 "-mpclmul",
219 ]
Nico Weber0f60cc52014-11-18 15:21:17 -0800220 }
robert.bradford10dd6862014-11-05 06:59:34 -0800221 } else {
scottmgb8135bf2014-12-02 23:28:00 -0800222 sources = [
223 "simd_stub.c",
224 ]
robert.bradford10dd6862014-11-05 06:59:34 -0800225 }
dpranke73636152014-11-17 17:54:55 -0800226
227 configs -= [ "//build/config/compiler:chromium_code" ]
Tom Anderson20c7ae12019-04-08 20:51:48 +0000228 configs += [
229 ":zlib_internal_config",
230 "//build/config/compiler:no_chromium_code",
231 ]
robert.bradford10dd6862014-11-05 06:59:34 -0800232}
233
brettw3f3d1262015-09-02 10:57:05 -0700234config("zlib_warnings") {
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000235 if (is_clang && use_x86_x64_optimizations) {
brettw3f3d1262015-09-02 10:57:05 -0700236 cflags = [ "-Wno-incompatible-pointer-types" ]
237 }
238}
239
Tom Anderson20c7ae12019-04-08 20:51:48 +0000240component("zlib") {
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000241 if (!is_win) {
242 # Don't stomp on "libzlib" on other platforms.
243 output_name = "chrome_zlib"
244 }
245
246 sources = [
247 "adler32.c",
Tom Anderson20c7ae12019-04-08 20:51:48 +0000248 "chromeconf.h",
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000249 "compress.c",
250 "crc32.c",
251 "crc32.h",
252 "deflate.c",
253 "deflate.h",
254 "gzclose.c",
255 "gzguts.h",
256 "gzlib.c",
257 "gzread.c",
258 "gzwrite.c",
259 "infback.c",
260 "inffast.c",
261 "inffast.h",
262 "inffixed.h",
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000263 "inflate.h",
264 "inftrees.c",
265 "inftrees.h",
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000266 "trees.c",
267 "trees.h",
268 "uncompr.c",
robert.bradford10dd6862014-11-05 06:59:34 -0800269 "x86.h",
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000270 "zconf.h",
271 "zlib.h",
272 "zutil.c",
273 "zutil.h",
274 ]
275
Boris Sazonov0f473a12017-11-30 10:01:30 +0000276 defines = []
277 deps = []
278
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000279 if (use_x86_x64_optimizations || use_arm_neon_optimizations) {
280 deps += [
281 ":zlib_adler32_simd",
282 ":zlib_inflate_chunk_simd",
283 ]
Noel Gordon8e904b32018-01-04 12:10:08 +1100284
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000285 if (use_x86_x64_optimizations) {
286 sources += [ "x86.c" ]
287 deps += [ ":zlib_crc32_simd" ]
288 } else if (use_arm_neon_optimizations) {
Adenilson Cavalcantid6d19612018-08-07 16:08:59 +0000289 sources += [ "contrib/optimizations/slide_hash_neon.h" ]
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000290 deps += [ ":zlib_arm_crc32" ]
Noel Gordon17bbb3d2017-09-29 19:44:25 +0000291 }
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000292 } else {
293 sources += [ "inflate.c" ]
robert.bradford10dd6862014-11-05 06:59:34 -0800294 }
295
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000296 configs -= [ "//build/config/compiler:chromium_code" ]
brettw3f3d1262015-09-02 10:57:05 -0700297 configs += [
Tom Anderson20c7ae12019-04-08 20:51:48 +0000298 ":zlib_internal_config",
brettw3f3d1262015-09-02 10:57:05 -0700299 "//build/config/compiler:no_chromium_code",
300
301 # Must be after no_chromium_code for warning flags to be ordered correctly.
302 ":zlib_warnings",
303 ]
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000304
Brett Wilson9bdea3f2014-09-23 16:41:46 -0700305 public_configs = [ ":zlib_config" ]
Noel Gordon17bbb3d2017-09-29 19:44:25 +0000306
Adenilson Cavalcantif44229b2017-10-30 18:39:29 +0000307 deps += [ ":zlib_x86_simd" ]
Daniel Bratelldde5ce52018-10-31 11:39:12 +0000308 allow_circular_includes_from = deps
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000309}
310
brettw3f3d1262015-09-02 10:57:05 -0700311config("minizip_warnings") {
312 visibility = [ ":*" ]
Noel Gordon71eb81f2018-02-12 08:15:47 +0000313
brettw3f3d1262015-09-02 10:57:05 -0700314 if (is_clang) {
315 # zlib uses `if ((a == b))` for some reason.
316 cflags = [ "-Wno-parentheses-equality" ]
317 }
318}
319
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000320static_library("minizip") {
321 sources = [
322 "contrib/minizip/ioapi.c",
323 "contrib/minizip/ioapi.h",
324 "contrib/minizip/iowin32.c",
325 "contrib/minizip/iowin32.h",
326 "contrib/minizip/unzip.c",
327 "contrib/minizip/unzip.h",
328 "contrib/minizip/zip.c",
329 "contrib/minizip/zip.h",
330 ]
331
332 if (!is_win) {
333 sources -= [
334 "contrib/minizip/iowin32.c",
335 "contrib/minizip/iowin32.h",
336 ]
337 }
Noel Gordon71eb81f2018-02-12 08:15:47 +0000338
takiseb3994102017-04-06 22:48:40 -0700339 if (is_mac || is_ios || is_android || is_nacl) {
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000340 # Mac, Android and the BSDs don't have fopen64, ftello64, or fseeko64. We
341 # use fopen, ftell, and fseek instead on these systems.
342 defines = [ "USE_FILE32API" ]
343 }
344
scottmgb8135bf2014-12-02 23:28:00 -0800345 deps = [
346 ":zlib",
347 ]
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000348
349 configs -= [ "//build/config/compiler:chromium_code" ]
brettw3f3d1262015-09-02 10:57:05 -0700350 configs += [
351 "//build/config/compiler:no_chromium_code",
352
353 # Must be after no_chromium_code for warning flags to be ordered correctly.
354 ":minizip_warnings",
355 ]
Noel Gordon17bbb3d2017-09-29 19:44:25 +0000356
Brett Wilson9bdea3f2014-09-23 16:41:46 -0700357 public_configs = [ ":zlib_config" ]
brettw@chromium.org069e2b82014-04-30 16:47:24 +0000358}
Noel Gordonc83e2162018-01-21 11:19:12 +0000359
360executable("zlib_bench") {
361 include_dirs = [ "." ]
362
363 sources = [
364 "contrib/bench/zlib_bench.cc",
365 ]
366
367 if (!is_debug) {
368 configs -= [ "//build/config/compiler:default_optimization" ]
369 configs += [ "//build/config/compiler:optimize_speed" ]
370 }
371
372 configs -= [ "//build/config/compiler:chromium_code" ]
373 configs += [ "//build/config/compiler:no_chromium_code" ]
374
375 deps = [
Noel Gordonbedc29e2018-02-12 01:46:01 +0000376 ":zlib",
Noel Gordonc83e2162018-01-21 11:19:12 +0000377 ]
378}