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