mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-05 20:02:19 +03:00
Zephyr: Support C++ builds
Some of the Zephyr include files need to be C++, not C based. The 'extern "C"' wrapper in include/coap3/coap.h means that all #include are treated as being C. Remove 'extern "C"' wrapper from include/coap3/coap.h and add wrapper to include files after #include and before any function / structure definitions. Add in a C++ build test for CI.
This commit is contained in:
1 parent
7dff177f29
commit
ea01661faf
68 files changed
+582
-29
No files matched your search
@@ -1,2 +1,4 @@
|
||||
# never objects, and not the resulting binary
|
||||
coap-client
|
||||
coap-cpp-test
|
||||
zephyrproject
|
||||
@@ -1,6 +1,6 @@
|
||||
ZEPHYR_PROJECT?=zephyrproject
|
||||
|
||||
all: $(ZEPHYR_PROJECT) coap-client
|
||||
all: $(ZEPHYR_PROJECT) coap-client coap-cpp-test
|
||||
|
||||
${ZEPHYR_PROJECT}:
|
||||
python3 -m venv ${ZEPHYR_PROJECT}/.venv ;\
|
||||
@@ -34,7 +34,20 @@ coap-client: client-src/src/main.c client-src/* ../../src/*.c ../../include/*/*
|
||||
-DEXTRA_ZEPHYR_MODULES=$${LIBCOAP_DIR} \
|
||||
-DEXTRA_CONF_FILE=$${LIBCOAP_DIR}/zephyr/libcoap-mbedtls.conf)
|
||||
@cp -f $(ZEPHYR_PROJECT)/zephyr/build/zephyr/zephyr.exe coap-client
|
||||
@rm -rf $(ZEPHYR_PROJECT)/zephyr/build
|
||||
|
||||
coap-cpp-test: test-cpp-src/src/test.cpp test-cpp-src/* ../../src/*.c ../../include/*/*
|
||||
@LIBCOAP_DIR=`pwd`/../.. ;\
|
||||
(if [ -f $(ZEPHYR_PROJECT)/.venv/bin/activate ]; then \
|
||||
. $(ZEPHYR_PROJECT)/.venv/bin/activate ;\
|
||||
fi ;\
|
||||
cd $(ZEPHYR_PROJECT)/zephyr ;\
|
||||
west build -p always -b native_sim \
|
||||
$${LIBCOAP_DIR}/examples/zephyr/test-cpp-src -- \
|
||||
-DCONF_FILE=prj.conf \
|
||||
-DEXTRA_ZEPHYR_MODULES=$${LIBCOAP_DIR})
|
||||
@cp -f $(ZEPHYR_PROJECT)/zephyr/build/zephyr/zephyr.exe coap-cpp-test
|
||||
@rm -rf $(ZEPHYR_PROJECT)/zephyr/build
|
||||
clean:
|
||||
@rm -rf $(ZEPHYR_PROJECT)/zephyr/build
|
||||
@rm -f coap-client
|
||||
@rm -f coap-client coap-cpp-test
|
||||
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(coap_client)
|
||||
|
||||
target_sources(app PRIVATE src/test.cpp)
|
||||
|
||||
include(${ZEPHYR_BASE}/samples/net/common/common.cmake)
|
||||
@@ -0,0 +1,8 @@
|
||||
# Private config options for coap-client sample app
|
||||
|
||||
# Copyright (c) 2020 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
mainmenu "Test cpp build application"
|
||||
|
||||
source "Kconfig.zephyr"
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
CONFIG_LOG=y
|
||||
|
||||
CONFIG_LIBCOAP=y
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(coap_cpp_test, LOG_LEVEL_DBG);
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <errno.h>
|
||||
#include "coap3/coap.h"
|
||||
#include <stdio.h>
|
||||
|
||||
coap_str_const_t *xxx_libcoap_get_version() {
|
||||
coap_str_const_t *ver;
|
||||
|
||||
ver = coap_make_str_const(LIBCOAP_PACKAGE_VERSION);
|
||||
printf("Version: %s\n", ver->s);
|
||||
return ver;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
xxx_libcoap_get_version();
|
||||
exit(0);
|
||||
}
|
||||
Reference in new issue
Block a user