Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame] | 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 | |
Armando Montanez | fb3d3fb | 2020-06-09 18:12:12 -0700 | [diff] [blame^] | 15 | # gn-format disable |
| 16 | import("//build_overrides/pigweed.gni") |
| 17 | |
| 18 | import("$dir_pigweed/legacy_target.gni") |
| 19 | |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame] | 20 | # TODO(frolv): The code in all of the templates below is duplicated, with the |
| 21 | # exception of the target type. This file could be auto-generated with Python. |
| 22 | |
| 23 | _supported_toolchain_defaults = [ |
| 24 | "configs", |
| 25 | "public_deps", |
| 26 | ] |
| 27 | |
| 28 | template("pw_source_set") { |
| 29 | import("$dir_pw_build/defaults.gni") |
| 30 | |
| 31 | source_set(target_name) { |
| 32 | forward_variables_from(invoker, "*", _supported_toolchain_defaults) |
| 33 | |
| 34 | if (defined(pw_build_defaults.configs)) { |
| 35 | configs = pw_build_defaults.configs |
| 36 | } else { |
| 37 | configs = [] |
| 38 | } |
| 39 | if (defined(remove_configs)) { |
| 40 | if (remove_configs[0] == "*") { |
| 41 | configs = [] |
| 42 | } else { |
| 43 | configs -= remove_configs |
| 44 | } |
| 45 | } |
| 46 | if (defined(invoker.configs)) { |
| 47 | configs += invoker.configs |
| 48 | } |
| 49 | |
| 50 | if (defined(pw_build_defaults.public_deps)) { |
| 51 | public_deps = pw_build_defaults.public_deps |
| 52 | } else { |
| 53 | public_deps = [] |
| 54 | } |
| 55 | if (defined(remove_public_deps)) { |
| 56 | if (remove_public_deps[0] == "*") { |
| 57 | public_deps = [] |
| 58 | } else { |
| 59 | public_deps -= remove_public_deps |
| 60 | } |
| 61 | } |
| 62 | if (defined(invoker.public_deps)) { |
| 63 | public_deps += invoker.public_deps |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | template("pw_static_library") { |
| 69 | import("$dir_pw_build/defaults.gni") |
| 70 | |
| 71 | static_library(target_name) { |
| 72 | forward_variables_from(invoker, "*", _supported_toolchain_defaults) |
| 73 | |
| 74 | if (defined(pw_build_defaults.configs)) { |
| 75 | configs = pw_build_defaults.configs |
| 76 | } else { |
| 77 | configs = [] |
| 78 | } |
| 79 | if (defined(remove_configs)) { |
| 80 | if (remove_configs[0] == "*") { |
| 81 | configs = [] |
| 82 | } else { |
| 83 | configs -= remove_configs |
| 84 | } |
| 85 | } |
| 86 | if (defined(invoker.configs)) { |
| 87 | configs += invoker.configs |
| 88 | } |
| 89 | |
| 90 | if (defined(pw_build_defaults.public_deps)) { |
| 91 | public_deps = pw_build_defaults.public_deps |
| 92 | } else { |
| 93 | public_deps = [] |
| 94 | } |
| 95 | if (defined(remove_public_deps)) { |
| 96 | if (remove_public_deps[0] == "*") { |
| 97 | public_deps = [] |
| 98 | } else { |
| 99 | public_deps -= remove_public_deps |
| 100 | } |
| 101 | } |
| 102 | if (defined(invoker.public_deps)) { |
| 103 | public_deps += invoker.public_deps |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | template("pw_shared_library") { |
| 109 | import("$dir_pw_build/defaults.gni") |
| 110 | |
| 111 | shared_library(target_name) { |
| 112 | forward_variables_from(invoker, "*", _supported_toolchain_defaults) |
| 113 | |
| 114 | if (defined(pw_build_defaults.configs)) { |
| 115 | configs = pw_build_defaults.configs |
| 116 | } else { |
| 117 | configs = [] |
| 118 | } |
| 119 | if (defined(remove_configs)) { |
| 120 | if (remove_configs[0] == "*") { |
| 121 | configs = [] |
| 122 | } else { |
| 123 | configs -= remove_configs |
| 124 | } |
| 125 | } |
| 126 | if (defined(invoker.configs)) { |
| 127 | configs += invoker.configs |
| 128 | } |
| 129 | |
| 130 | if (defined(pw_build_defaults.public_deps)) { |
| 131 | public_deps = pw_build_defaults.public_deps |
| 132 | } else { |
| 133 | public_deps = [] |
| 134 | } |
| 135 | if (defined(remove_public_deps)) { |
| 136 | if (remove_public_deps[0] == "*") { |
| 137 | public_deps = [] |
| 138 | } else { |
| 139 | public_deps -= remove_public_deps |
| 140 | } |
| 141 | } |
| 142 | if (defined(invoker.public_deps)) { |
| 143 | public_deps += invoker.public_deps |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | # Wrapper for Pigweed executable build targets which uses a globally-defined, |
| 149 | # configurable target type. |
| 150 | template("pw_executable") { |
| 151 | import("$dir_pw_build/defaults.gni") |
| 152 | |
| 153 | target(pw_executable_config.target_type, target_name) { |
| 154 | forward_variables_from(invoker, "*", _supported_toolchain_defaults) |
| 155 | |
| 156 | if (defined(pw_build_defaults.configs)) { |
| 157 | configs = pw_build_defaults.configs |
| 158 | } else { |
| 159 | configs = [] |
| 160 | } |
| 161 | if (defined(remove_configs)) { |
| 162 | if (remove_configs[0] == "*") { |
| 163 | configs = [] |
| 164 | } else { |
| 165 | configs -= remove_configs |
| 166 | } |
| 167 | } |
| 168 | if (defined(invoker.configs)) { |
| 169 | configs += invoker.configs |
| 170 | } |
| 171 | |
| 172 | if (defined(pw_build_defaults.public_deps)) { |
| 173 | public_deps = pw_build_defaults.public_deps |
| 174 | } else { |
| 175 | public_deps = [] |
| 176 | } |
| 177 | if (defined(remove_public_deps)) { |
| 178 | if (remove_public_deps[0] == "*") { |
| 179 | public_deps = [] |
| 180 | } else { |
| 181 | public_deps -= remove_public_deps |
| 182 | } |
| 183 | } |
| 184 | if (defined(invoker.public_deps)) { |
| 185 | public_deps += invoker.public_deps |
| 186 | } |
| 187 | } |
| 188 | } |