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