sandboxed-api/CMakeLists.txt
Christian Blichmann 3c51348aaf Enable CMake projects to consume Sandboxed API via add_subdirectory()
This change moves away from a classical superbuild which downloads and builds
at build time. Instead, we now follow a "Fetch Content" workflow (available as
FetchContent in CMake 3.11+) and download dependencies at config time.

Rationale: Superbuild projects have the disadvantage that projects cannot
directly access their individual declared targets. This is not a problem with
regular libraries, as those are usually/supposed to be installed. With
Sandboxed API, this is not desirable, as it has dependencies like Abseil and
glog, which are almost always consumed by including their source tree using
add_subdirectory().

Fixes #10 and makes external embedding easier.

PiperOrigin-RevId: 260129870
Change-Id: I70f295f29a6e4fc8c330512c94b01ef10c017166
2019-07-26 05:51:08 -07:00

79 lines
2.3 KiB
CMake

# 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.10)
project(SandboxedAPI C CXX ASM)
# SAPI-wide setting for the language level
set(SAPI_CXX_STANDARD 11)
set(SAPI_BINARY_DIR "${PROJECT_BINARY_DIR}" CACHE INTERNAL "" FORCE)
set(SAPI_SOURCE_DIR "${PROJECT_SOURCE_DIR}" CACHE INTERNAL "" FORCE)
# Sapi CMake modules, order matters
list(APPEND CMAKE_MODULE_PATH "${SAPI_SOURCE_DIR}/cmake")
include(SapiOptions)
include(SapiDeps)
include(SapiUtil)
include(SapiBuildDefs)
# Make Bazel-style includes work
configure_file(cmake/libcap_capability.h.in
libcap/include/sys/capability.h
@ONLY)
# Library with basic project settings. The empty file is there to be able to
# define header-only libraries without cumbersome target_sources() hacks.
file(TOUCH ${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc)
add_library(sapi_base STATIC
"${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc"
)
add_library(sapi::base ALIAS sapi_base)
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
)
target_include_directories(sapi_base INTERFACE
"${SAPI_BINARY_DIR}"
"${SAPI_SOURCE_DIR}"
"${Protobuf_INCLUDE_DIR}"
)
if(UNIX)
target_compile_options(sapi_base INTERFACE
-Wno-deprecated
-Wno-psabi
)
endif()
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
)
if(SAPI_ENABLE_TESTS)
include(GoogleTest)
# Setup tests to work like with Bazel
create_directory_symlink("${SAPI_BINARY_DIR}" com_google_sandboxed_api)
enable_testing()
endif()
add_subdirectory(sandboxed_api)