Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcoap: add makefile, Kconfig and CMakeLists.txt #2250

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions netutils/libcoap/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/libcoap*
130 changes: 130 additions & 0 deletions netutils/libcoap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# ##############################################################################
# apps/netutils/libcoap/CMakeLists.txt
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################

if(CONFIG_NETUTILS_LIBCOAP)
set(LIBCOAP_DIR ${CMAKE_CURRENT_LIST_DIR}/libcoap)

if(NOT EXISTS ${LIBCOAP_DIR})
set(LIBCOAP_URL https://codeload.github.com/obgm/libcoap/zip/refs/tags)
set(LIBCOAP_VERSION ${CONFIG_LIBCOAP_VERSION})
FetchContent_Declare(
libcoap_fetch
URL ${LIBCOAP_URL}/v${LIBCOAP_VERSION} SOURCE_DIR ${LIBCOAP_DIR}
BINARY_DIR ${CMAKE_BINARY_DIR}/apps/netutils/libcoap
DOWNLOAD_NO_PROGRESS true
TIMEOUT 30)

FetchContent_GetProperties(libcoap_fetch)

if(NOT libcoap_fetch_POPULATED)
FetchContent_Populate(libcoap_fetch)
endif()
endif()

set(LIBCOAP_FLAGS -Wno-undef)
set(LIBCOAP_INCDIR ${CMAKE_CURRENT_LIST_DIR} ${LIBCOAP_DIR}/include
${NUTTX_APPS_DIR}/crypto/mbedtls/mbedtls/include)

target_include_directories(apps PUBLIC ${LIBCOAP_INCDIR})
target_compile_options(apps PRIVATE ${LIBCOAP_FLAGS})
target_sources(
apps
PRIVATE libcoap/src/coap_address.c
libcoap/src/coap_asn1.c
libcoap/src/coap_async.c
libcoap/src/coap_block.c
libcoap/src/coap_cache.c
libcoap/src/coap_debug.c
libcoap/src/coap_dtls.c
libcoap/src/coap_encode.c
libcoap/src/coap_event.c
libcoap/src/coap_hashkey.c
libcoap/src/coap_gnutls.c
libcoap/src/coap_io.c
libcoap/src/coap_layers.c
libcoap/src/coap_mbedtls.c
libcoap/src/coap_mem.c
libcoap/src/coap_net.c
libcoap/src/coap_netif.c
libcoap/src/coap_notls.c
libcoap/src/coap_openssl.c
libcoap/src/coap_option.c
libcoap/src/coap_oscore.c
libcoap/src/coap_pdu.c
libcoap/src/coap_prng.c
libcoap/src/coap_resource.c
libcoap/src/coap_session.c
libcoap/src/coap_str.c
libcoap/src/coap_subscribe.c
libcoap/src/coap_tcp.c
libcoap/src/coap_time.c
libcoap/src/coap_tinydtls.c
libcoap/src/coap_uri.c
libcoap/src/coap_ws.c
libcoap/src/oscore/oscore.c
libcoap/src/oscore/oscore_cbor.c
libcoap/src/oscore/oscore_context.c
libcoap/src/oscore/oscore_cose.c
libcoap/src/oscore/oscore_crypto.c)

set(LIBCOAP_API_VERSION 3)
set(LIBCOAP_PACKAGE_BUGREPORT "[email protected]")
set(LIBCOAP_PACKAGE_NAME "libcoap")
set(LIBCOAP_PACKAGE_VERSION "${CONFIG_LIBCOAP_VERSION}")
set(LIBCOAP_PACKAGE_STRING
"${LIBCOAP_PACKAGE_NAME} ${LIBCOAP_PACKAGE_VERSION}")
set(LIBCOAP_PACKAGE_URL "https://libcoap.net/")
configure_file(${LIBCOAP_DIR}/include/coap3/coap.h.in
${LIBCOAP_DIR}/include/coap3/coap.h)

if(CONFIG_NETUTILS_LIBCOAP_EXAMPLE)
nuttx_add_application(
NAME
coap_server
SRCS
libcoap/examples/coap-server.c
INCLUDE_DIRECTORIES
${LIBCOAP_INCDIR}
COMPILE_FLAGS
${LIBCOAP_FLAGS}
DEPENDS
mbedtls
STACKSIZE
${CONFIG_NETUTILS_LIBCOAP_EXAMPLE_STACKSIZE}
PRIORITY
${CONFIG_NETUTILS_LIBCOAP_EXAMPLE_PRIORITY})

nuttx_add_application(
NAME
coap_client
SRCS
libcoap/examples/coap-client.c
INCLUDE_DIRECTORIES
${LIBCOAP_INCDIR}
COMPILE_FLAGS
${LIBCOAP_FLAGS}
DEPENDS
mbedtls
STACKSIZE
${CONFIG_NETUTILS_LIBCOAP_EXAMPLE_STACKSIZE}
PRIORITY
${CONFIG_NETUTILS_LIBCOAP_EXAMPLE_PRIORITY})
endif()
endif()
37 changes: 37 additions & 0 deletions netutils/libcoap/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

config NETUTILS_LIBCOAP
bool "LIBCOAP"
default n
---help---
libcoap is a C implementation of a lightweight application-protocol
for devices that are constrained their resources such as computing
power, RF range, memory, bandwidth, or network packet sizes. This
protocol, CoAP, is standardized by the IETF as RFC 7252.

if NETUTILS_LIBCOAP

config LIBCOAP_VERSION
string "libcoap version"
default "4.3.4"

config NETUTILS_LIBCOAP_EXAMPLE
tristate "Example coap-server and coap-client"
default n

if NETUTILS_LIBCOAP_EXAMPLE

config NETUTILS_LIBCOAP_EXAMPLE_PRIORITY
int "libcoap example priority"
default 100

config NETUTILS_LIBCOAP_EXAMPLE_STACKSIZE
int "libcoap example stacksize"
default 2048

endif # NETUTILS_LIBCOAP_EXAMPLE

endif # NETUTILS_LIBCOAP
24 changes: 24 additions & 0 deletions netutils/libcoap/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
############################################################################
# apps/netutils/libcoap/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

ifneq ($(CONFIG_NETUTILS_LIBCOAP),)
CONFIGURED_APPS += $(APPDIR)/netutils/libcoap
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)$(DELIM)netutils$(DELIM)libcoap$(DELIM)libcoap$(DELIM)include
endif
105 changes: 105 additions & 0 deletions netutils/libcoap/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
############################################################################
# apps/netutils/libcoap/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

include $(APPDIR)/Make.defs

COAP_URL ?= "https://codeload.github.com/obgm/libcoap/zip/refs/tags"

COAP_ZIP = libcoap-$(CONFIG_LIBCOAP_VERSION).zip

COAP_UNPACKNAME = libcoap
UNPACK ?= unzip -q -o

$(COAP_ZIP):
@echo "Downloading: $(COAP_URL)/v$(CONFIG_LIBCOAP_VERSION)"
$(Q) curl -o $(COAP_ZIP) -L $(COAP_URL)/v$(CONFIG_LIBCOAP_VERSION)

$(COAP_UNPACKNAME): $(COAP_ZIP)
@echo "Unpacking: $(COAP_ZIP) -> $(COAP_UNPACKNAME)"
$(Q) $(UNPACK) $(COAP_ZIP)
@echo "Unpacking: $(COAP_ZIP) -> $(COAP_UNPACKNAME)"
$(Q) mv libcoap-$(CONFIG_LIBCOAP_VERSION) $(COAP_UNPACKNAME)
$(Q) touch $(COAP_UNPACKNAME)

# Download and unpack tarball if no git repo found
ifeq ($(wildcard $(COAP_UNPACKNAME)/.git),)
context:: $(COAP_UNPACKNAME)

distclean::
$(call DELDIR, $(COAP_UNPACKNAME))
$(call DELFILE, $(COAP_ZIP))
endif

context:: $(COAP_UNPACKNAME)/include/coap3/coap.h

$(COAP_UNPACKNAME)/include/coap3/coap.h:: $(COAP_UNPACKNAME)
cd $(COAP_UNPACKNAME) && ./autogen.sh && \
./configure --disable-doxygen --disable-manpages

CSRCS += libcoap/src/coap_address.c
CSRCS += libcoap/src/coap_asn1.c
CSRCS += libcoap/src/coap_async.c
CSRCS += libcoap/src/coap_block.c
CSRCS += libcoap/src/coap_cache.c
CSRCS += libcoap/src/coap_debug.c
CSRCS += libcoap/src/coap_dtls.c
CSRCS += libcoap/src/coap_encode.c
CSRCS += libcoap/src/coap_event.c
CSRCS += libcoap/src/coap_hashkey.c
CSRCS += libcoap/src/coap_gnutls.c
CSRCS += libcoap/src/coap_io.c
CSRCS += libcoap/src/coap_layers.c
CSRCS += libcoap/src/coap_mbedtls.c
CSRCS += libcoap/src/coap_mem.c
CSRCS += libcoap/src/coap_net.c
CSRCS += libcoap/src/coap_netif.c
CSRCS += libcoap/src/coap_notls.c
CSRCS += libcoap/src/coap_openssl.c
CSRCS += libcoap/src/coap_option.c
CSRCS += libcoap/src/coap_oscore.c
CSRCS += libcoap/src/coap_pdu.c
CSRCS += libcoap/src/coap_prng.c
CSRCS += libcoap/src/coap_resource.c
CSRCS += libcoap/src/coap_session.c
CSRCS += libcoap/src/coap_str.c
CSRCS += libcoap/src/coap_subscribe.c
CSRCS += libcoap/src/coap_tcp.c
CSRCS += libcoap/src/coap_time.c
CSRCS += libcoap/src/coap_tinydtls.c
CSRCS += libcoap/src/coap_uri.c
CSRCS += libcoap/src/coap_ws.c
CSRCS += libcoap/src/oscore/oscore.c
CSRCS += libcoap/src/oscore/oscore_cbor.c
CSRCS += libcoap/src/oscore/oscore_context.c
CSRCS += libcoap/src/oscore/oscore_cose.c
CSRCS += libcoap/src/oscore/oscore_crypto.c

CFLAGS += ${INCDIR_PREFIX}$(APPDIR)$(DELIM)netutils$(DELIM)libcoap
CFLAGS += -Wno-undef

ifneq ($(CONFIG_NETUTILS_LIBCOAP_EXAMPLE),)
PROGNAME += coap_server coap_client
PRIORITY = $(CONFIG_NETUTILS_LIBCOAP_EXAMPLE_PRIORITY)
STACKSIZE = $(CONFIG_NETUTILS_LIBCOAP_EXAMPLE_STACKSIZE)
MODULE = $(CONFIG_NETUTILS_LIBCOAP_EXAMPLE)
MAINSRC = libcoap/examples/coap-server.c libcoap/examples/coap-client.c
endif

include $(APPDIR)/Application.mk
Loading
Loading