xref: /aosp_15_r20/external/sandboxed-api/contrib/libzip/CMakeLists.txt (revision ec63e07ab9515d95e79c211197c445ef84cefa6a)
1# Copyright 2022 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
15cmake_minimum_required(VERSION 3.13..2.22)
16
17project(sapi_zip CXX)
18include(CTest)
19include(GoogleTest)
20
21set(CMAKE_CXX_STANDARD 17)
22set(CMAKE_CXX_STANDARD_REQUIRED True)
23
24if(NOT TARGET sapi::sapi)
25  set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree")
26  add_subdirectory("${SAPI_ROOT}"
27                   "${CMAKE_BINARY_DIR}/sandboxed-api-build"
28                   EXCLUDE_FROM_ALL)
29endif()
30
31set(BUILD_SHARED_LIBS OFF)
32set(BUILD_TOOLS OFF CACHE BOOL "" FORCE)
33set(BUILD_REGRESS OFF CACHE BOOL "" FORCE)
34set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
35set(BUILD_DOC OFF CACHE BOOL "" FORCE)
36set(LIBZIP_DO_INSTALL OFF CACHE BOOL "" FORCE)
37FetchContent_Declare(libzip
38  GIT_REPOSITORY https://github.com/nih-at/libzip/
39  GIT_TAG        e076a6fd97663025785a64cc8160aa633220be61 # 2022-06-08
40)
41FetchContent_MakeAvailable(libzip)
42
43add_subdirectory(wrapper)
44
45add_sapi_library(sapi_zip
46  FUNCTIONS zip_open_from_source
47            zip_close
48
49            zip_get_name
50            zip_get_num_entries
51
52            zip_stat
53            zip_stat_index
54
55            zip_fopen
56            zip_fopen_index
57            zip_fclose
58
59            zip_fread
60            zip_fseek
61            zip_ftell
62
63            zip_source_buffer
64            zip_read_fd_to_source
65            zip_source_to_fd
66            zip_source_filefd
67            zip_source_filefd_create
68            zip_source_keep
69            zip_source_free
70
71            zip_file_add
72            zip_file_replace
73            zip_delete
74
75            zip_strerror
76  INPUTS "${libzip_BINARY_DIR}/zipconf.h"
77         "${libzip_SOURCE_DIR}/lib/zip.h"
78         wrapper/wrapper_zip.h
79
80  LIBRARY libzip::zip
81  LIBRARY_NAME Zip
82  NAMESPACE ""
83)
84add_library(sapi_contrib::libzip ALIAS sapi_zip)
85target_include_directories(sapi_zip PUBLIC
86  "${PROJECT_BINARY_DIR}"
87  "${libzip_BINARY_DIR}"
88)
89target_sources(sapi_zip PUBLIC
90  sandboxed.h
91  utils/utils_zip.cc
92  utils/utils_zip.h
93)
94target_link_libraries(sapi_zip PRIVATE
95  absl::die_if_null
96)
97
98if(SAPI_BUILD_EXAMPLES)
99  add_subdirectory(example)
100endif()
101
102if(BUILD_TESTING AND SAPI_BUILD_TESTING)
103  add_subdirectory(test)
104endif()
105