1# Copyright 2019 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15add_subdirectory(tools/filewrapper) 16add_subdirectory(sandbox2) 17add_subdirectory(util) 18if(SAPI_ENABLE_CLANG_TOOL AND NOT SAPI_CLANG_TOOL_EXECUTABLE) 19 add_subdirectory(tools/clang_generator) 20endif() 21add_subdirectory(examples) 22 23# sandboxed_api:config 24add_library(sapi_config ${SAPI_LIB_TYPE} 25 config.cc 26 config.h 27) 28add_library(sapi::config ALIAS sapi_config) 29target_link_libraries(sapi_config 30 PRIVATE sapi::base 31 PUBLIC absl::config 32) 33 34# sandboxed_api:proto_arg 35sapi_protobuf_generate_cpp(_sapi_proto_arg_pb_cc _sapi_proto_arg_pb_h 36 proto_arg.proto 37) 38add_library(sapi_proto_arg_proto ${SAPI_LIB_TYPE} 39 ${_sapi_proto_arg_pb_cc} 40 ${_sapi_proto_arg_pb_h} 41) 42add_library(sapi::proto_arg_proto ALIAS sapi_proto_arg_proto) 43target_link_libraries(sapi_proto_arg_proto PRIVATE 44 protobuf::libprotobuf 45 sapi::base 46) 47 48# sandboxed_api:embed_file 49add_library(sapi_embed_file ${SAPI_LIB_TYPE} 50 embed_file.cc 51 embed_file.h 52 file_toc.h 53) 54add_library(sapi::embed_file ALIAS sapi_embed_file) 55target_link_libraries(sapi_embed_file 56 PRIVATE absl::strings 57 sandbox2::util 58 sapi::base 59 sapi::fileops 60 sapi::raw_logging 61 PUBLIC absl::flat_hash_map 62 absl::synchronization 63) 64 65# sandboxed_api:sapi 66add_library(sapi_sapi ${SAPI_LIB_TYPE} 67 sandbox.cc 68 sandbox.h 69 transaction.cc 70 transaction.h 71) 72add_library(sapi::sapi ALIAS sapi_sapi) 73target_link_libraries(sapi_sapi 74 PRIVATE absl::base 75 absl::dynamic_annotations 76 absl::flat_hash_map 77 absl::log 78 absl::log_globals 79 absl::status 80 absl::statusor 81 absl::str_format 82 absl::strings 83 absl::synchronization 84 sandbox2::bpf_helper 85 sapi::file_base 86 sapi::fileops 87 sapi::runfiles 88 sapi::strerror 89 sandbox2::util 90 sapi::embed_file 91 sapi::vars 92 PUBLIC absl::check 93 absl::core_headers 94 sandbox2::client 95 sandbox2::sandbox2 96 sapi::base 97 sapi::status 98) 99 100# sandboxed_api:call 101add_library(sapi_call ${SAPI_LIB_TYPE} 102 call.h 103) 104add_library(sapi::call ALIAS sapi_call) 105target_link_libraries(sapi_call PRIVATE 106 absl::core_headers 107 sapi::var_type 108 sapi::base 109) 110 111# sandboxed_api:lenval_core 112add_library(sapi_lenval_core ${SAPI_LIB_TYPE} 113 lenval_core.h 114) 115add_library(sapi::lenval_core ALIAS sapi_lenval_core) 116target_link_libraries(sapi_lenval_core PRIVATE 117 sapi::base 118) 119 120# sandboxed_api:var_type 121add_library(sapi_var_type ${SAPI_LIB_TYPE} 122 var_type.h 123) 124add_library(sapi::var_type ALIAS sapi_var_type) 125target_link_libraries(sapi_var_type PRIVATE 126 sapi::base 127) 128 129# sandboxed_api:vars 130add_library(sapi_vars ${SAPI_LIB_TYPE} 131 proto_helper.cc 132 proto_helper.h 133 rpcchannel.cc 134 rpcchannel.h 135 var_abstract.cc 136 var_abstract.h 137 var_array.h 138 var_int.cc 139 var_int.h 140 var_lenval.cc 141 var_lenval.h 142 var_proto.h 143 var_ptr.h 144 var_reg.h 145 var_struct.h 146 var_void.h 147 vars.h 148) 149add_library(sapi::vars ALIAS sapi_vars) 150target_link_libraries(sapi_vars 151 PRIVATE absl::core_headers 152 absl::status 153 absl::statusor 154 absl::str_format 155 absl::strings 156 absl::synchronization 157 absl::utility 158 sandbox2::comms 159 sapi::base 160 sapi::call 161 sapi::lenval_core 162 sapi::proto_arg_proto 163 sapi::status 164 sapi::var_type 165 PUBLIC absl::log 166) 167 168# sandboxed_api:client 169add_library(sapi_client ${SAPI_LIB_TYPE} 170 client.cc 171) 172add_library(sapi::client ALIAS sapi_client) 173target_link_libraries(sapi_client 174 PRIVATE absl::check 175 absl::core_headers 176 absl::dynamic_annotations 177 absl::flags_parse 178 absl::log 179 absl::log_flags 180 absl::log_initialize 181 absl::statusor 182 absl::strings 183 libffi::libffi 184 sandbox2::comms 185 sandbox2::forkingclient 186 sandbox2::logsink 187 sapi::base 188 sapi::call 189 sapi::lenval_core 190 sapi::proto_arg_proto 191 sapi::vars 192 ${CMAKE_DL_LIBS} 193) 194 195if(BUILD_TESTING AND SAPI_BUILD_TESTING AND NOT CMAKE_CROSSCOMPILING) 196 # sandboxed_api:testing 197 add_library(sapi_testing ${SAPI_LIB_TYPE} 198 testing.cc 199 testing.h 200 ) 201 add_library(sapi::testing ALIAS sapi_testing) 202 target_link_libraries(sapi_testing 203 PRIVATE absl::strings 204 sapi::file_base 205 sapi::base 206 PUBLIC sapi::config 207 sandbox2::allow_all_syscalls 208 sandbox2::policybuilder 209 ) 210 211 # sandboxed_api:sapi_test 212 add_executable(sapi_test 213 sapi_test.cc 214 ) 215 target_link_libraries(sapi_test PRIVATE 216 absl::status 217 absl::statusor 218 absl::time 219 benchmark 220 sandbox2::result 221 sapi::proto_arg_proto 222 sapi::sapi 223 sapi::status 224 sapi::status_matchers 225 sapi::stringop_sapi 226 sapi::sum_sapi 227 sapi::test_main 228 sapi::testing 229 ) 230 gtest_discover_tests_xcompile(sapi_test) 231endif() 232 233# Install headers and libraries, excluding tools, tests and examples 234foreach(_dir IN ITEMS . sandbox2 sandbox2/network_proxy sandbox2/util util) 235 get_property(_sapi_targets DIRECTORY ${_dir} PROPERTY BUILDSYSTEM_TARGETS) 236 list(FILTER _sapi_targets INCLUDE REGEX ^\(sapi|sandbox2\).*) 237 list(FILTER _sapi_targets EXCLUDE REGEX _test) 238 install(TARGETS ${_sapi_targets} 239 DESTINATION ${CMAKE_INSTALL_LIBDIR}) 240 set_property(TARGET ${_sapi_targets} PROPERTY SOVERSION 1) 241endforeach() 242 243file(GLOB_RECURSE _sapi_headers true ${CMAKE_CURRENT_LIST_DIR}/*.h) 244list(FILTER _sapi_headers EXCLUDE REGEX /\(tools|examples\)/) 245foreach(_file ${_sapi_headers}) 246 get_filename_component(_dir ${_file} DIRECTORY) 247 string(REPLACE ${CMAKE_CURRENT_LIST_DIR} "" _dir ${_dir}) 248 install(FILES ${_file} 249 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sandboxed_api/${_dir}) 250endforeach() 251 252configure_file( 253 "${PROJECT_SOURCE_DIR}/cmake/sapi.pc.in" 254 "${PROJECT_BINARY_DIR}/sapi.pc" 255 @ONLY 256) 257 258install(FILES "${PROJECT_BINARY_DIR}/sapi.pc" 259 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 260