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-cli")
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 ${crate_name}-static)
33
34  android_add_library(
35    TARGET frontend-client
36    LICENSE Apache-2.0
37    SRC ${binding_header} ${binding_source} ${common_header}
38        frontend/frontend_client.cc frontend/frontend_client.h
39    DEPS grpc++ netsim-cli-proto-lib protobuf::libprotobuf util-lib)
40  target_include_directories(frontend-client PRIVATE .
41                             PUBLIC ${cxx_bridge_binary_folder})
42
43  set(cxx_bridge_binary_folder
44      ${CMAKE_BINARY_DIR}/cargo/build/${Rust_CARGO_TARGET_CACHED}/cxxbridge)
45  set(common_header ${cxx_bridge_binary_folder}/rust/cxx.h)
46  set(cxx_bridge_source_file "src/ffi.rs")
47  set(crate_name "netsim-daemon")
48  set(binding_header
49      ${cxx_bridge_binary_folder}/${crate_name}/${cxx_bridge_source_file}.h)
50  set(binding_source
51      ${cxx_bridge_binary_folder}/${crate_name}/${cxx_bridge_source_file}.cc)
52
53  # Make sure we have the cxx files generated before we build them.
54  add_custom_command(OUTPUT ${common_header} ${binding_header} ${binding_source}
55                     COMMAND DEPENDS cargo-build_${crate_name})
56
57  android_add_library(
58    TARGET netsimd-lib
59    LICENSE Apache-2.0
60    SRC ${binding_header}
61        ${binding_source}
62        ${common_header}
63        backend/backend_packet_hub.h
64        backend/grpc_server.cc
65        backend/grpc_server.h
66        core/server.cc
67        core/server.h
68        frontend/frontend_client_stub.cc
69        frontend/frontend_client_stub.h
70        frontend/frontend_server.cc
71        frontend/frontend_server.h
72        frontend/server_response_writable.h
73        hci/async_manager.cc
74        hci/bluetooth_facade.cc
75        hci/bluetooth_facade.h
76        hci/hci_packet_transport.cc
77        hci/hci_packet_transport.h
78        hci/rust_device.cc
79        hci/rust_device.h
80        wifi/wifi_facade.cc
81        wifi/wifi_facade.h
82        wifi/wifi_packet_hub.h
83    DEPS android-emu-base
84         android-emu-base-headers
85         android-wifi-service
86         grpc++
87         libbt-rootcanal
88         netsimd-proto-lib
89         packet-streamer-proto-lib
90         protobuf::libprotobuf
91         util-lib)
92  target_include_directories(netsimd-lib PRIVATE . ${PROTOBUF_INCLUDE_DIR}
93                             PUBLIC ${cxx_bridge_binary_folder})
94  target_compile_definitions(netsimd-lib PUBLIC NETSIM_ANDROID_EMULATOR)
95  # Make sure we have the cxx files generated before we build them.
96  add_dependencies(netsimd-lib cargo-build_netsim-daemon)
97endif()
98