Skip to content

Commit

Permalink
include: Move header files into libcoap namespace
Browse files Browse the repository at this point in the history
I.E. '#include "mem.h"' becomes '#include "coap2/mem.h"'

This prevents header name clashes.

Replacement for #487
  • Loading branch information
mrdeep1 committed Mar 4, 2021
1 parent 4efb04d commit ccca2c2
Show file tree
Hide file tree
Showing 68 changed files with 150 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ aclocal.m4
ar-lib
autom4te.cache/
coap_config.h
/coap_config.h.in
coap_config.h.in
compile
config.*
configure
Expand Down
51 changes: 32 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ set(DTLS_BACKEND
"default"
CACHE
STRING
" \
Name of the dtls backend, only relevant if `ENABLE_DTLS` is ON which is default. \
Possible values: default, gnutls, openssl, tinydtls and mbedtls. \
If specified then this library will be searched and if found also used. \
If not found then the cmake configuration will stop with an error. \
If not specified, then cmake will try to use the first one found in the following order: \
gnutls, openssl, tinydtls, mbedtls \
"\
Name of the dtls backend, only relevant if `ENABLE_DTLS` is ON which is default. \
Possible values: default, gnutls, openssl, tinydtls and mbedtls. \
If specified then this library will be searched and if found also used. \
If not found then the cmake configuration will stop with an error. \
If not specified, then cmake will try to use the first one found in the following order: \
gnutls, openssl, tinydtls, mbedtls \
")
set_property(
CACHE DTLS_BACKEND
Expand Down Expand Up @@ -220,7 +220,8 @@ function(compile_tinydtls)
IMPORTED)
set_target_properties(
tinydtls
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/include"
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_CURRENT_BINARY_DIR}/include"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${LIBTINYDTLS_PATH}")

Expand Down Expand Up @@ -266,7 +267,10 @@ if(ENABLE_DTLS)

else()
# no cryto lib found
message(FATAL_ERROR "cannot find any cryto lib, either install one or compile without DTLS support")
message(
FATAL_ERROR
"cannot find any cryto lib, either install one or compile without DTLS support"
)
endif()

endif()
Expand Down Expand Up @@ -377,9 +381,10 @@ else(ENABLE_TCP)
endif(ENABLE_TCP)

# creates config header file in build directory
configure_file(${CMAKE_CURRENT_LIST_DIR}/include/coap2/coap.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/coap2/coap.h)
configure_file(${CMAKE_CURRENT_LIST_DIR}/include/coap2/coap.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/coap2/coap.h)

configure_file(${CMAKE_CURRENT_LIST_DIR}/include/coap2/coap_config.h.in
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake_coap_config.h.in
${CMAKE_CURRENT_BINARY_DIR}/coap_config.h)

#
Expand Down Expand Up @@ -459,9 +464,7 @@ target_include_directories(
PUBLIC # config headers are generated during configuration time
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/coap2/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/coap2>
$<INSTALL_INTERFACE:include/>
$<$<BOOL:${USE_VENDORED_TINYDTLS}>:${CMAKE_BINARY_DIR}/include/tinydtls>
$<$<BOOL:${HAVE_LIBGNUTLS}>:${GNUTLS_INCLUDE_DIR}>
Expand Down Expand Up @@ -530,7 +533,8 @@ if(ENABLE_TESTS)
${CMAKE_CURRENT_LIST_DIR}/tests/test_wellknown.c
${CMAKE_CURRENT_LIST_DIR}/tests/test_wellknown.h)
# tests require libcunit (e.g. debian libcunit1-dev)
target_link_libraries(testdriver PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME} -lcunit)
target_link_libraries(testdriver PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME}
-lcunit)
endif()

#
Expand All @@ -539,17 +543,20 @@ endif()

if(ENABLE_EXAMPLES)
add_executable(coap-client ${CMAKE_CURRENT_LIST_DIR}/examples/coap-client.c)
target_link_libraries(coap-client PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})
target_link_libraries(coap-client
PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})

add_executable(coap-rd ${CMAKE_CURRENT_LIST_DIR}/examples/coap-rd.c)
target_link_libraries(coap-rd PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})

add_executable(coap-server ${CMAKE_CURRENT_LIST_DIR}/examples/coap-server.c)
target_link_libraries(coap-server PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})
target_link_libraries(coap-server
PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})

if(NOT WIN32)
add_executable(etsi_iot_01 ${CMAKE_CURRENT_LIST_DIR}/examples/etsi_iot_01.c)
target_link_libraries(etsi_iot_01 PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})
target_link_libraries(etsi_iot_01
PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})

add_executable(tiny ${CMAKE_CURRENT_LIST_DIR}/examples/tiny.c)
target_link_libraries(tiny PUBLIC ${PROJECT_NAME}::${COAP_LIBRARY_NAME})
Expand Down Expand Up @@ -586,7 +593,9 @@ if(ENABLE_DOCS)
message(STATUS "Setup up the Doxygen documention build")

else(Doxygen_FOUND)
message(WARNING "Doxygen need to be installed to generate the doxygen documentation")
message(
WARNING
"Doxygen need to be installed to generate the doxygen documentation")
endif(Doxygen_FOUND)

endif()
Expand Down Expand Up @@ -616,7 +625,9 @@ configure_package_config_file(
${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION
${LIBCOAP_CONFIG_INSTALL_DIR})
write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake COMPATIBILITY SameMajorVersion)
write_basic_package_version_file(
${PROJECT_NAME}ConfigVersion.cmake
COMPATIBILITY SameMajorVersion)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
Expand All @@ -629,6 +640,8 @@ install(
COMPONENT dev
FILES_MATCHING
PATTERN "*.h"
PATTERN "coap.h" EXCLUDE
PATTERN "utlist.h" EXCLUDE
PATTERN "*internal.h" EXCLUDE)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ EXTRA_DIST = \
win32/testdriver/testdriver.vcxproj.filters \
win32/testdriver/testdriver.vcxproj.user

AM_CFLAGS = -I$(top_builddir)/include/coap$(LIBCOAP_API_VERSION) -I$(top_srcdir)/include/coap$(LIBCOAP_API_VERSION) $(WARNING_CFLAGS) $(DTLS_CFLAGS) -std=c99 $(EXTRA_CFLAGS)
AM_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include $(WARNING_CFLAGS) $(DTLS_CFLAGS) -std=c99 $(EXTRA_CFLAGS)

SUBDIRS = $(subdirs) . man $(DOC_DIR) tests examples

Expand Down
2 changes: 1 addition & 1 deletion Makefile.libcoap
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ libcoap_dir := $(filter %libcoap,$(APPDS))
vpath %c $(libcoap_dir)/src

# set include path for coap sources
CFLAGS += -I$(libcoap_dir)/include/coap2
CFLAGS += -I$(libcoap_dir)/include
2 changes: 1 addition & 1 deletion cmake-format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# https://github.com/cheshirekow/cmake_format

# How wide to allow formatted cmake files
line_width: 120
line_width: 80

# How many spaces to tab for indent
tab_size: 2
Expand Down
2 changes: 1 addition & 1 deletion include/coap2/coap_config.h.in → cmake_coap_config.h.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* coap_config.h. Generated from coap_config.h.in by cmake. */
/* coap_config.h. Generated from cmake_coap_config.h.in by cmake. */

#ifndef COAP_CONFIG_H_
#define COAP_CONFIG_H_
Expand Down
8 changes: 1 addition & 7 deletions examples/coap_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@
* of coap-client
*/

/* #include "coap_config.h" */

#include <stdio.h>
#include <string.h>

#include <coap2/libcoap.h>
#include <coap2/debug.h>
#include <coap2/mem.h>
#include "coap_list.h"

#include <coap2/coap.h>

int
coap_insert(coap_list_t **head, coap_list_t *node) {
Expand Down
2 changes: 1 addition & 1 deletion examples/contiki/coap-observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#include <string.h>

#include "coap.h"
#include "coap2/coap.h"

static coap_context_t *coap_context;

Expand Down
2 changes: 1 addition & 1 deletion examples/contiki/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#include <string.h>

#include "coap.h"
#include "coap2/coap.h"

static coap_context_t *coap_context;

Expand Down
1 change: 0 additions & 1 deletion examples/etsi_iot_01.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <errno.h>
#include <signal.h>

#include "uthash.h"
#include <coap2/coap.h>

#define COAP_RESOURCE_CHECK_TIME_SEC 1
Expand Down
2 changes: 1 addition & 1 deletion examples/lwip/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ LWIPOBJS += mld6.o ip6.o icmp6.o ethip6.o nd6.o ip6_addr.o ip6_frag.o

CFLAGS += -std=gnu99

CFLAGS += -I$(top_srcdir)/include/coap2
CFLAGS += -I$(top_srcdir)/include -I$(top_srcdir)/include/coap2

vpath %.c $(top_srcdir)/src

Expand Down
2 changes: 1 addition & 1 deletion examples/lwip/server-coap.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "coap_config.h"
#include <coap.h>
#include <coap2/coap.h>

coap_context_t *main_coap_context;

Expand Down
2 changes: 1 addition & 1 deletion examples/lwip/server-coap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "coap_config.h"
#include <coap.h>
#include <coap2/coap.h>

void server_coap_init(void);
/* call this when you think that resources could be dirty */
Expand Down
2 changes: 1 addition & 1 deletion include/coap2/address.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include "libcoap.h"
#include "coap2/libcoap.h"

#if defined(WITH_LWIP)

Expand Down
2 changes: 1 addition & 1 deletion include/coap2/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef COAP_ASYNC_H_
#define COAP_ASYNC_H_

#include "net.h"
#include "coap2/net.h"

#ifndef WITHOUT_ASYNC

Expand Down
6 changes: 3 additions & 3 deletions include/coap2/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#ifndef COAP_BLOCK_H_
#define COAP_BLOCK_H_

#include "encode.h"
#include "option.h"
#include "pdu.h"
#include "coap2/encode.h"
#include "coap2/option.h"
#include "coap2/pdu.h"

/**
* @defgroup block Block Transfer
Expand Down
44 changes: 22 additions & 22 deletions include/coap2/coap.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@
extern "C" {
#endif

#include "libcoap.h"
#include "coap2/libcoap.h"

#include "coap_forward_decls.h"
#include "address.h"
#include "async.h"
#include "bits.h"
#include "block.h"
#include "coap_cache.h"
#include "coap_dtls.h"
#include "coap_event.h"
#include "coap_io.h"
#include "coap_time.h"
#include "coap_debug.h"
#include "encode.h"
#include "mem.h"
#include "net.h"
#include "option.h"
#include "pdu.h"
#include "coap_prng.h"
#include "resource.h"
#include "str.h"
#include "subscribe.h"
#include "uri.h"
#include "coap2/coap_forward_decls.h"
#include "coap2/address.h"
#include "coap2/async.h"
#include "coap2/bits.h"
#include "coap2/block.h"
#include "coap2/coap_cache.h"
#include "coap2/coap_dtls.h"
#include "coap2/coap_event.h"
#include "coap2/coap_io.h"
#include "coap2/coap_time.h"
#include "coap2/coap_debug.h"
#include "coap2/encode.h"
#include "coap2/mem.h"
#include "coap2/net.h"
#include "coap2/option.h"
#include "coap2/pdu.h"
#include "coap2/coap_prng.h"
#include "coap2/resource.h"
#include "coap2/str.h"
#include "coap2/subscribe.h"
#include "coap2/uri.h"

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion include/coap2/coap_block_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef COAP_BLOCK_INTERNAL_H_
#define COAP_BLOCK_INTERNAL_H_

#include <resource.h>
#include "coap2/resource.h"

/**
* @defgroup block_internal Block (Internal)
Expand Down
2 changes: 1 addition & 1 deletion include/coap2/coap_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void coap_log_impl(coap_log_t level, const char *format, ...);
} while(0)
#endif

#include "pdu.h"
#include "coap2/pdu.h"

/**
* Defines the output mode for the coap_show_pdu() function.
Expand Down
4 changes: 2 additions & 2 deletions include/coap2/coap_dtls.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#ifndef COAP_DTLS_H_
#define COAP_DTLS_H_

#include "coap_time.h"
#include "str.h"
#include "coap2/coap_time.h"
#include "coap2/str.h"

/**
* @defgroup dtls DTLS Support
Expand Down
2 changes: 1 addition & 1 deletion include/coap2/coap_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef COAP_EVENT_H_
#define COAP_EVENT_H_

#include "libcoap.h"
#include "coap2/libcoap.h"

/**
* @defgroup events Event API
Expand Down
6 changes: 3 additions & 3 deletions include/coap2/coap_hashkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#ifndef COAP_HASHKEY_H_
#define COAP_HASHKEY_H_

#include "libcoap.h"
#include "uthash.h"
#include "str.h"
#include "coap2/libcoap.h"
#include "coap2/uthash.h"
#include "coap2/str.h"

typedef unsigned char coap_key_t[4];

Expand Down
Loading

0 comments on commit ccca2c2

Please sign in to comment.