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:embed_file 35add_library(sapi_embed_file ${SAPI_LIB_TYPE} 36 embed_file.cc 37 embed_file.h 38 file_toc.h 39) 40add_library(sapi::embed_file ALIAS sapi_embed_file) 41target_link_libraries(sapi_embed_file 42 PRIVATE absl::strings 43 sandbox2::util 44 sapi::base 45 sapi::raw_logging 46 PUBLIC absl::flat_hash_map 47 absl::synchronization 48 sapi::fileops 49) 50 51# sandboxed_api:sapi 52add_library(sapi_sapi ${SAPI_LIB_TYPE} 53 sandbox.cc 54 sandbox.h 55 transaction.cc 56 transaction.h 57) 58add_library(sapi::sapi ALIAS sapi_sapi) 59target_link_libraries(sapi_sapi 60 PRIVATE absl::base 61 absl::cleanup 62 absl::dynamic_annotations 63 absl::flat_hash_map 64 absl::log 65 absl::log_globals 66 absl::span 67 absl::status 68 absl::statusor 69 absl::str_format 70 absl::strings 71 absl::synchronization 72 sapi::call 73 sapi::file_base 74 sapi::runfiles 75 sapi::strerror 76 sandbox2::util 77 sapi::embed_file 78 sapi::var_type 79 sapi::vars 80 PUBLIC absl::check 81 absl::core_headers 82 sandbox2::client 83 sandbox2::sandbox2 84 sapi::base 85 sapi::status 86) 87 88# sandboxed_api:call 89add_library(sapi_call ${SAPI_LIB_TYPE} 90 call.h 91) 92add_library(sapi::call ALIAS sapi_call) 93target_link_libraries(sapi_call PRIVATE 94 absl::core_headers 95 sapi::var_type 96 sapi::base 97) 98 99# sandboxed_api:lenval_core 100add_library(sapi_lenval_core ${SAPI_LIB_TYPE} 101 lenval_core.h 102) 103add_library(sapi::lenval_core ALIAS sapi_lenval_core) 104target_link_libraries(sapi_lenval_core PRIVATE 105 sapi::base 106) 107 108# sandboxed_api:var_type 109add_library(sapi_var_type ${SAPI_LIB_TYPE} 110 var_type.h 111) 112add_library(sapi::var_type ALIAS sapi_var_type) 113target_link_libraries(sapi_var_type PRIVATE 114 sapi::base 115) 116 117# sandboxed_api:vars 118add_library(sapi_vars ${SAPI_LIB_TYPE} 119 rpcchannel.cc 120 rpcchannel.h 121 var_abstract.cc 122 var_abstract.h 123 var_array.h 124 var_int.cc 125 var_int.h 126 var_lenval.cc 127 var_lenval.h 128 var_proto.h 129 var_ptr.h 130 var_reg.h 131 var_struct.h 132 var_void.h 133 vars.h 134) 135add_library(sapi::vars ALIAS sapi_vars) 136target_link_libraries(sapi_vars 137 PRIVATE absl::core_headers 138 absl::span 139 absl::status 140 absl::statusor 141 absl::str_format 142 absl::strings 143 absl::synchronization 144 absl::utility 145 sandbox2::comms 146 sandbox2::util 147 sapi::base 148 sapi::call 149 sapi::lenval_core 150 sapi::status 151 sapi::var_type 152 PUBLIC absl::log 153 sapi::proto_helper 154) 155 156# sandboxed_api:client 157add_library(sapi_client ${SAPI_LIB_TYPE} 158 client.cc 159) 160add_library(sapi::client ALIAS sapi_client) 161target_link_libraries(sapi_client 162 PRIVATE absl::check 163 absl::core_headers 164 absl::dynamic_annotations 165 absl::flags_parse 166 absl::log 167 absl::log_flags 168 absl::log_initialize 169 absl::statusor 170 absl::strings 171 libffi::libffi 172 sandbox2::comms 173 sandbox2::forkingclient 174 sandbox2::logsink 175 sapi::base 176 sapi::call 177 sapi::lenval_core 178 sapi::proto_arg_proto 179 sapi::proto_helper 180 ${CMAKE_DL_LIBS} 181) 182 183if(BUILD_TESTING AND SAPI_BUILD_TESTING AND NOT CMAKE_CROSSCOMPILING) 184 # sandboxed_api:embed_file_test 185 add_executable(embed_file_test 186 embed_file_test.cc 187 ) 188 target_link_libraries(embed_file_test PRIVATE 189 absl::memory 190 absl::strings 191 sapi::embed_file 192 sapi::test_main 193 ) 194 195 # sandboxed_api:testing 196 add_library(sapi_testing ${SAPI_LIB_TYPE} 197 testing.cc 198 testing.h 199 ) 200 add_library(sapi::testing ALIAS sapi_testing) 201 target_link_libraries(sapi_testing 202 PRIVATE absl::strings 203 sapi::file_base 204 sapi::base 205 PUBLIC sapi::config 206 sandbox2::allowlists_all_syscalls 207 sandbox2::policybuilder 208 ) 209 210 # sandboxed_api:sapi_test 211 add_executable(sapi_test 212 sapi_test.cc 213 ) 214 target_link_libraries(sapi_test PRIVATE 215 absl::status 216 absl::statusor 217 absl::time 218 benchmark 219 sandbox2::result 220 sapi::proto_arg_proto 221 sapi::sapi 222 sapi::status 223 sapi::status_matchers 224 sapi::stringop_sapi 225 sapi::sum_sapi 226 sapi::test_main 227 sapi::testing 228 sapi::thread 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