1 # Copyright 2020 The Pigweed Authors
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
7 # https://www.apache.org/licenses/LICENSE-2.0
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
15 import("//build_overrides/pigweed.gni")
18 # The name of the GN target type used to build Pigweed executables.
20 # If this is a custom template, the .gni file containing the template must
21 # be imported at the top of the target configuration file to make it globally
23 pw_build_EXECUTABLE_TARGET_TYPE = "executable"
25 # The path to the .gni file that defines pw_build_EXECUTABLE_TARGET_TYPE.
27 # If pw_build_EXECUTABLE_TARGET_TYPE is not the default of `executable`, this
28 # .gni file is imported to provide the template definition.
29 pw_build_EXECUTABLE_TARGET_TYPE_FILE = ""
32 if (pw_build_EXECUTABLE_TARGET_TYPE != "executable" &&
33 pw_build_EXECUTABLE_TARGET_TYPE_FILE != "") {
34 import(pw_build_EXECUTABLE_TARGET_TYPE_FILE)
37 # TODO(frolv): The code in all of the templates below is duplicated, with the
38 # exception of the target type. This file could be auto-generated with Python.
40 _supported_toolchain_defaults = [
45 template("pw_source_set") {
46 source_set(target_name) {
47 import("$dir_pw_build/defaults.gni")
48 forward_variables_from(invoker, "*", _supported_toolchain_defaults)
50 if (!defined(configs)) {
53 if (defined(pw_build_defaults.configs)) {
54 configs += pw_build_defaults.configs
56 if (defined(remove_configs)) {
57 if (remove_configs != [] && remove_configs[0] == "*") {
60 configs += remove_configs # Add configs in case they aren't already
61 configs -= remove_configs # present, then remove them.
64 if (defined(invoker.configs)) {
65 configs += invoker.configs
68 if (defined(pw_build_defaults.public_deps)) {
69 public_deps = pw_build_defaults.public_deps
73 if (defined(remove_public_deps)) {
74 if (remove_public_deps != [] && remove_public_deps[0] == "*") {
77 public_deps += remove_public_deps
78 public_deps -= remove_public_deps
81 if (defined(invoker.public_deps)) {
82 public_deps += invoker.public_deps
87 template("pw_static_library") {
88 _library_output_dir = "${target_out_dir}/lib"
89 if (defined(invoker.output_dir)) {
90 _library_output_dir = invoker.output_dir
93 static_library(target_name) {
94 import("$dir_pw_build/defaults.gni")
95 forward_variables_from(invoker, "*", _supported_toolchain_defaults)
97 if (!defined(configs)) {
100 if (defined(pw_build_defaults.configs)) {
101 configs += pw_build_defaults.configs
103 if (defined(remove_configs)) {
104 if (remove_configs != [] && remove_configs[0] == "*") {
107 configs += remove_configs # Add configs in case they aren't already
108 configs -= remove_configs # present, then remove them.
111 if (defined(invoker.configs)) {
112 configs += invoker.configs
115 if (defined(pw_build_defaults.public_deps)) {
116 public_deps = pw_build_defaults.public_deps
120 if (defined(remove_public_deps)) {
121 if (remove_public_deps != [] && remove_public_deps[0] == "*") {
124 public_deps += remove_public_deps
125 public_deps -= remove_public_deps
128 if (defined(invoker.public_deps)) {
129 public_deps += invoker.public_deps
132 output_dir = _library_output_dir
136 template("pw_shared_library") {
137 _library_output_dir = "${target_out_dir}/lib"
138 if (defined(invoker.output_dir)) {
139 _library_output_dir = invoker.output_dir
142 shared_library(target_name) {
143 import("$dir_pw_build/defaults.gni")
144 forward_variables_from(invoker, "*", _supported_toolchain_defaults)
146 if (!defined(configs)) {
149 if (defined(pw_build_defaults.configs)) {
150 configs += pw_build_defaults.configs
152 if (defined(remove_configs)) {
153 if (remove_configs != [] && remove_configs[0] == "*") {
156 configs += remove_configs # Add configs in case they aren't already
157 configs -= remove_configs # present, then remove them.
160 if (defined(invoker.configs)) {
161 configs += invoker.configs
164 if (defined(pw_build_defaults.public_deps)) {
165 public_deps = pw_build_defaults.public_deps
169 if (defined(remove_public_deps)) {
170 if (remove_public_deps != [] && remove_public_deps[0] == "*") {
173 public_deps += remove_public_deps
174 public_deps -= remove_public_deps
177 if (defined(invoker.public_deps)) {
178 public_deps += invoker.public_deps
181 output_dir = _library_output_dir
185 # Wrapper for Pigweed executable build targets which uses a globally-defined,
186 # configurable target type.
187 template("pw_executable") {
188 _executable_output_dir = "${target_out_dir}/bin"
189 if (defined(invoker.output_dir)) {
190 _executable_output_dir = invoker.output_dir
193 target(pw_build_EXECUTABLE_TARGET_TYPE, target_name) {
194 import("$dir_pw_build/defaults.gni")
196 forward_variables_from(invoker, "*", _supported_toolchain_defaults)
198 if (!defined(configs)) {
201 if (defined(pw_build_defaults.configs)) {
202 configs += pw_build_defaults.configs
204 if (defined(remove_configs)) {
205 if (remove_configs != [] && remove_configs[0] == "*") {
208 configs += remove_configs # Add configs in case they aren't already
209 configs -= remove_configs # present, then remove them.
212 if (defined(invoker.configs)) {
213 configs += invoker.configs
216 if (defined(pw_build_defaults.public_deps)) {
217 public_deps = pw_build_defaults.public_deps
221 if (defined(remove_public_deps)) {
222 if (remove_public_deps != [] && remove_public_deps[0] == "*") {
225 public_deps += remove_public_deps
226 public_deps -= remove_public_deps
229 if (defined(invoker.public_deps)) {
230 public_deps += invoker.public_deps
233 output_dir = _executable_output_dir