1# Copyright 2022 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# 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, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15# Netsim - a network simulator for discovery, ranging and communication
16
17project(netsim)
18cmake_minimum_required(VERSION 3.5)
19cmake_policy(SET CMP0079 NEW)
20set(CMAKE_CXX_STANDARD 17)
21set(CMAKE_CXX_STANDARD_REQUIRED True)
22set(CMAKE_POSITION_INDEPENDENT_CODE ON)
23list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
24
25if(NOT ANDROID_EMULATOR_BUILD)
26  message(STATUS "Building netsim standalone.")
27  include(netsim_dependencies)
28endif()
29
30if(TARGET Rust::Rustc)
31  add_subdirectory(pdl)
32  add_subdirectory(rust)
33else()
34  message(WARNING "Only building client side dependencies.")
35endif()
36
37add_subdirectory(proto)
38add_subdirectory(src)
39
40if(TARGET Rust::Rustc)
41  android_add_executable(
42    TARGET netsim LICENSE Apache-2.0 INSTALL . SRC rust/netsim.cc
43    DEPS frontend-client grpc++ netsim-cli-proto-lib netsim-cli-rust-lib
44         protobuf::libprotobuf util-lib)
45
46  android_add_executable(
47    TARGET netsimd
48    LICENSE Apache-2.0 INSTALL .
49    SRC rust/netsimd.cc
50    DEPS grpc++
51         libbt-rootcanal
52         netsim-cli-proto-lib
53         netsim-daemon
54         netsimd-lib
55         netsimd-proto-lib
56         packet-streamer-proto-lib)
57
58  if(NOT DARWIN_AARCH64 AND NOT DARWIN_X86_64)
59    # Prevent duplicate symbol for cxx Rust crate.
60    target_link_libraries(netsimd PRIVATE -Wl,--allow-multiple-definition)
61  endif()
62
63  android_target_dependency(netsimd linux TCMALLOC_OS_DEPENDENCIES)
64
65  android_add_test(
66    TARGET netsim-test LICENSE Apache-2.0
67    SRC src/util/ini_file_test.cc src/util/os_utils_test.cc
68        src/util/string_utils_test.cc
69    DEPS android-emu-base-headers
70         grpc++
71         gtest
72         gtest_main
73         libbt-rootcanal
74         netsim-cli-proto-lib
75         netsim-daemon
76         netsim-proto
77         netsimd-lib
78         netsimd-proto-lib
79         protobuf::libprotobuf
80         util-lib)
81
82  target_compile_definitions(netsim-test PUBLIC NETSIM_ANDROID_EMULATOR)
83  target_include_directories(netsim-test PRIVATE src)
84
85  # Link NtDll to netsim executables.
86  if(WIN32)
87    target_link_libraries(netsim PRIVATE ntdll)
88    target_link_libraries(netsimd PRIVATE ntdll)
89    target_link_libraries(netsim-test PRIVATE ntdll)
90    android_license(TARGET "ntdll" LIBNAME None SPDX None LICENSE None
91                    LOCAL None)
92  endif()
93endif()
94
95if(NOT NETSIM_EXT)
96  android_add_executable(
97    TARGET netsim-packet-streamer-client
98    LICENSE Apache-2.0
99    SRC src/netsim-packet-streamer-client.cc
100    DEPS grpc++ packet-streamer-client-lib packet-streamer-proto-lib
101         protobuf::libprotobuf)
102endif()
103
104add_subdirectory(ui)
105