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) 16 17project(sapi_zstd CXX) 18include(CTest) 19 20set(CMAKE_CXX_STANDARD 17) 21set(CMAKE_CXX_STANDARD_REQUIRED True) 22 23if(NOT TARGET sapi::sapi) 24 set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree") 25 add_subdirectory("${SAPI_ROOT}" 26 "${CMAKE_BINARY_DIR}/sandboxed-api-build" 27 EXCLUDE_FROM_ALL) 28endif() 29 30FetchContent_Declare(libzstd 31 GIT_REPOSITORY https://github.com/facebook/zstd.git 32 GIT_TAG 4dfc4eca9a166b474b09542a9fc8e2da162eea99 33 SOURCE_SUBDIR build/cmake 34) 35FetchContent_MakeAvailable(libzstd) 36 37set(libzstd_INCLUDE_DIR "${libzstd_SOURCE_DIR}/lib") 38add_subdirectory(wrapper) 39 40add_sapi_library( 41 sapi_zstd 42 43 FUNCTIONS 44 ZSTD_versionNumber 45 ZSTD_versionString 46 47 ZSTD_compressBound 48 ZSTD_isError 49 ZSTD_getErrorName 50 ZSTD_minCLevel 51 ZSTD_maxCLevel 52 ZSTD_defaultCLevel 53 54 ZSTD_createDCtx 55 ZSTD_freeDCtx 56 57 ZSTD_createCCtx 58 ZSTD_freeCCtx 59 60 ZSTD_CCtx_setParameter 61 62 ZSTD_compress 63 ZSTD_compressStream 64 ZSTD_compressStream2 65 ZSTD_flushStream 66 ZSTD_endStream 67 68 ZSTD_CStreamInSize 69 ZSTD_CStreamOutSize 70 71 ZSTD_decompress 72 ZSTD_decompressStream 73 74 ZSTD_getFrameContentSize 75 76 ZSTD_compress_fd 77 ZSTD_compressStream_fd 78 79 ZSTD_decompress_fd 80 ZSTD_decompressStream_fd 81 INPUTS 82 "${libzstd_INCLUDE_DIR}/zstd.h" 83 wrapper/wrapper_zstd.h 84 85 LIBRARY wrapper_zstd 86 LIBRARY_NAME Zstd 87 NAMESPACE "" 88) 89add_library(sapi_contrib::zstd ALIAS sapi_zstd) 90target_include_directories(sapi_zstd INTERFACE 91 "${PROJECT_BINARY_DIR}" 92 "${SAPI_SOURCE_DIR}" 93) 94 95if(SAPI_BUILD_EXAMPLES) 96 add_subdirectory(example) 97endif() 98 99if(BUILD_TESTING AND SAPI_BUILD_TESTING) 100 add_subdirectory(test) 101endif() 102