xref: /aosp_15_r20/tools/netsim/src/CMakeLists.txt (revision cf78ab8cffb8fc9207af348f23af247fb04370a6)
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        frontend/server_response_writable.h
64        hci/async_manager.cc
65        hci/bluetooth_facade.cc
66        hci/bluetooth_facade.h
67        hci/hci_packet_transport.cc
68        hci/hci_packet_transport.h
69        hci/rust_device.cc
70        hci/rust_device.h
71    DEPS grpc++ libbt-rootcanal netsimd-proto-lib packet-streamer-proto-lib
72         protobuf::libprotobuf util-lib)
73
74  target_link_libraries(
75    netsimd-lib PUBLIC android-emu-base android-emu-net
76    PRIVATE libslirp glib2 ssl hostapd android-emu-base-headers)
77
78  # Update to protobuf 26.x introduces some warnings.
79  target_compile_options(netsimd-lib PRIVATE -Wno-unused-result)
80
81  target_include_directories(netsimd-lib PRIVATE . ${PROTOBUF_INCLUDE_DIR}
82                             PUBLIC ${cxx_bridge_binary_folder})
83  target_compile_definitions(netsimd-lib PUBLIC NETSIM_ANDROID_EMULATOR)
84  # Make sure we have the cxx files generated before we build them.
85  add_dependencies(netsimd-lib cargo-build_netsim-daemon)
86endif()
87