• 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_function/function.gni")
22import("$dir_pw_unit_test/test.gni")
23
24config("public_include_path") {
25  include_dirs = [ "public" ]
26  visibility = [ ":*" ]
27}
28
29pw_source_set("config") {
30  public = [ "public/pw_function/config.h" ]
31  public_configs = [ ":public_include_path" ]
32  public_deps = [
33    "$dir_pw_third_party/fuchsia:fit",
34    pw_function_CONFIG,
35  ]
36  visibility = [ ":*" ]
37}
38
39pw_source_set("pw_function") {
40  public_configs = [ ":public_include_path" ]
41  public_deps = [
42    ":config",
43    "$dir_pw_third_party/fuchsia:fit",
44    dir_pw_assert,
45    dir_pw_preprocessor,
46  ]
47  public = [ "public/pw_function/function.h" ]
48}
49
50config("enable_dynamic_allocation_config") {
51  defines = [ "PW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION=1" ]
52  visibility = [ ":*" ]
53}
54
55# Use this for pw_function_CONFIG to enable dynamic allocation.
56pw_source_set("enable_dynamic_allocation") {
57  public_configs = [ ":enable_dynamic_allocation_config" ]
58}
59
60pw_source_set("pointer") {
61  public_configs = [ ":public_include_path" ]
62  public = [ "public/pw_function/pointer.h" ]
63  sources = [ "public/pw_function/internal/static_invoker.h" ]
64}
65
66pw_source_set("scope_guard") {
67  public_configs = [ ":public_include_path" ]
68  public = [ "public/pw_function/scope_guard.h" ]
69}
70
71pw_doc_group("docs") {
72  inputs = [
73    "Kconfig",
74    "function_test.cc",
75  ]
76  sources = [ "docs.rst" ]
77  report_deps = [
78    ":callable_size",
79    ":function_size",
80  ]
81}
82
83pw_test_group("tests") {
84  tests = [
85    ":function_test",
86    ":pointer_test",
87    ":scope_guard_test",
88    "$dir_pw_third_party/fuchsia:function_tests",
89  ]
90}
91
92pw_test("function_test") {
93  deps = [
94    ":pw_function",
95    dir_pw_polyfill,
96  ]
97  sources = [ "function_test.cc" ]
98  negative_compilation_tests = true
99}
100
101pw_test("pointer_test") {
102  deps = [
103    ":pointer",
104    ":pw_function",
105  ]
106  sources = [ "pointer_test.cc" ]
107}
108
109pw_test("scope_guard_test") {
110  sources = [ "scope_guard_test.cc" ]
111  deps = [
112    ":pw_function",
113    ":scope_guard",
114  ]
115}
116
117pw_size_diff("function_size") {
118  title = "Pigweed function size report"
119
120  binaries = [
121    {
122      target = "size_report:basic_function"
123      base = "size_report:pointer_base"
124      label = "Simple pw::Function vs. function pointer"
125    },
126  ]
127}
128
129pw_size_diff("callable_size") {
130  title = "Size comparison of callable objects"
131
132  binaries = [
133    {
134      target = "size_report:callable_size_function_pointer"
135      base = "size_report:callable_size_base"
136      label = "Function pointer"
137    },
138    {
139      target = "size_report:callable_size_static_lambda"
140      base = "size_report:callable_size_base"
141      label = "Static lambda (operator+)"
142    },
143    {
144      target = "size_report:callable_size_simple_lambda"
145      base = "size_report:callable_size_base"
146      label = "Non-capturing lambda"
147    },
148    {
149      target = "size_report:callable_size_capturing_lambda"
150      base = "size_report:callable_size_base"
151      label = "Simple capturing lambda"
152    },
153    {
154      target = "size_report:callable_size_multi_capturing_lambda"
155      base = "size_report:callable_size_base"
156      label = "Multi-argument capturing lambda"
157    },
158    {
159      target = "size_report:callable_size_custom_class"
160      base = "size_report:callable_size_base"
161      label = "Custom class"
162    },
163  ]
164}
165