• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 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_bloat/bloat.gni")
18import("$dir_pw_build/module_config.gni")
19import("$dir_pw_build/target_types.gni")
20import("$dir_pw_docgen/docs.gni")
21import("$dir_pw_unit_test/test.gni")
22
23declare_args() {
24  # The build target that overrides the default configuration options for this
25  # module. This should point to a source set that provides defines through a
26  # public config (which may -include a file or add defines directly).
27  pw_function_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
28}
29
30config("public_include_path") {
31  include_dirs = [ "public" ]
32  visibility = [ ":*" ]
33}
34
35pw_source_set("config") {
36  public = [ "public/pw_function/config.h" ]
37  public_configs = [ ":public_include_path" ]
38  public_deps = [ pw_function_CONFIG ]
39  visibility = [ ":*" ]
40}
41
42pw_source_set("pw_function") {
43  public_configs = [ ":public_include_path" ]
44  public_deps = [
45    ":config",
46    "$dir_pw_third_party/fuchsia:fit",
47    dir_pw_assert,
48    dir_pw_preprocessor,
49  ]
50  public = [ "public/pw_function/function.h" ]
51}
52
53pw_source_set("pointer") {
54  public_configs = [ ":public_include_path" ]
55  public = [ "public/pw_function/pointer.h" ]
56  sources = [ "public/pw_function/internal/static_invoker.h" ]
57}
58
59pw_source_set("scope_guard") {
60  public_configs = [ ":public_include_path" ]
61  public = [ "public/pw_function/scope_guard.h" ]
62}
63
64pw_doc_group("docs") {
65  sources = [ "docs.rst" ]
66  report_deps = [
67    ":callable_size",
68    ":function_size",
69  ]
70}
71
72pw_test_group("tests") {
73  tests = [
74    ":function_test",
75    ":pointer_test",
76    ":scope_guard_test",
77    "$dir_pw_third_party/fuchsia:function_tests",
78  ]
79}
80
81pw_test("function_test") {
82  deps = [
83    ":pw_function",
84    dir_pw_polyfill,
85  ]
86  sources = [ "function_test.cc" ]
87  negative_compilation_tests = true
88}
89
90pw_test("pointer_test") {
91  deps = [
92    ":pointer",
93    ":pw_function",
94  ]
95  sources = [ "pointer_test.cc" ]
96}
97
98pw_test("scope_guard_test") {
99  sources = [ "scope_guard_test.cc" ]
100  deps = [
101    ":pw_function",
102    ":scope_guard",
103  ]
104}
105
106pw_size_diff("function_size") {
107  title = "Pigweed function size report"
108
109  binaries = [
110    {
111      target = "size_report:basic_function"
112      base = "size_report:pointer_base"
113      label = "Simple pw::Function vs. function pointer"
114    },
115  ]
116}
117
118pw_size_diff("callable_size") {
119  title = "Size comparison of callable objects"
120
121  binaries = [
122    {
123      target = "size_report:callable_size_function_pointer"
124      base = "size_report:callable_size_base"
125      label = "Function pointer"
126    },
127    {
128      target = "size_report:callable_size_static_lambda"
129      base = "size_report:callable_size_base"
130      label = "Static lambda (operator+)"
131    },
132    {
133      target = "size_report:callable_size_simple_lambda"
134      base = "size_report:callable_size_base"
135      label = "Non-capturing lambda"
136    },
137    {
138      target = "size_report:callable_size_capturing_lambda"
139      base = "size_report:callable_size_base"
140      label = "Simple capturing lambda"
141    },
142    {
143      target = "size_report:callable_size_multi_capturing_lambda"
144      base = "size_report:callable_size_base"
145      label = "Multi-argument capturing lambda"
146    },
147    {
148      target = "size_report:callable_size_custom_class"
149      base = "size_report:callable_size_base"
150      label = "Custom class"
151    },
152  ]
153}
154