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 = [ "Kconfig" ] 73 sources = [ "docs.rst" ] 74 report_deps = [ 75 ":callable_size", 76 ":function_size", 77 ] 78} 79 80pw_test_group("tests") { 81 tests = [ 82 ":function_test", 83 ":pointer_test", 84 ":scope_guard_test", 85 "$dir_pw_third_party/fuchsia:function_tests", 86 ] 87} 88 89pw_test("function_test") { 90 deps = [ 91 ":pw_function", 92 dir_pw_polyfill, 93 ] 94 sources = [ "function_test.cc" ] 95 negative_compilation_tests = true 96} 97 98pw_test("pointer_test") { 99 deps = [ 100 ":pointer", 101 ":pw_function", 102 ] 103 sources = [ "pointer_test.cc" ] 104} 105 106pw_test("scope_guard_test") { 107 sources = [ "scope_guard_test.cc" ] 108 deps = [ 109 ":pw_function", 110 ":scope_guard", 111 ] 112} 113 114pw_size_diff("function_size") { 115 title = "Pigweed function size report" 116 117 binaries = [ 118 { 119 target = "size_report:basic_function" 120 base = "size_report:pointer_base" 121 label = "Simple pw::Function vs. function pointer" 122 }, 123 ] 124} 125 126pw_size_diff("callable_size") { 127 title = "Size comparison of callable objects" 128 129 binaries = [ 130 { 131 target = "size_report:callable_size_function_pointer" 132 base = "size_report:callable_size_base" 133 label = "Function pointer" 134 }, 135 { 136 target = "size_report:callable_size_static_lambda" 137 base = "size_report:callable_size_base" 138 label = "Static lambda (operator+)" 139 }, 140 { 141 target = "size_report:callable_size_simple_lambda" 142 base = "size_report:callable_size_base" 143 label = "Non-capturing lambda" 144 }, 145 { 146 target = "size_report:callable_size_capturing_lambda" 147 base = "size_report:callable_size_base" 148 label = "Simple capturing lambda" 149 }, 150 { 151 target = "size_report:callable_size_multi_capturing_lambda" 152 base = "size_report:callable_size_base" 153 label = "Multi-argument capturing lambda" 154 }, 155 { 156 target = "size_report:callable_size_custom_class" 157 base = "size_report:callable_size_base" 158 label = "Custom class" 159 }, 160 ] 161} 162