2019-05-06 20:03:29 +08:00
|
|
|
# Copyright 2019 Google LLC. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
|
|
|
|
option(USE_SUPERBUILD "Whether or not a superbuild should be invoked" ON)
|
|
|
|
if(USE_SUPERBUILD)
|
|
|
|
project(superbuild NONE)
|
|
|
|
include(cmake/SuperBuild.cmake)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
project(sandboxed_api C CXX ASM)
|
|
|
|
|
2019-07-09 21:11:47 +08:00
|
|
|
# SAPI-wide setting for the language level
|
|
|
|
set(SAPI_CXX_STANDARD 11)
|
|
|
|
|
2019-05-06 20:03:29 +08:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
list(APPEND CMAKE_PREFIX_PATH
|
|
|
|
"${PROJECT_BINARY_DIR}/Dependencies/Build/gflags"
|
|
|
|
"${PROJECT_BINARY_DIR}/Dependencies/Build/glog"
|
2019-06-05 20:28:34 +08:00
|
|
|
"${PROJECT_BINARY_DIR}/Dependencies/Build/protobuf"
|
2019-05-06 20:03:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
include(SapiUtil)
|
|
|
|
include(GoogleTest)
|
|
|
|
|
|
|
|
# Build Abseil directly, as recommended upstream
|
|
|
|
find_path(absl_src_dir
|
|
|
|
absl/base/port.h
|
|
|
|
HINTS ${ABSL_ROOT_DIR}
|
|
|
|
PATHS ${PROJECT_BINARY_DIR}/Dependencies/Source/absl
|
|
|
|
)
|
2019-07-09 21:11:47 +08:00
|
|
|
set(_sapi_saved_CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD})
|
|
|
|
set(CMAKE_CXX_STANDARD ${SAPI_CXX_STANDARD})
|
2019-05-06 20:03:29 +08:00
|
|
|
add_subdirectory(${absl_src_dir}
|
|
|
|
${PROJECT_BINARY_DIR}/Dependencies/Build/absl
|
|
|
|
EXCLUDE_FROM_ALL)
|
2019-07-09 21:11:47 +08:00
|
|
|
if(_sapi_saved_CMAKE_CXX_STANDARD)
|
|
|
|
set(CMAKE_CXX_STANDARD "${_sapi_saved_CMAKE_CXX_STANDARD}")
|
|
|
|
endif()
|
2019-05-06 20:03:29 +08:00
|
|
|
|
|
|
|
# Build Googletest directly, as recommended upstream
|
|
|
|
find_path(googletest_src_dir
|
|
|
|
googletest/include/gtest/gtest.h
|
|
|
|
HINTS ${GOOGLETEST_ROOT_DIR}
|
|
|
|
PATHS ${PROJECT_BINARY_DIR}/Dependencies/Source/googletest
|
|
|
|
)
|
2019-07-09 21:11:47 +08:00
|
|
|
set(gtest_force_shared_crt ON CACHE BOOL "")
|
2019-05-06 20:03:29 +08:00
|
|
|
add_subdirectory(${googletest_src_dir}
|
|
|
|
${PROJECT_BINARY_DIR}/Dependencies/Build/googletest
|
|
|
|
EXCLUDE_FROM_ALL)
|
|
|
|
|
2019-07-09 21:11:47 +08:00
|
|
|
# Prefer to use static libraries
|
|
|
|
set(_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
2019-05-06 20:03:29 +08:00
|
|
|
if(WIN32)
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
|
|
|
else()
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_package(gflags REQUIRED)
|
|
|
|
find_package(glog REQUIRED)
|
|
|
|
find_package(Libcap REQUIRED)
|
2019-07-09 21:12:49 +08:00
|
|
|
find_package(Libffi REQUIRED)
|
2019-06-07 22:27:06 +08:00
|
|
|
find_package(ZLIB REQUIRED)
|
2019-07-09 21:12:49 +08:00
|
|
|
find_package(Protobuf REQUIRED)
|
2019-05-06 20:03:29 +08:00
|
|
|
|
2019-07-09 21:11:47 +08:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES})
|
|
|
|
|
2019-05-06 20:03:29 +08:00
|
|
|
# Make Bazel-like includes work
|
|
|
|
configure_file(cmake/libcap_capability.h.in
|
2019-07-01 17:53:20 +08:00
|
|
|
libcap/include/sys/capability.h
|
2019-05-06 20:03:29 +08:00
|
|
|
@ONLY)
|
|
|
|
set(libunwind_INCLUDE_DIR
|
2019-07-09 21:11:47 +08:00
|
|
|
${PROJECT_BINARY_DIR}/Dependencies/Source/libunwind/include)
|
2019-05-06 20:03:29 +08:00
|
|
|
configure_file(cmake/libunwind_ptrace.h.in
|
2019-07-01 17:53:20 +08:00
|
|
|
libunwind-ptrace.h
|
2019-05-06 20:03:29 +08:00
|
|
|
@ONLY)
|
|
|
|
|
2019-06-04 18:02:44 +08:00
|
|
|
# Library with basic project settings. The empty file is there to be able to
|
|
|
|
# define header-only libraries without cumbersome target_sources() hacks.
|
2019-06-04 18:47:19 +08:00
|
|
|
file(TOUCH ${PROJECT_BINARY_DIR}/sapi_base_force_cxx_linkage.cc)
|
2019-06-04 18:02:44 +08:00
|
|
|
add_library(sapi_base STATIC
|
2019-06-04 18:47:19 +08:00
|
|
|
${PROJECT_BINARY_DIR}/sapi_base_force_cxx_linkage.cc
|
2019-06-04 18:02:44 +08:00
|
|
|
)
|
2019-05-06 20:03:29 +08:00
|
|
|
add_library(sapi::base ALIAS sapi_base)
|
2019-07-09 21:11:47 +08:00
|
|
|
set_target_properties(sapi_base PROPERTIES
|
|
|
|
CXX_STANDARD ${SAPI_CXX_STANDARD}
|
|
|
|
CXX_STANDARD_REQUIRED TRUE
|
|
|
|
CXX_EXTENSIONS FALSE
|
|
|
|
SKIP_BUILD_RPATH TRUE
|
|
|
|
POSITION_INDEPENDENT_CODE TRUE
|
|
|
|
)
|
2019-05-06 20:03:29 +08:00
|
|
|
target_include_directories(sapi_base INTERFACE
|
|
|
|
${PROJECT_BINARY_DIR}
|
|
|
|
${PROJECT_SOURCE_DIR}
|
2019-06-05 20:28:34 +08:00
|
|
|
${Protobuf_INCLUDE_DIR}
|
2019-05-06 20:03:29 +08:00
|
|
|
# Need to reach into Abseil internal headers from a few targets.
|
|
|
|
${PROJECT_BINARY_DIR}/Dependencies/Source/absl
|
|
|
|
)
|
2019-07-09 21:11:47 +08:00
|
|
|
if(UNIX)
|
|
|
|
target_compile_options(sapi_base INTERFACE
|
|
|
|
-Wno-deprecated
|
|
|
|
)
|
|
|
|
endif()
|
2019-05-06 20:03:29 +08:00
|
|
|
|
|
|
|
add_library(sapi_test_main INTERFACE)
|
|
|
|
add_library(sapi::test_main ALIAS sapi_test_main)
|
|
|
|
target_link_libraries(sapi_test_main INTERFACE
|
|
|
|
gtest_main
|
|
|
|
gmock
|
|
|
|
sapi::base
|
|
|
|
)
|
|
|
|
|
|
|
|
# Setup tests to work like with Bazel
|
2019-06-03 21:27:35 +08:00
|
|
|
create_directory_symlink(${PROJECT_BINARY_DIR} com_google_sandboxed_api)
|
2019-05-06 20:03:29 +08:00
|
|
|
enable_testing()
|
|
|
|
|
|
|
|
add_subdirectory(cmake/libunwind)
|
|
|
|
add_subdirectory(sandboxed_api)
|