Skip to content

Commit 684ea0a

Browse files
committed
feat(coap): Add COAP enable macro to make coap not build if application not use coap module
1 parent 9ed7356 commit 684ea0a

File tree

7 files changed

+51
-33
lines changed

7 files changed

+51
-33
lines changed

components/coap/CMakeLists.txt

+33-29
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
1-
set(include_dirs port/include port/include/coap libcoap/include libcoap/include/coap2)
1+
if(CONFIG_ENABLE_COAP)
2+
set(include_dirs port/include port/include/coap libcoap/include libcoap/include/coap2)
23

3-
set(srcs
4-
"libcoap/src/address.c"
5-
"libcoap/src/async.c"
6-
"libcoap/src/block.c"
7-
"libcoap/src/coap_event.c"
8-
"libcoap/src/coap_hashkey.c"
9-
"libcoap/src/coap_session.c"
10-
"libcoap/src/coap_time.c"
11-
"libcoap/src/coap_debug.c"
12-
"libcoap/src/encode.c"
13-
"libcoap/src/mem.c"
14-
"libcoap/src/net.c"
15-
"libcoap/src/option.c"
16-
"libcoap/src/pdu.c"
17-
"libcoap/src/resource.c"
18-
"libcoap/src/str.c"
19-
"libcoap/src/subscribe.c"
20-
"libcoap/src/uri.c"
21-
"libcoap/src/coap_notls.c"
22-
"port/coap_io.c")
4+
set(srcs
5+
"libcoap/src/address.c"
6+
"libcoap/src/async.c"
7+
"libcoap/src/block.c"
8+
"libcoap/src/coap_event.c"
9+
"libcoap/src/coap_hashkey.c"
10+
"libcoap/src/coap_session.c"
11+
"libcoap/src/coap_time.c"
12+
"libcoap/src/coap_debug.c"
13+
"libcoap/src/encode.c"
14+
"libcoap/src/mem.c"
15+
"libcoap/src/net.c"
16+
"libcoap/src/option.c"
17+
"libcoap/src/pdu.c"
18+
"libcoap/src/resource.c"
19+
"libcoap/src/str.c"
20+
"libcoap/src/subscribe.c"
21+
"libcoap/src/uri.c"
22+
"libcoap/src/coap_notls.c"
23+
"port/coap_io.c")
2324

24-
set(COMPONENT_REQUIRES lwip)
25+
set(COMPONENT_REQUIRES lwip)
2526

26-
idf_component_register(SRCS "${srcs}"
27+
idf_component_register(SRCS "${srcs}"
2728
INCLUDE_DIRS "${include_dirs}"
2829
REQUIRES lwip)
2930

30-
# Silence format truncation warning, until it is fixed upstream
31-
set_source_files_properties(libcoap/src/coap_debug.c PROPERTIES COMPILE_FLAGS -Wno-format-truncation)
31+
# Silence format truncation warning, until it is fixed upstream
32+
set_source_files_properties(libcoap/src/coap_debug.c PROPERTIES COMPILE_FLAGS -Wno-format-truncation)
3233

33-
# Needed for coap headers in public builds, also.
34-
#
35-
# TODO: find a way to move this to a port header
36-
target_compile_definitions(${COMPONENT_LIB} PUBLIC WITH_POSIX)
34+
# Needed for coap headers in public builds, also.
35+
#
36+
# TODO: find a way to move this to a port header
37+
target_compile_definitions(${COMPONENT_LIB} PUBLIC WITH_POSIX)
38+
else()
39+
register_component()
40+
endif()
3741

components/coap/Kconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
menu "COAP"
2+
3+
config ENABLE_COAP
4+
bool "Enable coap"
5+
default n
6+
select LWIP_IPV6
7+
help
8+
Enable this option and coap is to be used, IPv6 is to be Enable.
9+
endmenu
10+

components/coap/component.mk

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Component Makefile
33
#
44

5+
ifdef CONFIG_ENABLE_COAP
56
COMPONENT_ADD_INCLUDEDIRS := port/include port/include/coap libcoap/include libcoap/include/coap2
67

78
COMPONENT_OBJS = libcoap/src/address.o libcoap/src/async.o libcoap/src/block.o libcoap/src/coap_event.o libcoap/src/coap_hashkey.o libcoap/src/coap_session.o libcoap/src/coap_time.o libcoap/src/coap_debug.o libcoap/src/encode.o libcoap/src/mem.o libcoap/src/net.o libcoap/src/option.o libcoap/src/pdu.o libcoap/src/resource.o libcoap/src/str.o libcoap/src/subscribe.o libcoap/src/uri.o libcoap/src/coap_notls.o port/coap_io.o
@@ -12,3 +13,4 @@ COMPONENT_SUBMODULES += libcoap
1213

1314
# Silence format truncation warning, until it is fixed upstream
1415
libcoap/src/coap_debug.o: CFLAGS += -Wno-format-truncation
16+
endif

examples/protocols/coap_client/main/coap_client_example_main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "esp_log.h"
1919
#include "esp_wifi.h"
2020
#include "esp_event.h"
21-
21+
#include "esp_netif.h"
2222
#include "nvs_flash.h"
2323

2424
#include "protocol_examples_common.h"
@@ -282,7 +282,7 @@ static void coap_example_task(void *p)
282282
void app_main(void)
283283
{
284284
ESP_ERROR_CHECK( nvs_flash_init() );
285-
tcpip_adapter_init();
285+
ESP_ERROR_CHECK(esp_netif_init());
286286
ESP_ERROR_CHECK(esp_event_loop_create_default());
287287

288288
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ENABLE_COAP=y

examples/protocols/coap_server/main/coap_server_example_main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "esp_log.h"
1818
#include "esp_wifi.h"
1919
#include "esp_event.h"
20-
20+
#include "esp_netif.h"
2121
#include "nvs_flash.h"
2222

2323
#include "protocol_examples_common.h"
@@ -162,7 +162,7 @@ static void coap_example_thread(void *p)
162162
void app_main(void)
163163
{
164164
ESP_ERROR_CHECK( nvs_flash_init() );
165-
tcpip_adapter_init();
165+
ESP_ERROR_CHECK(esp_netif_init());
166166
ESP_ERROR_CHECK(esp_event_loop_create_default());
167167

168168
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ENABLE_COAP=y

0 commit comments

Comments
 (0)