mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Do not use any global compiler settings in CMake build
This change also tries to make the build more idempotent wrt to embedding projects. PiperOrigin-RevId: 257177255 Change-Id: I291cd02840496db901f829e902623887f6e0eb10
This commit is contained in:
parent
d170bc3c80
commit
b5d85f5e56
|
@ -22,6 +22,9 @@ if(USE_SUPERBUILD)
|
|||
endif()
|
||||
project(sandboxed_api C CXX ASM)
|
||||
|
||||
# SAPI-wide setting for the language level
|
||||
set(SAPI_CXX_STANDARD 11)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
list(APPEND CMAKE_PREFIX_PATH
|
||||
"${PROJECT_BINARY_DIR}/Dependencies/Build/gflags"
|
||||
|
@ -29,7 +32,6 @@ list(APPEND CMAKE_PREFIX_PATH
|
|||
"${PROJECT_BINARY_DIR}/Dependencies/Build/protobuf"
|
||||
)
|
||||
|
||||
include(SapiCompilerOptions)
|
||||
include(SapiUtil)
|
||||
include(GoogleTest)
|
||||
|
||||
|
@ -39,9 +41,14 @@ find_path(absl_src_dir
|
|||
HINTS ${ABSL_ROOT_DIR}
|
||||
PATHS ${PROJECT_BINARY_DIR}/Dependencies/Source/absl
|
||||
)
|
||||
set(_sapi_saved_CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD})
|
||||
set(CMAKE_CXX_STANDARD ${SAPI_CXX_STANDARD})
|
||||
add_subdirectory(${absl_src_dir}
|
||||
${PROJECT_BINARY_DIR}/Dependencies/Build/absl
|
||||
EXCLUDE_FROM_ALL)
|
||||
if(_sapi_saved_CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD "${_sapi_saved_CMAKE_CXX_STANDARD}")
|
||||
endif()
|
||||
|
||||
# Build Googletest directly, as recommended upstream
|
||||
find_path(googletest_src_dir
|
||||
|
@ -49,12 +56,13 @@ find_path(googletest_src_dir
|
|||
HINTS ${GOOGLETEST_ROOT_DIR}
|
||||
PATHS ${PROJECT_BINARY_DIR}/Dependencies/Source/googletest
|
||||
)
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "")
|
||||
add_subdirectory(${googletest_src_dir}
|
||||
${PROJECT_BINARY_DIR}/Dependencies/Build/googletest
|
||||
EXCLUDE_FROM_ALL)
|
||||
|
||||
# Always use static libraries
|
||||
# Prefer to use static libraries
|
||||
set(_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
if(WIN32)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
else()
|
||||
|
@ -67,12 +75,14 @@ find_package(Protobuf REQUIRED)
|
|||
find_package(Libcap REQUIRED)
|
||||
find_package(ZLIB REQUIRED)
|
||||
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
|
||||
# Make Bazel-like includes work
|
||||
configure_file(cmake/libcap_capability.h.in
|
||||
libcap/include/sys/capability.h
|
||||
@ONLY)
|
||||
set(libunwind_INCLUDE_DIR
|
||||
${PROJECT_BINARY_DIR}/Dependencies/Source/libunwind/include)
|
||||
${PROJECT_BINARY_DIR}/Dependencies/Source/libunwind/include)
|
||||
configure_file(cmake/libunwind_ptrace.h.in
|
||||
libunwind-ptrace.h
|
||||
@ONLY)
|
||||
|
@ -84,6 +94,13 @@ add_library(sapi_base STATIC
|
|||
${PROJECT_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
|
||||
${PROJECT_BINARY_DIR}
|
||||
${PROJECT_SOURCE_DIR}
|
||||
|
@ -91,6 +108,11 @@ target_include_directories(sapi_base INTERFACE
|
|||
# Need to reach into Abseil internal headers from a few targets.
|
||||
${PROJECT_BINARY_DIR}/Dependencies/Source/absl
|
||||
)
|
||||
if(UNIX)
|
||||
target_compile_options(sapi_base INTERFACE
|
||||
-Wno-deprecated
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(sapi_test_main INTERFACE)
|
||||
add_library(sapi::test_main ALIAS sapi_test_main)
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
# 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.
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(CMAKE_SKIP_BUILD_RPATH TRUE)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
||||
|
||||
# Compiler-specific global options
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # GCC
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported compiler")
|
||||
endif()
|
||||
|
||||
# OS-specific global options
|
||||
if(UNIX)
|
||||
add_compile_options(-Wno-deprecated)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported OS")
|
||||
endif()
|
Loading…
Reference in New Issue
Block a user