• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 The Pigweed Authors
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#     https://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
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pigweed/third_party/emboss/build_defs.gni")
18import("$dir_pw_async2/backend.gni")
19import("$dir_pw_bloat/bloat.gni")
20import("$dir_pw_build/module_config.gni")
21import("$dir_pw_build/target_types.gni")
22import("$dir_pw_chrono/backend.gni")
23import("$dir_pw_docgen/docs.gni")
24import("$dir_pw_unit_test/test.gni")
25
26declare_args() {
27  # The build target that overrides the default configuration options for this
28  # module. This should point to a source set that provides defines through a
29  # public config (which may -include a file or add defines directly).
30  pw_bluetooth_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
31}
32
33pw_source_set("config") {
34  public = [ "public/pw_bluetooth/config.h" ]
35  public_configs = [ ":public_include_path" ]
36  public_deps = [ pw_bluetooth_CONFIG ]
37}
38
39config("public_include_path") {
40  include_dirs = [ "public" ]
41  visibility = [ ":*" ]
42}
43
44pw_doc_group("docs") {
45  # Also, sources with doxygen comment blocks must be added to //docs/BUILD.gn
46  inputs = [ "emboss_test.cc" ]
47  sources = [ "docs.rst" ]
48
49  report_deps = [
50    ":emboss_size_report",
51    ":emboss_size_report_diff",
52  ]
53}
54
55pw_source_set("pw_bluetooth") {
56  public_configs = [ ":public_include_path" ]
57  public = [
58    "public/pw_bluetooth/address.h",
59    "public/pw_bluetooth/assigned_uuids.h",
60    "public/pw_bluetooth/constants.h",
61    "public/pw_bluetooth/controller.h",
62    "public/pw_bluetooth/gatt/client.h",
63    "public/pw_bluetooth/gatt/constants.h",
64    "public/pw_bluetooth/gatt/error.h",
65    "public/pw_bluetooth/gatt/server.h",
66    "public/pw_bluetooth/gatt/types.h",
67    "public/pw_bluetooth/host.h",
68    "public/pw_bluetooth/internal/hex.h",
69    "public/pw_bluetooth/internal/raii_ptr.h",
70    "public/pw_bluetooth/low_energy/advertising_data.h",
71    "public/pw_bluetooth/low_energy/bond_data.h",
72    "public/pw_bluetooth/low_energy/central.h",
73    "public/pw_bluetooth/low_energy/channel.h",
74    "public/pw_bluetooth/low_energy/connection.h",
75    "public/pw_bluetooth/low_energy/peripheral.h",
76    "public/pw_bluetooth/low_energy/security_mode.h",
77    "public/pw_bluetooth/pairing_delegate.h",
78    "public/pw_bluetooth/peer.h",
79    "public/pw_bluetooth/result.h",
80    "public/pw_bluetooth/types.h",
81    "public/pw_bluetooth/uuid.h",
82    "public/pw_bluetooth/vendor.h",
83  ]
84  public_deps = [
85    ":config",
86    "$dir_pw_chrono:system_clock",
87    "$dir_pw_string:string",
88    dir_pw_containers,
89    dir_pw_function,
90    dir_pw_multibuf,
91    dir_pw_result,
92    dir_pw_span,
93    dir_pw_status,
94  ]
95}
96
97pw_source_set("pw_bluetooth2") {
98  public_configs = [ ":public_include_path" ]
99  public = [
100    "public/pw_bluetooth/address.h",
101    "public/pw_bluetooth/assigned_uuids.h",
102    "public/pw_bluetooth/constants.h",
103    "public/pw_bluetooth/controller2.h",
104    "public/pw_bluetooth/gatt/client2.h",
105    "public/pw_bluetooth/gatt/constants.h",
106    "public/pw_bluetooth/gatt/error.h",
107    "public/pw_bluetooth/gatt/server2.h",
108    "public/pw_bluetooth/gatt/types.h",
109    "public/pw_bluetooth/internal/hex.h",
110    "public/pw_bluetooth/internal/raii_ptr.h",
111    "public/pw_bluetooth/low_energy/advertising_data.h",
112    "public/pw_bluetooth/low_energy/bond_data2.h",
113    "public/pw_bluetooth/low_energy/central2.h",
114    "public/pw_bluetooth/low_energy/channel.h",
115    "public/pw_bluetooth/low_energy/connection2.h",
116    "public/pw_bluetooth/low_energy/peripheral2.h",
117    "public/pw_bluetooth/low_energy/phy.h",
118    "public/pw_bluetooth/low_energy/security_mode.h",
119    "public/pw_bluetooth/pairing_delegate2.h",
120    "public/pw_bluetooth/peer.h",
121    "public/pw_bluetooth/types.h",
122    "public/pw_bluetooth/uuid.h",
123    "public/pw_bluetooth/vendor.h",
124  ]
125  public_deps = [
126    ":config",
127    "$dir_pw_async2:dispatcher",
128    "$dir_pw_async2:once_sender",
129    "$dir_pw_chrono:system_clock",
130    "$dir_pw_result:expected",
131    "$dir_pw_string:string",
132    dir_pw_channel,
133    dir_pw_containers,
134    dir_pw_function,
135    dir_pw_multibuf,
136    dir_pw_result,
137    dir_pw_span,
138    dir_pw_status,
139  ]
140}
141
142pw_source_set("emboss_util") {
143  public_configs = [ ":public_include_path" ]
144  public = [ "public/pw_bluetooth/emboss_util.h" ]
145  public_deps = [
146    dir_pw_result,
147    dir_pw_span,
148    dir_pw_status,
149  ]
150}
151
152pw_source_set("snoop") {
153  public_configs = [ ":public_include_path" ]
154  public = [ "public/pw_bluetooth/snoop.h" ]
155  sources = [ "snoop.cc" ]
156  public_deps = [
157    ":emboss_snoop",
158    "$dir_pw_chrono:system_clock",
159    "$dir_pw_containers:inline_var_len_entry_queue",
160    "$dir_pw_sync:mutex",
161    "$dir_pw_sync:virtual_basic_lockable",
162    dir_pw_assert,
163    dir_pw_bluetooth_proxy,
164    dir_pw_hex_dump,
165    dir_pw_log,
166    dir_pw_result,
167  ]
168}
169
170if (dir_pw_third_party_emboss != "") {
171  config("emboss_include_path") {
172    include_dirs = [
173      "$target_gen_dir/public",
174
175      # Emboss headers (.emb.h) need to look for imported Emboss file headers in
176      # Pigweed's root gen directory. This is *not* root_gen_dir in
177      # external repositories depending on Pigweed.
178      "$target_gen_dir/..",
179    ]
180    visibility = [ ":*" ]
181  }
182
183  emboss_cc_library("emboss_att") {
184    public_configs = [ ":emboss_include_path" ]
185    source = "public/pw_bluetooth/att.emb"
186    imports = [
187      "public/pw_bluetooth/hci_data.emb",
188      "public/pw_bluetooth/l2cap_frames.emb",
189    ]
190    import_dirs = [ "public" ]
191    deps = [
192      ":emboss_hci_data",
193      ":emboss_l2cap_frames",
194    ]
195  }
196
197  emboss_cc_library("emboss_hci_android") {
198    public_configs = [ ":emboss_include_path" ]
199    source = "public/pw_bluetooth/hci_android.emb"
200    imports = [ "public/pw_bluetooth/hci_common.emb" ]
201    import_dirs = [ "public" ]
202    deps = [ ":emboss_hci_common" ]
203  }
204
205  emboss_cc_library("emboss_hci_common") {
206    public_configs = [ ":emboss_include_path" ]
207    source = "public/pw_bluetooth/hci_common.emb"
208  }
209
210  emboss_cc_library("emboss_hci_commands") {
211    public_configs = [ ":emboss_include_path" ]
212    source = "public/pw_bluetooth/hci_commands.emb"
213    imports = [ "public/pw_bluetooth/hci_common.emb" ]
214    import_dirs = [ "public" ]
215    deps = [ ":emboss_hci_common" ]
216  }
217
218  emboss_cc_library("emboss_hci_data") {
219    public_configs = [ ":emboss_include_path" ]
220    source = "public/pw_bluetooth/hci_data.emb"
221  }
222
223  emboss_cc_library("emboss_hci_events") {
224    public_configs = [ ":emboss_include_path" ]
225    source = "public/pw_bluetooth/hci_events.emb"
226    imports = [ "public/pw_bluetooth/hci_common.emb" ]
227    import_dirs = [ "public" ]
228    deps = [ ":emboss_hci_common" ]
229  }
230
231  emboss_cc_library("emboss_hci_h4") {
232    public_configs = [ ":emboss_include_path" ]
233    source = "public/pw_bluetooth/hci_h4.emb"
234    imports = [ "public/pw_bluetooth/hci_h4.emb" ]
235    import_dirs = [ "public" ]
236  }
237
238  emboss_cc_library("emboss_hci_test") {
239    public_configs = [ ":emboss_include_path" ]
240    source = "public/pw_bluetooth/hci_test.emb"
241    imports = [ "public/pw_bluetooth/hci_common.emb" ]
242    import_dirs = [ "public" ]
243    deps = [ ":emboss_hci_common" ]
244  }
245
246  emboss_cc_library("emboss_l2cap_frames") {
247    public_configs = [ ":emboss_include_path" ]
248    source = "public/pw_bluetooth/l2cap_frames.emb"
249  }
250
251  emboss_cc_library("emboss_rfcomm_frames") {
252    public_configs = [ ":emboss_include_path" ]
253    source = "public/pw_bluetooth/rfcomm_frames.emb"
254  }
255
256  emboss_cc_library("emboss_snoop") {
257    public_configs = [ ":emboss_include_path" ]
258    source = "public/pw_bluetooth/snoop.emb"
259  }
260
261  group("emboss_hci_group") {
262    public_configs = [ ":emboss_include_path" ]
263    public_deps = [
264      ":emboss_hci_android",
265      ":emboss_hci_commands",
266      ":emboss_hci_common",
267      ":emboss_hci_data",
268      ":emboss_hci_events",
269      ":emboss_hci_h4",
270    ]
271  }
272} else {
273  group("emboss_att") {
274  }
275  group("emboss_hci_android") {
276  }
277  group("emboss_hci_common") {
278  }
279  group("emboss_hci_commands") {
280  }
281  group("emboss_hci_data") {
282  }
283  group("emboss_hci_events") {
284  }
285  group("emboss_hci_h4") {
286  }
287  group("emboss_hci_test") {
288  }
289  group("emboss_hci_group") {
290  }
291  group("emboss_l2cap_frames") {
292  }
293  group("emboss_rfcomm_frames") {
294  }
295}
296
297pw_test_group("tests") {
298  enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != ""
299  tests = [
300    ":address_test",
301    ":api_test",
302    ":api2_test",
303    ":result_test",
304    ":uuid_test",
305    ":emboss_test",
306    ":emboss_util_test",
307    ":snoop_test",
308  ]
309}
310
311pw_test("address_test") {
312  sources = [ "address_test.cc" ]
313  deps = [ ":pw_bluetooth" ]
314}
315
316pw_test("api_test") {
317  sources = [ "api_test.cc" ]
318  deps = [ ":pw_bluetooth" ]
319}
320
321pw_test("emboss_util_test") {
322  enable_if =
323      dir_pw_third_party_emboss != "" && pw_chrono_SYSTEM_CLOCK_BACKEND != ""
324  sources = [ "emboss_util_test.cc" ]
325  include_dirs = [ "." ]
326  deps = [
327    ":emboss_hci_test",
328    ":emboss_util",
329  ]
330}
331
332pw_test("api2_test") {
333  enable_if = pw_async2_DISPATCHER_BACKEND != ""
334  sources = [ "api2_test.cc" ]
335  deps = [ ":pw_bluetooth2" ]
336}
337
338pw_test("result_test") {
339  sources = [ "result_test.cc" ]
340  deps = [ ":pw_bluetooth" ]
341}
342
343pw_test("uuid_test") {
344  sources = [ "uuid_test.cc" ]
345  deps = [ ":pw_bluetooth" ]
346}
347
348pw_test("emboss_test") {
349  enable_if = dir_pw_third_party_emboss != ""
350  sources = [ "emboss_test.cc" ]
351  deps = [
352    # All emboss targets are listed (even if they don't have explicit tests) to
353    # ensure they are compiled.
354    ":emboss_att",
355    ":emboss_hci_group",
356    ":emboss_hci_test",
357    ":emboss_l2cap_frames",
358    ":emboss_rfcomm_frames",
359    "$dir_pw_third_party/fuchsia:stdcompat",
360  ]
361}
362
363if (dir_pw_third_party_emboss != "") {
364  pw_size_diff("emboss_size_report") {
365    title = "pw_bluetooth Emboss Size Report"
366    base = "$dir_pw_bloat:bloat_base"
367    binaries = [
368      {
369        target = "size_report:make_view_and_write"
370        label = "Make view and write field"
371      },
372    ]
373  }
374
375  pw_size_diff("emboss_size_report_diff") {
376    title = "pw_bluetooth Emboss Size Report diff"
377    base = "size_report:make_view_and_write"
378    binaries = [
379      {
380        target = "size_report:make_2_views_and_write"
381        label = "Size difference when adding a second view"
382      },
383    ]
384  }
385} else {
386  pw_size_diff("emboss_size_report") {
387    title = "pw_bluetooth Emboss Size Report"
388    base = "$dir_pw_bloat:bloat_base"
389    binaries = [
390      {
391        target = "$dir_pw_bloat:bloat_base"
392        label = "Emboss not configured."
393      },
394    ]
395  }
396
397  pw_size_diff("emboss_size_report_diff") {
398    title = "pw_bluetooth Emboss Size Report diff"
399    base = "$dir_pw_bloat:bloat_base"
400    binaries = [
401      {
402        target = "$dir_pw_bloat:bloat_base"
403        label = "Emboss not configured."
404      },
405    ]
406  }
407}
408
409pw_test("snoop_test") {
410  enable_if =
411      dir_pw_third_party_emboss != "" && pw_chrono_SYSTEM_CLOCK_BACKEND != ""
412  sources = [ "snoop_test.cc" ]
413  include_dirs = [ "." ]
414  deps = [
415    ":snoop",
416    "$dir_pw_chrono:simulated_system_clock",
417  ]
418}
419