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..3.26) 16 17project(sapi_brotli 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 31FetchContent_Declare(libbrotli 32 GIT_REPOSITORY https://github.com/google/brotli.git 33 GIT_TAG f4153a09f87cbb9c826d8fc12c74642bb2d879ea # 2022-01-10 34) 35FetchContent_MakeAvailable(libbrotli) 36 37set(brotli_INCLUDE_DIR "${brotli_SOURCE_DIR}/c/include") 38configure_file(brotli.gen.h.in brotli.gen.h) 39 40add_library(brotli_static STATIC 41 "${SAPI_BINARY_DIR}/sapi_force_cxx_linkage.cc" 42 $<TARGET_OBJECTS:brotlicommon-static> 43 $<TARGET_OBJECTS:brotlidec-static> 44 $<TARGET_OBJECTS:brotlienc-static> 45) 46 47add_sapi_library(sapi_brotli 48 FUNCTIONS BrotliDecoderCreateInstance 49 BrotliDecoderSetParameter 50 BrotliDecoderDecompressStream 51 BrotliDecoderTakeOutput 52 BrotliDecoderDestroyInstance 53 54 BrotliEncoderCreateInstance 55 BrotliEncoderCompressStream 56 BrotliEncoderTakeOutput 57 BrotliEncoderSetParameter 58 BrotliEncoderDestroyInstance 59 60 INPUTS "${CMAKE_BINARY_DIR}/brotli.gen.h" 61 62 LIBRARY brotli_static 63 LIBRARY_NAME Brotli 64 NAMESPACE "" 65) 66add_library(sapi_contrib::brotli ALIAS sapi_brotli) 67target_include_directories(sapi_brotli INTERFACE 68 "${PROJECT_BINARY_DIR}" 69 "${SAPI_SOURCE_DIR}" 70) 71 72if(SAPI_BUILD_EXAMPLES) 73 add_subdirectory(example) 74endif() 75 76if(BUILD_TESTING AND SAPI_BUILD_TESTING) 77 add_subdirectory(test) 78endif() 79