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 15cmake_minimum_required(VERSION 3.16) 16 17project(libarchive_sapi CXX) 18 19set(CMAKE_CXX_STANDARD 17) 20set(CMAKE_CXX_STANDARD_REQUIRED 17) 21set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) 22 23# Build SAPI library 24set(SAPI_ROOT "" CACHE PATH "Path to the Sandboxed API source tree") 25 26include(FetchContent) 27FetchContent_Declare( 28 libarchive 29 GIT_REPOSITORY https://github.com/libarchive/libarchive 30 PATCH_COMMAND cd libarchive && patch < ${CMAKE_SOURCE_DIR}/patches/header.patch && patch < ${CMAKE_SOURCE_DIR}/patches/archive_virtual.patch 31) 32FetchContent_MakeAvailable(libarchive) 33 34add_subdirectory("${SAPI_ROOT}" 35 "${CMAKE_BINARY_DIR}/sandboxed-api-build" 36 EXCLUDE_FROM_ALL 37) 38 39file(STRINGS functions_to_sandbox.txt FUNCTIONS_LIST) 40 41add_sapi_library( 42 libarchive_sapi 43 44 FUNCTIONS ${FUNCTIONS_LIST} 45 46 INPUTS 47 ${CMAKE_BINARY_DIR}/_deps/libarchive-src/libarchive/archive.h 48 ${CMAKE_BINARY_DIR}/_deps/libarchive-src/libarchive/archive_entry.h 49 50 LIBRARY archive_static 51 LIBRARY_NAME Libarchive 52 NAMESPACE "" 53) 54 55target_include_directories(libarchive_sapi INTERFACE 56 "${PROJECT_BINARY_DIR}" # To find the generated SAPI header 57) 58 59add_subdirectory(examples) 60add_subdirectory(test) 61add_subdirectory(ld_preload_example) 62