xref: /aosp_15_r20/external/pigweed/pw_span/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2020 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_pw_build/module_config.gni")
18import("$dir_pw_build/target_types.gni")
19import("$dir_pw_docgen/docs.gni")
20import("$dir_pw_toolchain/traits.gni")
21import("$dir_pw_unit_test/test.gni")
22
23declare_args() {
24  # Whether or not to enable bounds-checking asserts in pw::span. Enabling this
25  # may significantly increase binary size, and can introduce dependency cycles
26  # if your pw_assert backend's headers depends directly or indirectly on
27  # pw_span. It's recommended to enable this for debug builds if possible.
28  pw_span_ENABLE_ASSERTS = false
29
30  # The build target that overrides the default configuration options for this
31  # module. This should point to a source set that provides defines through a
32  # public config (which may -include a file or add defines directly).
33  #
34  # Most modules depend on pw_build_DEFAULT_MODULE_CONFIG as the default config,
35  # but since this module's config options require interaction with the build
36  # system, this defaults to an internal config to properly support
37  # pw_span_ENABLE_ASSERTS.
38  pw_span_CONFIG = "$dir_pw_span:span_asserts"
39}
40
41config("public_include_path") {
42  include_dirs = [ "public" ]
43  visibility = [ ":*" ]
44}
45
46pw_source_set("config") {
47  public = [ "public/pw_span/internal/config.h" ]
48  public_configs = [ ":public_include_path" ]
49  public_deps = [ pw_span_CONFIG ]
50  remove_public_deps = [ "*" ]
51  visibility = [ ":*" ]
52}
53
54config("public_config") {
55  include_dirs = [ "public" ]
56  visibility = [ ":*" ]
57}
58
59config("span_asserts_config") {
60  defines = [ "PW_SPAN_ENABLE_ASSERTS=${pw_span_ENABLE_ASSERTS}" ]
61  visibility = [ ":span_asserts" ]
62}
63
64pw_source_set("span_asserts") {
65  public_configs = [ ":span_asserts_config" ]
66  visibility = [ ":config" ]
67}
68
69# Provides "pw_span/span.h" and pw::span.
70pw_source_set("pw_span") {
71  public_configs = [ ":public_config" ]
72  public = [ "public/pw_span/span.h" ]
73  public_deps = [ ":config" ]
74
75  # Polyfill <cstddef> (std::byte) and <iterator> (std::size(), std::data) if
76  # C++17 is not supported.
77  if (pw_toolchain_CXX_STANDARD < pw_toolchain_STANDARD.CXX17) {
78    public_deps += [
79      "$dir_pw_polyfill:cstddef",
80      "$dir_pw_polyfill:iterator",
81    ]
82  }
83
84  # Only add a dependency on pw_assert if the flag is explicitly enabled.
85  if (pw_span_ENABLE_ASSERTS) {
86    public_deps += [ "$dir_pw_assert:assert" ]
87  }
88
89  sources = [ "public/pw_span/internal/span_impl.h" ]
90}
91
92pw_test_group("tests") {
93  tests = [
94    ":pw_span_test",
95    ":compatibility_test",
96  ]
97}
98
99pw_test("pw_span_test") {
100  deps = [
101    ":pw_span",
102    dir_pw_polyfill,
103  ]
104  remove_configs = [ "$dir_pw_build:extra_strict_warnings" ]
105  sources = [ "span_test.cc" ]
106}
107
108pw_test("compatibility_test") {
109  deps = [
110    ":pw_span",
111    dir_pw_polyfill,
112  ]
113  sources = [ "compatibility_test.cc" ]
114}
115
116pw_doc_group("docs") {
117  inputs = [ "Kconfig" ]
118  sources = [ "docs.rst" ]
119}
120