xref: /aosp_15_r20/external/sandboxed-api/cmake/zlib.cmake (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1# Copyright 2020 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15FetchContent_Declare(zlib
16  URL      https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz
17  URL_HASH SHA256=c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1
18  PATCH_COMMAND patch -p1
19                < "${SAPI_SOURCE_DIR}/sandboxed_api/bazel/external/zlib.patch"
20)
21FetchContent_GetProperties(zlib)
22if(NOT zlib_POPULATED)
23  FetchContent_Populate(zlib)
24endif()
25
26set(ZLIB_FOUND TRUE)
27set(ZLIB_INCLUDE_DIRS ${zlib_SOURCE_DIR})
28
29add_library(z STATIC
30  ${zlib_SOURCE_DIR}/adler32.c
31  ${zlib_SOURCE_DIR}/compress.c
32  ${zlib_SOURCE_DIR}/crc32.c
33  ${zlib_SOURCE_DIR}/crc32.h
34  ${zlib_SOURCE_DIR}/deflate.c
35  ${zlib_SOURCE_DIR}/deflate.h
36  ${zlib_SOURCE_DIR}/gzclose.c
37  ${zlib_SOURCE_DIR}/gzguts.h
38  ${zlib_SOURCE_DIR}/gzlib.c
39  ${zlib_SOURCE_DIR}/gzread.c
40  ${zlib_SOURCE_DIR}/gzwrite.c
41  ${zlib_SOURCE_DIR}/infback.c
42  ${zlib_SOURCE_DIR}/inffast.c
43  ${zlib_SOURCE_DIR}/inffast.h
44  ${zlib_SOURCE_DIR}/inffixed.h
45  ${zlib_SOURCE_DIR}/inflate.c
46  ${zlib_SOURCE_DIR}/inflate.h
47  ${zlib_SOURCE_DIR}/inftrees.c
48  ${zlib_SOURCE_DIR}/inftrees.h
49  ${zlib_SOURCE_DIR}/trees.c
50  ${zlib_SOURCE_DIR}/trees.h
51  ${zlib_SOURCE_DIR}/uncompr.c
52  ${zlib_SOURCE_DIR}/zconf.h
53  ${zlib_SOURCE_DIR}/zlib.h
54  ${zlib_SOURCE_DIR}/zutil.c
55  ${zlib_SOURCE_DIR}/zutil.h
56)
57add_library(ZLIB::ZLIB ALIAS z)
58target_include_directories(z PUBLIC
59  ${zlib_SOURCE_DIR}
60)
61target_compile_options(z PRIVATE
62  -w
63  -Dverbose=-1
64)
65target_link_libraries(z PRIVATE
66  sapi::base
67)
68
69