Skip to content

Commit d9f467d

Browse files
zhhyu7xiaoxiang781216
authored andcommitted
libcoap: add cmake script
Signed-off-by: zhanghongyu <[email protected]>
1 parent ce735f4 commit d9f467d

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

netutils/libcoap/CMakeLists.txt

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# ##############################################################################
2+
# apps/netutils/libcoap/CMakeLists.txt
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
5+
# license agreements. See the NOTICE file distributed with this work for
6+
# additional information regarding copyright ownership. The ASF licenses this
7+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
8+
# use this file except in compliance with the License. You may obtain a copy of
9+
# the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations under
17+
# the License.
18+
#
19+
# ##############################################################################
20+
21+
if(CONFIG_NETUTILS_LIBCOAP)
22+
set(LIBCOAP_DIR ${CMAKE_CURRENT_LIST_DIR}/libcoap)
23+
24+
if(NOT EXISTS ${LIBCOAP_DIR})
25+
set(LIBCOAP_URL https://codeload.github.com/obgm/libcoap/zip/refs/tags)
26+
set(LIBCOAP_VERSION ${CONFIG_LIBCOAP_VERSION})
27+
FetchContent_Declare(
28+
libcoap_fetch
29+
URL ${LIBCOAP_URL}/v${LIBCOAP_VERSION} SOURCE_DIR ${LIBCOAP_DIR}
30+
BINARY_DIR ${CMAKE_BINARY_DIR}/apps/netutils/libcoap
31+
DOWNLOAD_NO_PROGRESS true
32+
TIMEOUT 30)
33+
34+
FetchContent_GetProperties(libcoap_fetch)
35+
36+
if(NOT libcoap_fetch_POPULATED)
37+
FetchContent_Populate(libcoap_fetch)
38+
endif()
39+
endif()
40+
41+
set(LIBCOAP_FLAGS -Wno-undef)
42+
set(LIBCOAP_INCDIR ${CMAKE_CURRENT_LIST_DIR} ${LIBCOAP_DIR}/include
43+
${NUTTX_APPS_DIR}/crypto/mbedtls/mbedtls/include)
44+
45+
target_include_directories(apps PUBLIC ${LIBCOAP_INCDIR})
46+
target_compile_options(apps PRIVATE ${LIBCOAP_FLAGS})
47+
target_sources(
48+
apps
49+
PRIVATE libcoap/src/coap_address.c
50+
libcoap/src/coap_asn1.c
51+
libcoap/src/coap_async.c
52+
libcoap/src/coap_block.c
53+
libcoap/src/coap_cache.c
54+
libcoap/src/coap_debug.c
55+
libcoap/src/coap_dtls.c
56+
libcoap/src/coap_encode.c
57+
libcoap/src/coap_event.c
58+
libcoap/src/coap_hashkey.c
59+
libcoap/src/coap_gnutls.c
60+
libcoap/src/coap_io.c
61+
libcoap/src/coap_layers.c
62+
libcoap/src/coap_mbedtls.c
63+
libcoap/src/coap_mem.c
64+
libcoap/src/coap_net.c
65+
libcoap/src/coap_netif.c
66+
libcoap/src/coap_notls.c
67+
libcoap/src/coap_openssl.c
68+
libcoap/src/coap_option.c
69+
libcoap/src/coap_oscore.c
70+
libcoap/src/coap_pdu.c
71+
libcoap/src/coap_prng.c
72+
libcoap/src/coap_resource.c
73+
libcoap/src/coap_session.c
74+
libcoap/src/coap_str.c
75+
libcoap/src/coap_subscribe.c
76+
libcoap/src/coap_tcp.c
77+
libcoap/src/coap_time.c
78+
libcoap/src/coap_tinydtls.c
79+
libcoap/src/coap_uri.c
80+
libcoap/src/coap_ws.c
81+
libcoap/src/oscore/oscore.c
82+
libcoap/src/oscore/oscore_cbor.c
83+
libcoap/src/oscore/oscore_context.c
84+
libcoap/src/oscore/oscore_cose.c
85+
libcoap/src/oscore/oscore_crypto.c)
86+
87+
set(LIBCOAP_API_VERSION 3)
88+
set(LIBCOAP_PACKAGE_BUGREPORT "[email protected]")
89+
set(LIBCOAP_PACKAGE_NAME "libcoap")
90+
set(LIBCOAP_PACKAGE_VERSION "${CONFIG_LIBCOAP_VERSION}")
91+
set(LIBCOAP_PACKAGE_STRING
92+
"${LIBCOAP_PACKAGE_NAME} ${LIBCOAP_PACKAGE_VERSION}")
93+
set(LIBCOAP_PACKAGE_URL "https://libcoap.net/")
94+
configure_file(${LIBCOAP_DIR}/include/coap3/coap.h.in
95+
${LIBCOAP_DIR}/include/coap3/coap.h)
96+
97+
if(CONFIG_NETUTILS_LIBCOAP_EXAMPLE)
98+
nuttx_add_application(
99+
NAME
100+
coap_server
101+
SRCS
102+
libcoap/examples/coap-server.c
103+
INCLUDE_DIRECTORIES
104+
${LIBCOAP_INCDIR}
105+
COMPILE_FLAGS
106+
${LIBCOAP_FLAGS}
107+
DEPENDS
108+
mbedtls
109+
STACKSIZE
110+
${CONFIG_NETUTILS_LIBCOAP_EXAMPLE_STACKSIZE}
111+
PRIORITY
112+
${CONFIG_NETUTILS_LIBCOAP_EXAMPLE_PRIORITY})
113+
114+
nuttx_add_application(
115+
NAME
116+
coap_client
117+
SRCS
118+
libcoap/examples/coap-client.c
119+
INCLUDE_DIRECTORIES
120+
${LIBCOAP_INCDIR}
121+
COMPILE_FLAGS
122+
${LIBCOAP_FLAGS}
123+
DEPENDS
124+
mbedtls
125+
STACKSIZE
126+
${CONFIG_NETUTILS_LIBCOAP_EXAMPLE_STACKSIZE}
127+
PRIORITY
128+
${CONFIG_NETUTILS_LIBCOAP_EXAMPLE_PRIORITY})
129+
endif()
130+
endif()

0 commit comments

Comments
 (0)