Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_build / target_types.gni
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
15 import("//build_overrides/pigweed.gni")
16
17 declare_args() {
18   # The name of the GN target type used to build Pigweed executables.
19   #
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
22   # available.
23   pw_build_EXECUTABLE_TARGET_TYPE = "executable"
24
25   # The path to the .gni file that defines pw_build_EXECUTABLE_TARGET_TYPE.
26   #
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 = ""
30 }
31
32 if (pw_build_EXECUTABLE_TARGET_TYPE != "executable" &&
33     pw_build_EXECUTABLE_TARGET_TYPE_FILE != "") {
34   import(pw_build_EXECUTABLE_TARGET_TYPE_FILE)
35 }
36
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.
39
40 _supported_toolchain_defaults = [
41   "configs",
42   "public_deps",
43 ]
44
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)
49
50     if (!defined(configs)) {
51       configs = []
52     }
53     if (defined(pw_build_defaults.configs)) {
54       configs += pw_build_defaults.configs
55     }
56     if (defined(remove_configs)) {
57       if (remove_configs != [] && remove_configs[0] == "*") {
58         configs = []
59       } else {
60         configs += remove_configs  # Add configs in case they aren't already
61         configs -= remove_configs  # present, then remove them.
62       }
63     }
64     if (defined(invoker.configs)) {
65       configs += invoker.configs
66     }
67
68     if (defined(pw_build_defaults.public_deps)) {
69       public_deps = pw_build_defaults.public_deps
70     } else {
71       public_deps = []
72     }
73     if (defined(remove_public_deps)) {
74       if (remove_public_deps != [] && remove_public_deps[0] == "*") {
75         public_deps = []
76       } else {
77         public_deps += remove_public_deps
78         public_deps -= remove_public_deps
79       }
80     }
81     if (defined(invoker.public_deps)) {
82       public_deps += invoker.public_deps
83     }
84   }
85 }
86
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
91   }
92
93   static_library(target_name) {
94     import("$dir_pw_build/defaults.gni")
95     forward_variables_from(invoker, "*", _supported_toolchain_defaults)
96
97     if (!defined(configs)) {
98       configs = []
99     }
100     if (defined(pw_build_defaults.configs)) {
101       configs += pw_build_defaults.configs
102     }
103     if (defined(remove_configs)) {
104       if (remove_configs != [] && remove_configs[0] == "*") {
105         configs = []
106       } else {
107         configs += remove_configs  # Add configs in case they aren't already
108         configs -= remove_configs  # present, then remove them.
109       }
110     }
111     if (defined(invoker.configs)) {
112       configs += invoker.configs
113     }
114
115     if (defined(pw_build_defaults.public_deps)) {
116       public_deps = pw_build_defaults.public_deps
117     } else {
118       public_deps = []
119     }
120     if (defined(remove_public_deps)) {
121       if (remove_public_deps != [] && remove_public_deps[0] == "*") {
122         public_deps = []
123       } else {
124         public_deps += remove_public_deps
125         public_deps -= remove_public_deps
126       }
127     }
128     if (defined(invoker.public_deps)) {
129       public_deps += invoker.public_deps
130     }
131
132     output_dir = _library_output_dir
133   }
134 }
135
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
140   }
141
142   shared_library(target_name) {
143     import("$dir_pw_build/defaults.gni")
144     forward_variables_from(invoker, "*", _supported_toolchain_defaults)
145
146     if (!defined(configs)) {
147       configs = []
148     }
149     if (defined(pw_build_defaults.configs)) {
150       configs += pw_build_defaults.configs
151     }
152     if (defined(remove_configs)) {
153       if (remove_configs != [] && remove_configs[0] == "*") {
154         configs = []
155       } else {
156         configs += remove_configs  # Add configs in case they aren't already
157         configs -= remove_configs  # present, then remove them.
158       }
159     }
160     if (defined(invoker.configs)) {
161       configs += invoker.configs
162     }
163
164     if (defined(pw_build_defaults.public_deps)) {
165       public_deps = pw_build_defaults.public_deps
166     } else {
167       public_deps = []
168     }
169     if (defined(remove_public_deps)) {
170       if (remove_public_deps != [] && remove_public_deps[0] == "*") {
171         public_deps = []
172       } else {
173         public_deps += remove_public_deps
174         public_deps -= remove_public_deps
175       }
176     }
177     if (defined(invoker.public_deps)) {
178       public_deps += invoker.public_deps
179     }
180
181     output_dir = _library_output_dir
182   }
183 }
184
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
191   }
192
193   target(pw_build_EXECUTABLE_TARGET_TYPE, target_name) {
194     import("$dir_pw_build/defaults.gni")
195
196     forward_variables_from(invoker, "*", _supported_toolchain_defaults)
197
198     if (!defined(configs)) {
199       configs = []
200     }
201     if (defined(pw_build_defaults.configs)) {
202       configs += pw_build_defaults.configs
203     }
204     if (defined(remove_configs)) {
205       if (remove_configs != [] && remove_configs[0] == "*") {
206         configs = []
207       } else {
208         configs += remove_configs  # Add configs in case they aren't already
209         configs -= remove_configs  # present, then remove them.
210       }
211     }
212     if (defined(invoker.configs)) {
213       configs += invoker.configs
214     }
215
216     if (defined(pw_build_defaults.public_deps)) {
217       public_deps = pw_build_defaults.public_deps
218     } else {
219       public_deps = []
220     }
221     if (defined(remove_public_deps)) {
222       if (remove_public_deps != [] && remove_public_deps[0] == "*") {
223         public_deps = []
224       } else {
225         public_deps += remove_public_deps
226         public_deps -= remove_public_deps
227       }
228     }
229     if (defined(invoker.public_deps)) {
230       public_deps += invoker.public_deps
231     }
232
233     output_dir = _executable_output_dir
234   }
235 }