1# Copyright 2022 The Android Open Source Project 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# http://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. 14add_subdirectory(util) 15if(NOT NETSIM_EXT) 16 add_subdirectory(backend) 17endif() 18 19if(TARGET Rust::Rustc) 20 set(cxx_bridge_binary_folder 21 ${CMAKE_BINARY_DIR}/cargo/build/${Rust_CARGO_TARGET_CACHED}/cxxbridge) 22 set(common_header ${cxx_bridge_binary_folder}/rust/cxx.h) 23 set(cxx_bridge_source_file "src/ffi.rs") 24 set(crate_name "netsim-daemon") 25 set(binding_header 26 ${cxx_bridge_binary_folder}/${crate_name}/${cxx_bridge_source_file}.h) 27 set(binding_source 28 ${cxx_bridge_binary_folder}/${crate_name}/${cxx_bridge_source_file}.cc) 29 30 # Make sure we have the cxx files generated before we build them. 31 add_custom_command(OUTPUT ${common_header} ${binding_header} ${binding_source} 32 COMMAND DEPENDS cargo-build_${crate_name}) 33 34 android_add_library( 35 TARGET netsimd-lib 36 LICENSE Apache-2.0 37 SRC ${binding_header} 38 ${binding_source} 39 ${common_header} 40 hci/async_manager.cc 41 hci/bluetooth_facade.cc 42 hci/bluetooth_facade.h 43 hci/hci_packet_transport.cc 44 hci/hci_packet_transport.h 45 hci/rust_device.cc 46 hci/rust_device.h 47 DEPS grpc++ libbt-rootcanal netsimd-proto-lib packet-streamer-proto-lib 48 protobuf::libprotobuf util-lib) 49 50 target_link_libraries( 51 netsimd-lib PUBLIC android-emu-base android-emu-net 52 PRIVATE libslirp glib2 ssl hostapd android-emu-base-headers) 53 54 # Update to protobuf 26.x introduces some warnings. 55 target_compile_options(netsimd-lib PRIVATE -Wno-unused-result) 56 57 target_include_directories(netsimd-lib PRIVATE . ${PROTOBUF_INCLUDE_DIR} 58 PUBLIC ${cxx_bridge_binary_folder}) 59 target_compile_definitions(netsimd-lib PUBLIC NETSIM_ANDROID_EMULATOR) 60 # Make sure we have the cxx files generated before we build them. 61 add_dependencies(netsimd-lib cargo-build_netsim-daemon) 62endif() 63