Skip to content
Open
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
108 changes: 57 additions & 51 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,71 @@ env:

jobs:
build-linux-autotools:
name: Build for Linux using Autotools
runs-on: ubuntu-latest
strategy:
matrix:
CC: ["gcc", "clang" ]
steps:
- uses: actions/checkout@v3
- name: setup
run: |
sudo apt-get update && sudo apt-get install -y libcunit1-dev libtool libtool-bin exuberant-ctags valgrind
./autogen.sh
- name: configure
run: |
# mkdir build-${{matrix.CC}}
# cd build-${{matrix.CC}}
$GITHUB_WORKSPACE/configure --enable-tests
- name: compile
run: |
# cd build-${{matrix.CC}}
make EXTRA_CFLAGS=-Werror
- name: tests
run: |
# cd build-${{matrix.CC}}
libtool --mode=execute valgrind --track-origins=yes --leak-check=yes --show-reachable=yes --error-exitcode=123 --quiet tests/unit-tests/testdriver
libtool --mode=execute valgrind --track-origins=yes --leak-check=yes --show-reachable=yes --error-exitcode=123 --quiet tests/ccm-test

build-linux-cmake:
name: Build for Linux using CMake
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build tinydtls
- name: checkout
uses: actions/checkout@v3
- name: setup
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libcunit1-dev libtool libtool-bin exuberant-ctags valgrind
version: 1.0
- name: configure
run: |
cmake -E make_directory build_test
cd build_test
cmake -DWARNING_TO_ERROR=ON -Dmake_tests=ON ..
cmake --build .
build-macos-cmake:
name: Build for macOS using CMake
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
- name: Build tinydtls
# mkdir build-${{matrix.CC}}
# cd build-${{matrix.CC}}
$GITHUB_WORKSPACE/autogen.sh
$GITHUB_WORKSPACE/configure --enable-tests
- name: compile
run: |
cmake -E make_directory build_test
cd build_test
cmake -DWARNING_TO_ERROR=ON -Dmake_tests=ON ..
cmake --build .
# cd build-${{matrix.CC}}
make EXTRA_CFLAGS=-Werror
- name: tests
run: |
# cd build-${{matrix.CC}}
libtool --mode=execute valgrind --track-origins=yes --leak-check=yes --show-reachable=yes --error-exitcode=123 --quiet tests/unit-tests/testdriver
libtool --mode=execute valgrind --track-origins=yes --leak-check=yes --show-reachable=yes --error-exitcode=123 --quiet tests/ccm-test

build-windows:
name: Build for Windows using CMake
runs-on: windows-latest
build-cmake:
name: Build using CMake
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- os: ubuntu-latest
vcpkg_triplet: x64-linux-release
compiler: "Unix Makefiles"
- os: macos-latest
vcpkg_triplet: arm64-osx-release
compiler: "Unix Makefiles"
- os: windows-latest
vcpkg_triplet: x64-windows-release
compiler: "Unix Makefiles"
- os: windows-latest
vcpkg_triplet: x64-windows-release
compiler: "Visual Studio 17 2022"

steps:
- uses: actions/checkout@v3
- name: Build tinydtls
run: |
cmake -E make_directory build_test
cd build_test
cmake -G "Unix Makefiles" -DWARNING_TO_ERROR=ON ..
cmake --build .
- name: checkout
uses: actions/checkout@v3
- name: vcpkg-setup
uses: johnwason/vcpkg-action@v7
id: vcpkg
with:
pkgs: cunit
triplet: ${{ matrix.config.vcpkg_triplet }}
cache-key: ${{ matrix.config.os }}
token: ${{ github.token }}
- name: configure
run: cmake ${{ steps.vcpkg.outputs.vcpkg-cmake-config }} -G "${{ matrix.config.compiler }}" -DWARNING_TO_ERROR=ON -Dmake_tests=ON -DENABLE_DOCS=OFF -B build_test
- name: compile
run: cmake --build build_test
- name: test
working-directory: build_test
run: ctest -C Debug --verbose
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ CMakeFiles
tinydtls.dir
Debug
Release
*.json
out
3 changes: 2 additions & 1 deletion AutoConf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ check_function_exists (strdup HAVE_STRDUP)
check_function_exists (strerror HAVE_STRERROR)
check_function_exists (strnlen HAVE_STRNLEN)
check_function_exists (fls HAVE_FLS)
check_function_exists (snprintf HAVE_SNPRINTF)
check_function_exists (vprintf HAVE_VPRINTF)
check_function_exists (inet_ntop HAVE_INET_NTOP)
check_function_exists (random HAVE_RANDOM)
check_function_exists (random HAVE_RANDOM)

if(HAVE_SYS_RANDOM_H)
# zephyr/ncs 1.9.1 seems to link getrandom but doesn't offer a header
Expand Down
117 changes: 101 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@
#
###############################################################################

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.10)

project(tinydtls)
project(tinydtls
VERSION "0.8.6"
DESCRIPTION "A C library for Datagram Transport Layer Security (DTLS) supporting both client and server functionality."
HOMEPAGE_URL "https://projects.eclipse.org/projects/iot.tinydtls"
LANGUAGES C)

set(CMAKE_C_STANDARD 99)

include (AutoConf.cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

if(NOT ZEPHYR_BASE)
option(BUILD_SHARED_LIBS "Link using shared libs" OFF)
Expand All @@ -39,9 +46,10 @@ if(NOT PLATFORM)
set_property(CACHE PLATFORM PROPERTY STRINGS "contiki" "espidf" "posix" "riot" "zephyr" "windows")
endif()

set(PACKAGE_NAME "tinydtls")
set(PACKAGE_VERSION "0.8.6" )
set(SOVERSION "0" )
set(PACKAGE_NAME "${PROJECT_NAME}")
set(PACKAGE_VERSION "${PROJECT_VERSION}" )
set(PACKAGE_URL "${PROJECT_HOMEPAGE_URL}")
set(SOVERSION "0" )

if(NOT ZEPHYR_BASE)
option(DTLS_ECC "disable/enable support for TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" ON )
Expand All @@ -52,7 +60,11 @@ endif()

option(WARNING_TO_ERROR "force all compiler warnings to be errors" OFF)

configure_file(dtls_config.h.cmake.in dtls_config.h )
if(MSVC)
option(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS "Export all symbols when compiling to a .dll" ON)
endif()

configure_file(dtls_config.h.cmake.in dtls_config.h)

add_library(tinydtls)

Expand All @@ -73,14 +85,13 @@ target_sources(tinydtls PRIVATE
ecc/ecc.c)

target_include_directories(tinydtls PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(tinydtls PUBLIC DTLSv12 WITH_SHA256 SHA2_USE_INTTYPES_H DTLS_CHECK_CONTENTTYPE)
target_compile_definitions(tinydtls PUBLIC DTLSv12 WITH_SHA256 SHA2_USE_INTTYPES_H DTLS_CHECK_CONTENTTYPE $<$<BOOL:${make_tests}>:TEST_INCLUDE>)

if(MSVC)
option(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS "Export all symbols when compiling to a .dll" ON)
target_compile_options(tinydtls PRIVATE -Wall)
target_compile_options(tinydtls PRIVATE -Wall -wd4127 -wd4200 -wd4242 -wd4244 -wd4267 -wd4702 -wd4710 -wd4711 -wd4668 -wd4820 -wd5045 -D_CRT_SECURE_NO_WARNINGS)
if(${WARNING_TO_ERROR})
target_compile_options(tinydtls PRIVATE -WX)
endif()
endif()
elseif(NOT ZEPHYR_BASE)
target_compile_options(tinydtls PRIVATE -fPIC -pedantic -std=c99 -Wall -Wextra -Wformat-security -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wshadow -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wunused)
if(${WARNING_TO_ERROR})
Expand All @@ -92,16 +103,90 @@ set_target_properties(tinydtls PROPERTIES VERSION ${PACKAGE_VERSION} SOVERSION $

if( ${make_tests} )
add_subdirectory(tests)
endif()

if(BUILD_SHARED_LIBS)
install(TARGETS tinydtls LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
else()
install(TARGETS tinydtls DESTINATION ${CMAKE_INSTALL_LIBDIR} )
add_subdirectory(tests/unit-tests)
include(CTest)
add_test(NAME test COMMAND testdriver)
add_test(NAME ccm-test COMMAND ccm-test)
endif()

if(NOT (${CMAKE_VERSION} VERSION_LESS "3.18.0"))
file(CONFIGURE OUTPUT .gitignore
NEWLINE_STYLE UNIX
CONTENT "*")
endif()

include(GNUInstallDirs)
install(TARGETS tinydtls
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(FILES
alert.h
ccm.h
crypto.h
dtls.h
"${CMAKE_CURRENT_BINARY_DIR}/dtls_config.h"
dtls_debug.h
dtls_mutex.h
dtls_prng.h
dtls_time.h
global.h
hmac.h
netq.h
numeric.h
peer.h
session.h
state.h
tinydtls.h
uthash.h
utlist.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tinydtls")
install(FILES
aes/rijndael.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tinydtls/aes")
install(FILES
sha2/sha2.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tinydtls/sha2")
install(FILES
ecc/ecc.h
ecc/test_helper.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tinydtls/ecc")

# pkg-config
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "\${prefix}")
set(includedir "\${prefix}/include")
set(libdir "\${exec_prefix}/lib")
configure_file(tinydtls.pc.in tinydtls.pc @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/tinydtls.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

# Doxygen
option(ENABLE_DOCS "build Doxygen documentation" ON)
if(ENABLE_DOCS)
find_package(Doxygen REQUIRED)
set(DOXYGEN_QUIET YES)
set(DOXYGEN_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
set(DOXYGEN_PROJECT_NAME "${PACKAGE_NAME}")
set(DOXYGEN_PROJECT_NUMBER "${PACKAGE_VERSION}")
set(DOXYGEN_RECURSIVE NO)
set(DOXYGEN_EXTRACT_ALL YES)
set(DOXYGEN_EXTRACT_STATIC YES)
set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES)
set(DOXYGEN_DOT_IMAGE_FORMAT svg)
set(DOXYGEN_INTERACTIVE_SVG YES)
doxygen_add_docs(docs
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/aes
${CMAKE_CURRENT_SOURCE_DIR}/ecc
${CMAKE_CURRENT_SOURCE_DIR}/sha2
COMMENT "Building Doxygen documentation")
add_custom_command(TARGET tinydtls POST_BUILD
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target docs)
install(DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}/html/"
TYPE DOC
PATTERN "*.md5" EXCLUDE
PATTERN "*.map" EXCLUDE)
endif()
Loading