Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / lwip / lwip.gni
1 # Copyright (c) 2020 Project CHIP Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://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,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import("//build_overrides/lwip.gni")
16
17 declare_args() {
18   # Default enablement for lwIP library components.
19   # This has no effect on its own; it only changes between opt-out and opt-in.
20   lwip_default = current_os != "freertos"
21 }
22
23 declare_args() {
24   # Build IPv4 support in lwIP.
25   lwip_ipv4 = lwip_default
26
27   # Enable IPv6 support in lwIP.
28   lwip_ipv6 = lwip_default
29
30   # Enable sequential & socket API support in lwIP.
31   lwip_api = lwip_default
32
33   # Enable ethernet support in lwIP.
34   lwip_ethernet = lwip_default
35
36   # Enable SLIP interface support in lwIP.
37   lwip_slip = false
38
39   # Enable 6LoWPAN support in lwIP.
40   lwip_6lowpan = lwip_default
41
42   # Enable PPP support in lwIP.
43   lwip_ppp = lwip_default
44
45   # Default enablement for lwIP application components.
46   # This has no effect on its own; it only changes between opt-out and opt-in.
47   lwip_apps_default = false
48 }
49
50 declare_args() {
51   # Enable SNMPv2c agent application.
52   lwip_snmp = lwip_apps_default
53
54   # Enable HTTP server.
55   lwip_httpd = lwip_apps_default
56
57   # Enable IPERF server.
58   lwip_iperf = lwip_apps_default
59
60   # Enable SNTP client.
61   lwip_sntp = lwip_apps_default
62
63   # Enable MDNS responder.
64   lwip_mdns = lwip_apps_default
65
66   # Enable NetBIOS name server.
67   lwip_netbiosns = lwip_apps_default
68
69   # Enable TFTP server.
70   lwip_tftp = lwip_apps_default
71
72   # Enable MQTT client.
73   lwip_mqtt = lwip_apps_default
74 }
75
76 # Defines a lwIP build target.
77 #
78 # lwIP depends on external header files to compile. This template defines
79 # a combined build of the lwIP sources plus target configuration.
80 template("lwip_target") {
81   _lwip_root = "${lwip_root}/repo/lwip"
82
83   lwip_target_name = target_name
84
85   config("${lwip_target_name}_warnings") {
86     cflags = [
87       "-Wno-address",
88       "-Wno-format",
89       "-Wno-type-limits",
90       "-Wno-unused-variable",
91       "-Wno-maybe-uninitialized",
92     ]
93   }
94
95   config("${lwip_target_name}_base_config") {
96     include_dirs = [
97       "${lwip_root}/repo/lwip/src/include",
98       "include",
99     ]
100
101     # These options may have overlap with lwipopts.h, however this is harmless
102     # as long the options are the same and if they are not the same it's a
103     # compile error.
104     if (lwip_ipv4) {
105       enable_ipv4 = 1
106     } else {
107       enable_ipv4 = 0
108     }
109     if (lwip_ipv6) {
110       enable_ipv6 = 1
111     } else {
112       enable_ipv6 = 0
113     }
114     if (lwip_api) {
115       enable_api = 1
116     } else {
117       enable_api = 0
118     }
119     if (lwip_ethernet) {
120       enable_ethernet = 1
121     } else {
122       enable_ethernet = 0
123     }
124     if (lwip_slip) {
125       enable_slip = 1
126     } else {
127       enable_slip = 0
128     }
129     if (lwip_6lowpan) {
130       enable_6lowpan = 1
131     } else {
132       enable_6lowpan = 0
133     }
134     if (lwip_ppp) {
135       enable_ppp = 1
136     } else {
137       enable_ppp = 0
138     }
139     defines = [
140       "LWIP_IPV4=${enable_ipv4}",
141       "LWIP_IPV6=${enable_ipv6}",
142       "LWIP_API=${enable_api}",
143       "LWIP_ETHERNET=${enable_ethernet}",
144       "LWIP_SLIP=${enable_slip}",
145       "LWIP_6LOWPAN=${enable_6lowpan}",
146       "LWIP_PPP=${enable_ppp}",
147     ]
148   }
149
150   source_set(lwip_target_name) {
151     forward_variables_from(invoker,
152                            [
153                              "sources",
154                              "public",
155                              "public_configs",
156                              "public_deps",
157                            ])
158
159     # lwIP headers become empty if the relevant feature is disabled, so the
160     # whole interface can be public regardless of build options.
161     public += [
162       "${_lwip_root}/src/include/lwip/api.h",
163       "${_lwip_root}/src/include/lwip/autoip.h",
164       "${_lwip_root}/src/include/lwip/debug.h",
165       "${_lwip_root}/src/include/lwip/def.h",
166       "${_lwip_root}/src/include/lwip/dhcp.h",
167       "${_lwip_root}/src/include/lwip/dhcp6.h",
168       "${_lwip_root}/src/include/lwip/dns.h",
169       "${_lwip_root}/src/include/lwip/err.h",
170       "${_lwip_root}/src/include/lwip/etharp.h",
171       "${_lwip_root}/src/include/lwip/ethip6.h",
172       "${_lwip_root}/src/include/lwip/icmp.h",
173       "${_lwip_root}/src/include/lwip/icmp6.h",
174       "${_lwip_root}/src/include/lwip/if.h",
175       "${_lwip_root}/src/include/lwip/igmp.h",
176       "${_lwip_root}/src/include/lwip/inet.h",
177       "${_lwip_root}/src/include/lwip/inet_chksum.h",
178       "${_lwip_root}/src/include/lwip/init.h",
179       "${_lwip_root}/src/include/lwip/ip.h",
180       "${_lwip_root}/src/include/lwip/ip4_frag.h",
181       "${_lwip_root}/src/include/lwip/ip6.h",
182       "${_lwip_root}/src/include/lwip/ip6_addr.h",
183       "${_lwip_root}/src/include/lwip/ip6_frag.h",
184       "${_lwip_root}/src/include/lwip/ip6_route_table.h",
185       "${_lwip_root}/src/include/lwip/ip_addr.h",
186       "${_lwip_root}/src/include/lwip/mem.h",
187       "${_lwip_root}/src/include/lwip/memp.h",
188       "${_lwip_root}/src/include/lwip/mld6.h",
189       "${_lwip_root}/src/include/lwip/nd6.h",
190       "${_lwip_root}/src/include/lwip/netbuf.h",
191       "${_lwip_root}/src/include/lwip/netdb.h",
192       "${_lwip_root}/src/include/lwip/netif.h",
193       "${_lwip_root}/src/include/lwip/netifapi.h",
194       "${_lwip_root}/src/include/lwip/opt.h",
195       "${_lwip_root}/src/include/lwip/pbuf.h",
196       "${_lwip_root}/src/include/lwip/priv/tcp_priv.h",
197       "${_lwip_root}/src/include/lwip/priv/tcpip_priv.h",
198       "${_lwip_root}/src/include/lwip/prot/autoip.h",
199       "${_lwip_root}/src/include/lwip/prot/dhcp.h",
200       "${_lwip_root}/src/include/lwip/prot/dns.h",
201       "${_lwip_root}/src/include/lwip/prot/ethernet.h",
202       "${_lwip_root}/src/include/lwip/prot/icmp6.h",
203       "${_lwip_root}/src/include/lwip/prot/igmp.h",
204       "${_lwip_root}/src/include/lwip/prot/mld6.h",
205       "${_lwip_root}/src/include/lwip/prot/nd6.h",
206       "${_lwip_root}/src/include/lwip/raw.h",
207       "${_lwip_root}/src/include/lwip/snmp.h",
208       "${_lwip_root}/src/include/lwip/sockets.h",
209       "${_lwip_root}/src/include/lwip/stats.h",
210       "${_lwip_root}/src/include/lwip/sys.h",
211       "${_lwip_root}/src/include/lwip/tcp.h",
212       "${_lwip_root}/src/include/lwip/tcpip.h",
213       "${_lwip_root}/src/include/lwip/timeouts.h",
214       "${_lwip_root}/src/include/lwip/udp.h",
215     ]
216
217     sources += [
218       "${_lwip_root}/src/core/def.c",
219       "${_lwip_root}/src/core/dns.c",
220       "${_lwip_root}/src/core/inet_chksum.c",
221       "${_lwip_root}/src/core/init.c",
222       "${_lwip_root}/src/core/ip.c",
223       "${_lwip_root}/src/core/mem.c",
224       "${_lwip_root}/src/core/memp.c",
225       "${_lwip_root}/src/core/netif.c",
226       "${_lwip_root}/src/core/pbuf.c",
227       "${_lwip_root}/src/core/raw.c",
228       "${_lwip_root}/src/core/stats.c",
229       "${_lwip_root}/src/core/sys.c",
230       "${_lwip_root}/src/core/tcp.c",
231       "${_lwip_root}/src/core/tcp_in.c",
232       "${_lwip_root}/src/core/tcp_out.c",
233       "${_lwip_root}/src/core/timeouts.c",
234       "${_lwip_root}/src/core/udp.c",
235       "${_lwip_root}/src/include/lwip/priv/api_msg.h",
236       "${_lwip_root}/src/include/lwip/priv/memp_std.h",
237       "${_lwip_root}/src/include/lwip/priv/nd6_priv.h",
238     ]
239
240     if (lwip_ipv4) {
241       sources += [
242         "${_lwip_root}/src/core/ipv4/autoip.c",
243         "${_lwip_root}/src/core/ipv4/dhcp.c",
244         "${_lwip_root}/src/core/ipv4/etharp.c",
245         "${_lwip_root}/src/core/ipv4/icmp.c",
246         "${_lwip_root}/src/core/ipv4/igmp.c",
247         "${_lwip_root}/src/core/ipv4/ip4.c",
248         "${_lwip_root}/src/core/ipv4/ip4_addr.c",
249         "${_lwip_root}/src/core/ipv4/ip4_frag.c",
250       ]
251     }
252
253     if (lwip_ipv6) {
254       sources += [
255         "${_lwip_root}/src/core/ipv6/dhcp6.c",
256         "${_lwip_root}/src/core/ipv6/ethip6.c",
257         "${_lwip_root}/src/core/ipv6/icmp6.c",
258         "${_lwip_root}/src/core/ipv6/inet6.c",
259         "${_lwip_root}/src/core/ipv6/ip6.c",
260         "${_lwip_root}/src/core/ipv6/ip6_addr.c",
261         "${_lwip_root}/src/core/ipv6/ip6_frag.c",
262         "${_lwip_root}/src/core/ipv6/ip6_route_table.c",
263         "${_lwip_root}/src/core/ipv6/mld6.c",
264         "${_lwip_root}/src/core/ipv6/nd6.c",
265       ]
266     }
267
268     if (lwip_api) {
269       sources += [
270         "${_lwip_root}/src/api/api_lib.c",
271         "${_lwip_root}/src/api/api_msg.c",
272         "${_lwip_root}/src/api/err.c",
273         "${_lwip_root}/src/api/if.c",
274         "${_lwip_root}/src/api/netbuf.c",
275         "${_lwip_root}/src/api/netdb.c",
276         "${_lwip_root}/src/api/netifapi.c",
277         "${_lwip_root}/src/api/sockets.c",
278         "${_lwip_root}/src/api/tcpip.c",
279       ]
280     }
281
282     if (lwip_ethernet) {
283       sources += [ "${_lwip_root}/src/netif/ethernet.c" ]
284     }
285
286     if (lwip_slip) {
287       sources += [ "${_lwip_root}/src/netif/slipif.c" ]
288     }
289
290     if (lwip_6lowpan) {
291       sources += [ "${_lwip_root}/src/netif/lowpan6.c" ]
292     }
293
294     # Relax warnings for third_party code.
295     configs += [ ":${lwip_target_name}_warnings" ]
296
297     public_configs += [ ":${lwip_target_name}_base_config" ]
298   }
299
300   lwip_apps = []
301
302   template("lwip_app") {
303     app_name = target_name
304
305     static_library("${lwip_target_name}_${app_name}") {
306       forward_variables_from(invoker, [ "sources" ])
307
308       deps = [ ":lwip" ]
309
310       # Relax warnings for third_party code.
311       configs += [ ":${lwip_target_name}_warnings" ]
312     }
313   }
314
315   if (lwip_snmp) {
316     lwip_app("snmp") {
317       sources = [
318         "${_lwip_root}/src/apps/snmp/snmp_asn1.c",
319         "${_lwip_root}/src/apps/snmp/snmp_core.c",
320         "${_lwip_root}/src/apps/snmp/snmp_mib2.c",
321         "${_lwip_root}/src/apps/snmp/snmp_mib2_icmp.c",
322         "${_lwip_root}/src/apps/snmp/snmp_mib2_interfaces.c",
323         "${_lwip_root}/src/apps/snmp/snmp_mib2_ip.c",
324         "${_lwip_root}/src/apps/snmp/snmp_mib2_snmp.c",
325         "${_lwip_root}/src/apps/snmp/snmp_mib2_system.c",
326         "${_lwip_root}/src/apps/snmp/snmp_mib2_tcp.c",
327         "${_lwip_root}/src/apps/snmp/snmp_mib2_udp.c",
328         "${_lwip_root}/src/apps/snmp/snmp_msg.c",
329         "${_lwip_root}/src/apps/snmp/snmp_netconn.c",
330         "${_lwip_root}/src/apps/snmp/snmp_pbuf_stream.c",
331         "${_lwip_root}/src/apps/snmp/snmp_raw.c",
332         "${_lwip_root}/src/apps/snmp/snmp_scalar.c",
333         "${_lwip_root}/src/apps/snmp/snmp_table.c",
334         "${_lwip_root}/src/apps/snmp/snmp_threadsync.c",
335         "${_lwip_root}/src/apps/snmp/snmp_traps.c",
336         "${_lwip_root}/src/apps/snmp/snmpv3.c",
337         "${_lwip_root}/src/apps/snmp/snmpv3_dummy.c",
338         "${_lwip_root}/src/apps/snmp/snmpv3_mbedtls.c",
339       ]
340     }
341
342     lwip_apps += [ ":${lwip_target_name}_snmp" ]
343   }
344
345   if (lwip_httpd) {
346     lwip_app("httpd") {
347       sources = [
348         "${_lwip_root}/src/apps/httpd/fs.c",
349         "${_lwip_root}/src/apps/httpd/httpd.c",
350       ]
351     }
352
353     lwip_apps += [ ":${lwip_target_name}_httpd" ]
354   }
355
356   if (lwip_iperf) {
357     lwip_app("lwiperf") {
358       sources = [ "${_lwip_root}/src/apps/lwiperf/lwiperf.c" ]
359     }
360
361     lwip_apps += [ ":${lwip_target_name}_lwiperf" ]
362   }
363
364   if (lwip_sntp) {
365     lwip_app("sntp") {
366       sources = [ "${_lwip_root}/src/apps/sntp/sntp.c" ]
367     }
368
369     lwip_apps += [ ":${lwip_target_name}_sntp" ]
370   }
371
372   if (lwip_mdns) {
373     lwip_app("mdns") {
374       sources = [ "${_lwip_root}/src/apps/mdns/mdns.c" ]
375     }
376
377     lwip_apps += [ ":${lwip_target_name}_mdns" ]
378   }
379
380   if (lwip_netbiosns) {
381     lwip_app("netbiosns") {
382       sources = [ "${_lwip_root}/src/apps/netbiosns/netbiosns.c" ]
383     }
384
385     lwip_apps += [ ":${lwip_target_name}_netbiosns" ]
386   }
387
388   if (lwip_tftp) {
389     lwip_app("tftp") {
390       sources = [ "${_lwip_root}/src/apps/tftp/tftp_server.c" ]
391     }
392
393     lwip_apps += [ ":${lwip_target_name}_tftp" ]
394   }
395
396   if (lwip_mqtt) {
397     lwip_app("mqtt") {
398       sources = [ "${_lwip_root}/src/apps/mqtt/mqtt.c" ]
399     }
400
401     lwip_apps += [ ":${lwip_target_name}_mqtt" ]
402   }
403
404   group("${lwip_target_name}_apps") {
405     deps = lwip_apps
406   }
407
408   group("${lwip_target_name}_all") {
409     deps = [
410       ":${lwip_target_name}",
411       ":${lwip_target_name}_apps",
412     ]
413   }
414 }