diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0ffa4460..b1c61c49 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,8 +50,10 @@ jobs: - uses: actions/checkout@v3 - name: Build tinydtls run: | - cmake -Dmake_tests=ON . - make + 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 @@ -60,8 +62,10 @@ jobs: - uses: actions/checkout@v3 - name: Build tinydtls run: | - cmake -Dmake_tests=ON . - make + cmake -E make_directory build_test + cd build_test + cmake -DWARNING_TO_ERROR=ON -Dmake_tests=ON .. + cmake --build . build-windows: name: Build for Windows using CMake @@ -71,6 +75,7 @@ jobs: - uses: actions/checkout@v3 - name: Build tinydtls run: | - cmake -G "Unix Makefiles" . - make - + cmake -E make_directory build_test + cd build_test + cmake -G "Unix Makefiles" -DWARNING_TO_ERROR=ON .. + cmake --build . diff --git a/CMakeLists.txt b/CMakeLists.txt index 86762030..1292faf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ set(SOVERSION "0" ) option(DTLS_ECC "disable/enable support for TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" ON ) option(DTLS_PSK "disable/enable support for TLS_PSK_WITH_AES_128_CCM_8" ON) +option(WARNING_TO_ERROR "force all compiler warnings to be errors" OFF) configure_file(dtls_config.h.cmake.in dtls_config.h ) @@ -67,8 +68,14 @@ target_compile_definitions(tinydtls PUBLIC DTLSv12 WITH_SHA256 SHA2_USE_INTTYPES if(CMAKE_GENERATOR MATCHES "Visual Studio") option(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS "Export all symbols when compiling to a .dll" ON) target_compile_options(tinydtls PRIVATE -Wall) + if(${WARNING_TO_ERROR}) + target_compile_options(tinydtls PRIVATE -WX) + 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}) + target_compile_options(tinydtls PRIVATE -Werror) + endif() endif() set_target_properties(tinydtls PROPERTIES VERSION ${PACKAGE_VERSION} SOVERSION ${SOVERSION}) @@ -83,6 +90,8 @@ else() install(TARGETS tinydtls DESTINATION ${CMAKE_INSTALL_LIBDIR} ) endif() -file(CONFIGURE OUTPUT .gitignore - NEWLINE_STYLE UNIX - CONTENT "*") +if(NOT (${CMAKE_VERSION} VERSION_LESS "3.18.0")) + file(CONFIGURE OUTPUT .gitignore + NEWLINE_STYLE UNIX + CONTENT "*") +endif() diff --git a/dtls.c b/dtls.c index 3479bf7e..dafb6121 100644 --- a/dtls.c +++ b/dtls.c @@ -246,7 +246,7 @@ memarray_init(&dtlscontext_storage, dtlscontext_storage_data, */ #define CALL(Context, which, ...) \ ((Context)->h && (Context)->h->which \ - ? (Context)->h->which((Context), ##__VA_ARGS__) \ + ? (Context)->h->which((Context), __VA_ARGS__) \ : -1) static int diff --git a/sha2/sha2.c b/sha2/sha2.c index 633c3a91..9acec04c 100644 --- a/sha2/sha2.c +++ b/sha2/sha2.c @@ -224,6 +224,7 @@ static inline sha2_word64 get64be(const sha2_byte* data) #endif /* BYTE_ORDER != LITTLE_ENDIAN */ } +#if defined(WITH_SHA512) || (defined(WITH_SHA384) && BYTE_ORDER == LITTLE_ENDIAN) static inline void put64be(sha2_byte* data, sha2_word64 val) { #if BYTE_ORDER == LITTLE_ENDIAN @@ -239,6 +240,7 @@ static inline void put64be(sha2_byte* data, sha2_word64 val) MEMCPY_BCOPY(data, &val, sizeof(val)); #endif /* BYTE_ORDER != LITTLE_ENDIAN */ } +#endif /* WITH_SHA512 || (WITH_SHA364 && BYTE_ORDER == LITTLE_ENDIAN) */ /* * Macro for incrementally adding the unsigned 64-bit integer n to the diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dc50bed8..06988ffd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,13 +25,22 @@ project(tinydtls-tests) add_executable(dtls-server dtls-server.c) target_link_libraries(dtls-server LINK_PUBLIC tinydtls) -target_compile_options(dtls-server PUBLIC -DTEST_INCLUDE -DDTLSv12 -DWITH_SHA256) +target_compile_options(dtls-server PUBLIC -Wall -DTEST_INCLUDE -DDTLSv12 -DWITH_SHA256) +if(${WARNING_TO_ERROR}) + target_compile_options(dtls-server PUBLIC -Werror) +endif() add_executable(ccm-test ccm-test.c) target_link_libraries(ccm-test LINK_PUBLIC tinydtls) -target_compile_options(ccm-test PUBLIC -DTEST_INCLUDE -DDTLSv12 -DWITH_SHA256) +target_compile_options(ccm-test PUBLIC -Wall -DTEST_INCLUDE -DDTLSv12 -DWITH_SHA256) +if(${WARNING_TO_ERROR}) + target_compile_options(ccm-test PUBLIC -Werror) +endif() add_executable(dtls-client dtls-client.c) target_link_libraries(dtls-client LINK_PUBLIC tinydtls) -target_compile_options(dtls-client PUBLIC -DTEST_INCLUDE -DDTLSv12 -DWITH_SHA256) +target_compile_options(dtls-client PUBLIC -Wall -DTEST_INCLUDE -DDTLSv12 -DWITH_SHA256) +if(${WARNING_TO_ERROR}) + target_compile_options(dtls-client PUBLIC -Werror) +endif()