2020-01-17 21:05:03 +08:00
|
|
|
# Copyright 2019 Google LLC
|
2019-07-15 19:12:55 +08:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
2022-01-28 17:38:27 +08:00
|
|
|
# https://www.apache.org/licenses/LICENSE-2.0
|
2019-07-15 19:12:55 +08:00
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2022-01-25 20:48:07 +08:00
|
|
|
function(sapi_check_target target)
|
2019-07-26 20:50:45 +08:00
|
|
|
if(NOT TARGET ${target})
|
|
|
|
message(FATAL_ERROR " SAPI: compiling Sandboxed API requires a ${target}
|
|
|
|
CMake target in your project")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2019-07-15 19:12:55 +08:00
|
|
|
|
2022-01-25 20:48:07 +08:00
|
|
|
include(SapiFetchContent)
|
|
|
|
|
2019-11-21 21:16:59 +08:00
|
|
|
# Use static libraries
|
2019-07-15 19:12:55 +08:00
|
|
|
set(_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
2020-12-15 01:15:40 +08:00
|
|
|
if (SAPI_ENABLE_SHARED_LIBS)
|
|
|
|
set(SAPI_LIB_TYPE SHARED)
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
|
|
|
|
set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
|
|
|
|
# Imply linking with system-wide libs
|
|
|
|
set(SAPI_DOWNLOAD_LIBCAP OFF CACHE BOOL "" FORCE)
|
|
|
|
set(SAPI_DOWNLOAD_LIBFFI OFF CACHE BOOL "" FORCE)
|
|
|
|
set(SAPI_DOWNLOAD_PROTOBUF OFF CACHE BOOL "" FORCE)
|
|
|
|
set(SAPI_DOWNLOAD_ZLIB OFF CACHE BOOL "" FORCE)
|
|
|
|
add_compile_definitions(SAPI_LIB_IS_SHARED=1)
|
|
|
|
else()
|
|
|
|
set(SAPI_LIB_TYPE STATIC)
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
|
|
|
|
endif()
|
2019-07-15 19:12:55 +08:00
|
|
|
|
2022-01-25 20:48:07 +08:00
|
|
|
set(_sapi_saved_BUILD_TESTING ${BUILD_TESTING})
|
|
|
|
set(BUILD_TESTING OFF) # No need to build test code of our deps
|
|
|
|
|
2022-04-21 16:17:08 +08:00
|
|
|
if(SAPI_BUILD_TESTING)
|
2019-11-21 21:16:59 +08:00
|
|
|
if(SAPI_DOWNLOAD_GOOGLETEST)
|
2021-02-03 19:18:12 +08:00
|
|
|
include(cmake/googletest.cmake)
|
2019-07-26 20:50:45 +08:00
|
|
|
endif()
|
2022-01-25 20:48:07 +08:00
|
|
|
sapi_check_target(gtest)
|
|
|
|
sapi_check_target(gtest_main)
|
|
|
|
sapi_check_target(gmock)
|
2019-11-21 20:03:47 +08:00
|
|
|
|
2019-11-21 21:16:59 +08:00
|
|
|
if(SAPI_DOWNLOAD_BENCHMARK)
|
2021-02-03 19:18:12 +08:00
|
|
|
include(cmake/benchmark.cmake)
|
2019-11-21 20:03:47 +08:00
|
|
|
endif()
|
2022-01-25 20:48:07 +08:00
|
|
|
sapi_check_target(benchmark)
|
2019-07-26 20:50:45 +08:00
|
|
|
endif()
|
|
|
|
|
2019-11-21 21:16:59 +08:00
|
|
|
if(SAPI_DOWNLOAD_ABSL)
|
2021-02-03 19:18:12 +08:00
|
|
|
include(cmake/abseil-cpp.cmake)
|
2019-07-26 20:50:45 +08:00
|
|
|
endif()
|
2022-01-25 20:48:07 +08:00
|
|
|
sapi_check_target(absl::core_headers)
|
2019-07-26 20:50:45 +08:00
|
|
|
|
2019-11-25 23:30:16 +08:00
|
|
|
if(SAPI_DOWNLOAD_LIBCAP)
|
2021-02-03 19:18:12 +08:00
|
|
|
include(cmake/libcap.cmake)
|
2022-01-25 20:48:07 +08:00
|
|
|
sapi_check_target(libcap::libcap)
|
2019-11-25 23:30:16 +08:00
|
|
|
else()
|
|
|
|
find_package(Libcap REQUIRED)
|
|
|
|
endif()
|
|
|
|
|
2020-03-22 23:44:39 +08:00
|
|
|
if(SAPI_DOWNLOAD_LIBFFI)
|
2021-02-03 19:18:12 +08:00
|
|
|
include(cmake/libffi.cmake)
|
2022-01-25 20:48:07 +08:00
|
|
|
sapi_check_target(libffi::libffi)
|
2020-03-22 23:44:39 +08:00
|
|
|
else()
|
|
|
|
find_package(Libffi REQUIRED)
|
|
|
|
endif()
|
|
|
|
|
2019-11-21 21:16:59 +08:00
|
|
|
if(SAPI_DOWNLOAD_LIBUNWIND)
|
2021-02-03 19:18:12 +08:00
|
|
|
include(cmake/libunwind.cmake)
|
2019-07-26 20:50:45 +08:00
|
|
|
endif()
|
2022-11-30 21:59:36 +08:00
|
|
|
sapi_check_target(unwind_ptrace)
|
2019-07-26 20:50:45 +08:00
|
|
|
|
2019-11-21 21:16:59 +08:00
|
|
|
if(SAPI_DOWNLOAD_PROTOBUF)
|
2021-02-03 19:18:12 +08:00
|
|
|
include(cmake/protobuf.cmake)
|
2019-07-26 20:50:45 +08:00
|
|
|
endif()
|
2022-01-25 20:48:07 +08:00
|
|
|
find_package(Protobuf REQUIRED)
|
2019-07-26 20:50:45 +08:00
|
|
|
|
2022-04-21 16:17:08 +08:00
|
|
|
if(SAPI_BUILD_EXAMPLES)
|
2020-04-30 19:57:09 +08:00
|
|
|
if(SAPI_DOWNLOAD_ZLIB)
|
2021-02-03 19:18:12 +08:00
|
|
|
include(cmake/zlib.cmake)
|
2022-01-25 20:48:07 +08:00
|
|
|
sapi_check_target(ZLIB::ZLIB)
|
2020-04-30 19:57:09 +08:00
|
|
|
else()
|
|
|
|
find_package(ZLIB REQUIRED)
|
|
|
|
endif()
|
2019-07-15 19:42:39 +08:00
|
|
|
endif()
|
2020-03-18 04:26:14 +08:00
|
|
|
|
2020-12-15 01:15:40 +08:00
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
2023-05-12 15:29:13 +08:00
|
|
|
if(SAPI_ENABLE_CLANG_TOOL)
|
|
|
|
# If unset (the default), CMake will build the tool first and add it as a
|
|
|
|
# dependency.
|
|
|
|
set(SAPI_CLANG_TOOL_EXECUTABLE "" CACHE FILEPATH
|
|
|
|
"Path to the Clang tool based header generator"
|
|
|
|
)
|
|
|
|
else()
|
2019-06-25 20:48:56 +08:00
|
|
|
# Find Python 3 and add its location to the cache so that its available in
|
|
|
|
# the add_sapi_library() macro in embedding projects.
|
|
|
|
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
|
|
|
set(SAPI_PYTHON3_EXECUTABLE "${Python3_EXECUTABLE}" CACHE INTERNAL "" FORCE)
|
|
|
|
endif()
|
2019-07-15 19:12:55 +08:00
|
|
|
|
2022-01-25 20:48:07 +08:00
|
|
|
# Undo global changes
|
|
|
|
if(_sapi_saved_BUILD_TESTING)
|
|
|
|
set(BUILD_TESTING "${_sapi_saved_BUILD_TESTING}")
|
|
|
|
endif()
|
2019-07-15 19:12:55 +08:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES})
|