2020-01-17 05:05:03 -08:00
|
|
|
# Copyright 2019 Google LLC
|
2019-05-06 14:03:29 +02: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
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2019-11-21 05:16:59 -08:00
|
|
|
cmake_minimum_required(VERSION 3.12)
|
2019-05-06 14:03:29 +02:00
|
|
|
|
2020-09-23 06:42:34 -07:00
|
|
|
# Fix Ninja generator output to not rebuild entire sub-trees needlessly.
|
|
|
|
if(CMAKE_GENERATOR MATCHES "Ninja")
|
|
|
|
file(WRITE "${CMAKE_BINARY_DIR}/UserMakeRulesOverride.cmake"
|
|
|
|
"string(REPLACE \"-MD\" \"-MMD\" CMAKE_DEPFILE_FLAGS_C \"\${CMAKE_DEPFILE_FLAGS_C}\")\n"
|
|
|
|
"string(REPLACE \"-MD\" \"-MMD\" CMAKE_DEPFILE_FLAGS_CXX \"\${CMAKE_DEPFILE_FLAGS_CXX}\")\n"
|
|
|
|
)
|
|
|
|
set(CMAKE_USER_MAKE_RULES_OVERRIDE
|
|
|
|
"${CMAKE_BINARY_DIR}/UserMakeRulesOverride.cmake" CACHE INTERNAL "")
|
|
|
|
endif()
|
|
|
|
|
2019-07-26 05:50:45 -07:00
|
|
|
project(SandboxedAPI C CXX ASM)
|
2019-05-06 14:03:29 +02:00
|
|
|
|
2019-07-09 06:11:47 -07:00
|
|
|
# SAPI-wide setting for the language level
|
2019-11-20 04:39:44 -08:00
|
|
|
set(SAPI_CXX_STANDARD 17)
|
2019-07-09 06:11:47 -07:00
|
|
|
|
2019-07-26 05:50:45 -07:00
|
|
|
set(SAPI_BINARY_DIR "${PROJECT_BINARY_DIR}" CACHE INTERNAL "" FORCE)
|
|
|
|
set(SAPI_SOURCE_DIR "${PROJECT_SOURCE_DIR}" CACHE INTERNAL "" FORCE)
|
|
|
|
|
2020-12-14 09:15:40 -08:00
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE CACHE BOOL "" FORCE)
|
|
|
|
|
2019-07-30 06:51:15 -07:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
2020-12-14 09:03:29 -08:00
|
|
|
# TODO(cblichmann): Only apply this to SAPI and its dependencies
|
|
|
|
add_compile_options(-fno-exceptions)
|
|
|
|
|
|
|
|
if(SAPI_HARDENED_SOURCE)
|
|
|
|
add_compile_options(-fstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2)
|
|
|
|
add_link_options(-Wl,-z,relro -Wl,-z,now)
|
|
|
|
endif()
|
|
|
|
|
2019-07-15 04:42:39 -07:00
|
|
|
# Sapi CMake modules, order matters
|
2019-07-26 05:50:45 -07:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${SAPI_SOURCE_DIR}/cmake")
|
2019-07-15 04:42:39 -07:00
|
|
|
include(SapiOptions)
|
2019-07-15 04:12:55 -07:00
|
|
|
include(SapiDeps)
|
2019-07-15 04:42:39 -07:00
|
|
|
include(SapiUtil)
|
2019-07-15 04:12:55 -07:00
|
|
|
include(SapiBuildDefs)
|
2020-12-16 06:45:33 -08:00
|
|
|
include(GNUInstallDirs)
|
2019-07-15 04:42:39 -07:00
|
|
|
|
2020-09-23 06:42:34 -07:00
|
|
|
# Allow the header generator to auto-configure include paths
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
2019-06-25 14:48:56 +02:00
|
|
|
|
2020-09-25 01:13:50 -07:00
|
|
|
# Allow the header generator to auto-configure include paths
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
2020-12-11 14:58:01 -08:00
|
|
|
if(SAPI_FORCE_COLOR_OUTPUT)
|
2019-06-25 14:48:56 +02:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # GCC
|
|
|
|
add_compile_options(-fdiagnostics-color=always)
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Clang or Apple Clang
|
|
|
|
add_compile_options(-fcolor-diagnostics)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-07-15 04:12:55 -07:00
|
|
|
# Make Bazel-style includes work
|
2019-05-06 14:03:29 +02:00
|
|
|
configure_file(cmake/libcap_capability.h.in
|
2019-07-01 02:53:20 -07:00
|
|
|
libcap/include/sys/capability.h
|
2019-05-06 14:03:29 +02:00
|
|
|
@ONLY)
|
|
|
|
|
2019-06-04 03:02:44 -07: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-08-23 05:08:29 -07:00
|
|
|
file(WRITE ${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc "")
|
2019-06-04 03:02:44 -07:00
|
|
|
add_library(sapi_base STATIC
|
2019-07-26 05:50:45 -07:00
|
|
|
"${SAPI_BINARY_DIR}/sapi_base_force_cxx_linkage.cc"
|
2019-06-04 03:02:44 -07:00
|
|
|
)
|
2019-05-06 14:03:29 +02:00
|
|
|
add_library(sapi::base ALIAS sapi_base)
|
2019-07-09 06:11:47 -07: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 14:03:29 +02:00
|
|
|
target_include_directories(sapi_base INTERFACE
|
2019-07-26 05:50:45 -07:00
|
|
|
"${SAPI_BINARY_DIR}"
|
|
|
|
"${SAPI_SOURCE_DIR}"
|
|
|
|
"${Protobuf_INCLUDE_DIR}"
|
2019-07-30 06:51:15 -07:00
|
|
|
# Need to reach into Abseil internal headers from a few targets.
|
|
|
|
"${CMAKE_BINARY_DIR}/absl-src"
|
2019-05-06 14:03:29 +02:00
|
|
|
)
|
2019-07-09 06:11:47 -07:00
|
|
|
if(UNIX)
|
2019-07-30 06:51:15 -07:00
|
|
|
foreach(flag IN ITEMS -Wno-deprecated
|
|
|
|
-Wno-deprecated-declarations
|
|
|
|
-Wno-psabi)
|
|
|
|
check_cxx_compiler_flag(${flag} _sapi_has_flag)
|
|
|
|
if(_sapi_has_flag)
|
2020-10-26 01:21:58 -07:00
|
|
|
target_compile_options(sapi_base INTERFACE ${flag})
|
2019-07-30 06:51:15 -07:00
|
|
|
endif()
|
2020-10-26 01:21:58 -07:00
|
|
|
unset(_sapi_has_flag)
|
2019-07-30 06:51:15 -07:00
|
|
|
endforeach()
|
2019-07-09 06:11:47 -07:00
|
|
|
endif()
|
2019-05-06 14:03:29 +02: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
|
|
|
|
)
|
|
|
|
|
2019-07-26 05:50:45 -07:00
|
|
|
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()
|
2019-05-06 14:03:29 +02:00
|
|
|
|
|
|
|
add_subdirectory(sandboxed_api)
|