feat(coap): Add COAP enable macro to make coap not build if application not use coap module

This commit is contained in:
yuanjm
2020-09-18 11:51:18 +08:00
parent 9ed7356f01
commit 684ea0a479
7 changed files with 51 additions and 33 deletions

View File

@ -1,37 +1,41 @@
set(include_dirs port/include port/include/coap libcoap/include libcoap/include/coap2)
if(CONFIG_ENABLE_COAP)
set(include_dirs port/include port/include/coap libcoap/include libcoap/include/coap2)
set(srcs
"libcoap/src/address.c"
"libcoap/src/async.c"
"libcoap/src/block.c"
"libcoap/src/coap_event.c"
"libcoap/src/coap_hashkey.c"
"libcoap/src/coap_session.c"
"libcoap/src/coap_time.c"
"libcoap/src/coap_debug.c"
"libcoap/src/encode.c"
"libcoap/src/mem.c"
"libcoap/src/net.c"
"libcoap/src/option.c"
"libcoap/src/pdu.c"
"libcoap/src/resource.c"
"libcoap/src/str.c"
"libcoap/src/subscribe.c"
"libcoap/src/uri.c"
"libcoap/src/coap_notls.c"
"port/coap_io.c")
set(srcs
"libcoap/src/address.c"
"libcoap/src/async.c"
"libcoap/src/block.c"
"libcoap/src/coap_event.c"
"libcoap/src/coap_hashkey.c"
"libcoap/src/coap_session.c"
"libcoap/src/coap_time.c"
"libcoap/src/coap_debug.c"
"libcoap/src/encode.c"
"libcoap/src/mem.c"
"libcoap/src/net.c"
"libcoap/src/option.c"
"libcoap/src/pdu.c"
"libcoap/src/resource.c"
"libcoap/src/str.c"
"libcoap/src/subscribe.c"
"libcoap/src/uri.c"
"libcoap/src/coap_notls.c"
"port/coap_io.c")
set(COMPONENT_REQUIRES lwip)
set(COMPONENT_REQUIRES lwip)
idf_component_register(SRCS "${srcs}"
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "${include_dirs}"
REQUIRES lwip)
# Silence format truncation warning, until it is fixed upstream
set_source_files_properties(libcoap/src/coap_debug.c PROPERTIES COMPILE_FLAGS -Wno-format-truncation)
# Silence format truncation warning, until it is fixed upstream
set_source_files_properties(libcoap/src/coap_debug.c PROPERTIES COMPILE_FLAGS -Wno-format-truncation)
# Needed for coap headers in public builds, also.
#
# TODO: find a way to move this to a port header
target_compile_definitions(${COMPONENT_LIB} PUBLIC WITH_POSIX)
# Needed for coap headers in public builds, also.
#
# TODO: find a way to move this to a port header
target_compile_definitions(${COMPONENT_LIB} PUBLIC WITH_POSIX)
else()
register_component()
endif()

10
components/coap/Kconfig Normal file
View File

@ -0,0 +1,10 @@
menu "COAP"
config ENABLE_COAP
bool "Enable coap"
default n
select LWIP_IPV6
help
Enable this option and coap is to be used, IPv6 is to be Enable.
endmenu

View File

@ -2,6 +2,7 @@
# Component Makefile
#
ifdef CONFIG_ENABLE_COAP
COMPONENT_ADD_INCLUDEDIRS := port/include port/include/coap libcoap/include libcoap/include/coap2
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
# Silence format truncation warning, until it is fixed upstream
libcoap/src/coap_debug.o: CFLAGS += -Wno-format-truncation
endif

View File

@ -18,7 +18,7 @@
#include "esp_log.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "nvs_flash.h"
#include "protocol_examples_common.h"
@ -282,7 +282,7 @@ clean_up:
void app_main(void)
{
ESP_ERROR_CHECK( nvs_flash_init() );
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.

View File

@ -0,0 +1 @@
CONFIG_ENABLE_COAP=y

View File

@ -17,7 +17,7 @@
#include "esp_log.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "nvs_flash.h"
#include "protocol_examples_common.h"
@ -162,7 +162,7 @@ clean_up:
void app_main(void)
{
ESP_ERROR_CHECK( nvs_flash_init() );
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.

View File

@ -0,0 +1 @@
CONFIG_ENABLE_COAP=y