xref: /aosp_15_r20/external/openscreen/platform/BUILD.gn (revision 3f982cf4871df8771c9d4abe6e9a6f8d829b2736)
1# Copyright 2018 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build_overrides/build.gni")
6
7# Source files that depend on nothing (all your base/ are belong to us).
8source_set("base") {
9  defines = []
10
11  sources = [
12    "base/error.cc",
13    "base/error.h",
14    "base/interface_info.cc",
15    "base/interface_info.h",
16    "base/ip_address.cc",
17    "base/ip_address.h",
18    "base/location.cc",
19    "base/location.h",
20    "base/tls_connect_options.h",
21    "base/tls_credentials.cc",
22    "base/tls_credentials.h",
23    "base/tls_listen_options.h",
24    "base/trace_logging_activation.cc",
25    "base/trace_logging_activation.h",
26    "base/trace_logging_types.h",
27    "base/trivial_clock_traits.cc",
28    "base/trivial_clock_traits.h",
29    "base/udp_packet.cc",
30    "base/udp_packet.h",
31  ]
32
33  public_configs = [ "../build:openscreen_include_dirs" ]
34}
35
36# Public API source files. May depend on nothing except :base.
37source_set("logging") {
38  defines = []
39
40  sources = [ "api/logging.h" ]
41
42  public_deps = [ ":base" ]
43}
44
45# Public API source files. These may depend on nothing except :base.
46source_set("api") {
47  defines = []
48
49  sources = [
50    "api/export.h",
51    "api/logging.h",
52    "api/network_interface.h",
53    "api/scoped_wake_lock.cc",
54    "api/scoped_wake_lock.h",
55    "api/serial_delete_ptr.h",
56    "api/task_runner.h",
57    "api/time.h",
58    "api/tls_connection.cc",
59    "api/tls_connection.h",
60    "api/tls_connection_factory.cc",
61    "api/tls_connection_factory.h",
62    "api/trace_logging_platform.cc",
63    "api/trace_logging_platform.h",
64    "api/udp_socket.cc",
65    "api/udp_socket.h",
66  ]
67
68  public_deps = [
69    ":base",
70    ":logging",
71  ]
72}
73
74# The following target is only activated in standalone builds (see :platform).
75if (!build_with_chromium) {
76  source_set("standalone_impl") {
77    defines = []
78
79    sources = [
80      "impl/logging.h",
81      "impl/network_interface.cc",
82      "impl/network_interface.h",
83      "impl/socket_handle.h",
84      "impl/socket_handle_waiter.cc",
85      "impl/socket_handle_waiter.h",
86      "impl/socket_state.h",
87      "impl/stream_socket.h",
88      "impl/task_runner.cc",
89      "impl/task_runner.h",
90      "impl/text_trace_logging_platform.cc",
91      "impl/text_trace_logging_platform.h",
92      "impl/time.cc",
93      "impl/tls_write_buffer.cc",
94      "impl/tls_write_buffer.h",
95    ]
96
97    public_configs = [ "//util:trace_logging_config" ]
98
99    if (is_linux) {
100      sources += [
101        "impl/network_interface_linux.cc",
102        "impl/scoped_wake_lock_linux.cc",
103        "impl/scoped_wake_lock_linux.h",
104      ]
105    } else if (is_mac) {
106      defines += [
107        # Required, to use the new IPv6 Sockets options introduced by RFC 3542.
108        "__APPLE_USE_RFC_3542",
109      ]
110
111      frameworks = [
112        "CoreFoundation.framework",
113        "IOKit.framework",
114      ]
115
116      sources += [
117        "impl/network_interface_mac.cc",
118        "impl/scoped_wake_lock_mac.cc",
119        "impl/scoped_wake_lock_mac.h",
120      ]
121    }
122
123    if (is_posix) {
124      sources += [
125        "impl/logging_posix.cc",
126        "impl/logging_test.h",
127        "impl/platform_client_posix.cc",
128        "impl/platform_client_posix.h",
129        "impl/scoped_pipe.h",
130        "impl/socket_address_posix.cc",
131        "impl/socket_address_posix.h",
132        "impl/socket_handle_posix.cc",
133        "impl/socket_handle_posix.h",
134        "impl/socket_handle_waiter_posix.cc",
135        "impl/socket_handle_waiter_posix.h",
136        "impl/stream_socket_posix.cc",
137        "impl/stream_socket_posix.h",
138        "impl/timeval_posix.cc",
139        "impl/timeval_posix.h",
140        "impl/tls_connection_factory_posix.cc",
141        "impl/tls_connection_factory_posix.h",
142        "impl/tls_connection_posix.cc",
143        "impl/tls_connection_posix.h",
144        "impl/tls_data_router_posix.cc",
145        "impl/tls_data_router_posix.h",
146        "impl/udp_socket_posix.cc",
147        "impl/udp_socket_posix.h",
148        "impl/udp_socket_reader_posix.cc",
149        "impl/udp_socket_reader_posix.h",
150      ]
151    }
152
153    deps = [
154      ":api",
155      "../third_party/abseil",
156      "../third_party/boringssl",
157      "../util",
158    ]
159  }
160}
161
162# The main target, which either assumes an embedder will link-in the platform
163# API implementation elsewhere, or links-in the :standalone_impl in the build.
164source_set("platform") {
165  public_deps = [ ":api" ]
166  if (!build_with_chromium) {
167    deps = [ ":standalone_impl" ]
168  }
169}
170
171# Test helpers, referenced in other Open Screen BUILD.gn test targets.
172source_set("test") {
173  testonly = true
174  sources = [
175    "test/fake_clock.cc",
176    "test/fake_clock.h",
177    "test/fake_task_runner.cc",
178    "test/fake_task_runner.h",
179    "test/fake_udp_socket.cc",
180    "test/fake_udp_socket.h",
181    "test/mock_tls_connection.h",
182    "test/mock_udp_socket.h",
183    "test/paths.h",
184    "test/paths_internal.h",
185    "test/trace_logging_helpers.h",
186  ]
187
188  if (is_posix) {
189    sources += [ "test/paths_posix.cc" ]
190  }
191  if (is_linux) {
192    sources += [ "test/paths_internal_linux.cc" ]
193  } else if (is_mac) {
194    sources += [ "test/paths_internal_mac.cc" ]
195  } else if (build_with_chromium) {
196    # NOTE: This is used to resolve a linking issue when compiling in Chromium
197    # for other platforms, but nothing in here is called.
198    sources += [ "test/paths_internal_other.cc" ]
199  }
200
201  public_deps = [
202    ":api",
203    ":base",
204  ]
205
206  deps = [
207    ":platform",
208    "../third_party/abseil",
209    "../third_party/googletest:gmock",
210    "../util",
211  ]
212}
213
214source_set("unittests") {
215  testonly = true
216
217  sources = [
218    "api/serial_delete_ptr_unittest.cc",
219    "api/time_unittest.cc",
220    "base/error_unittest.cc",
221    "base/ip_address_unittest.cc",
222    "base/location_unittest.cc",
223    "base/udp_packet_unittest.cc",
224  ]
225
226  deps = [
227    ":platform",
228    ":test",
229    "../third_party/abseil",
230    "../third_party/boringssl",
231    "../third_party/googletest:gmock",
232    "../third_party/googletest:gtest",
233    "../util",
234  ]
235
236  # The socket integration tests assume that you can Bind with UDP sockets,
237  # which is simply not true when we are built inside of Chromium.
238  if (!build_with_chromium) {
239    sources += [ "api/socket_integration_unittest.cc" ]
240
241    deps += [ ":standalone_impl" ]
242  }
243
244  # The unit tests in impl/ assume the standalone implementation is being used.
245  # Exclude them if an embedder is providing the implementation.
246  if (!build_with_chromium) {
247    sources += [
248      "impl/task_runner_unittest.cc",
249      "impl/time_unittest.cc",
250    ]
251
252    if (is_posix) {
253      sources += [
254        "impl/logging_unittest.cc",
255        "impl/scoped_pipe_unittest.cc",
256        "impl/socket_address_posix_unittest.cc",
257        "impl/socket_handle_waiter_posix_unittest.cc",
258        "impl/timeval_posix_unittest.cc",
259        "impl/tls_data_router_posix_unittest.cc",
260        "impl/tls_write_buffer_unittest.cc",
261        "impl/udp_socket_reader_posix_unittest.cc",
262      ]
263    }
264  }
265}
266