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