From ef7ceb0bbfa7e6ae1f16b3158874c6da933397c8 Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Sun, 5 Feb 2023 14:19:25 +0000 Subject: [PATCH] Update to Mbed TLS 3.3.0 (#1558) * Convert mbedtls to subproject * Align cmake to subproject and mbedtls 3.3.0 * mdebtls 3.3.0 * Add cxx_std_20 for Windows build --- .gitmodules | 3 + dependencies/CMakeLists-mbedtls.txt.in | 37 ------------- dependencies/CMakeLists.txt | 76 +++----------------------- dependencies/external/mbedtls | 1 + libsrc/leddevice/CMakeLists.txt | 6 +- 5 files changed, 18 insertions(+), 105 deletions(-) delete mode 100644 dependencies/CMakeLists-mbedtls.txt.in create mode 160000 dependencies/external/mbedtls diff --git a/.gitmodules b/.gitmodules index 2fbcb55e8..624c175c6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -12,3 +12,6 @@ [submodule "dependencies/external/qmdnsengine"] path = dependencies/external/qmdnsengine url = https://github.com/nitroshare/qmdnsengine.git +[submodule "dependencies/external/mbedtls"] + path = dependencies/external/mbedtls + url = ../../Mbed-TLS/mbedtls.git diff --git a/dependencies/CMakeLists-mbedtls.txt.in b/dependencies/CMakeLists-mbedtls.txt.in deleted file mode 100644 index 76e177c7c..000000000 --- a/dependencies/CMakeLists-mbedtls.txt.in +++ /dev/null @@ -1,37 +0,0 @@ -cmake_minimum_required(VERSION 3.2) - -project(mbedtls) - -set(DOWNLOAD_DIR "@MBEDTLS_DOWNLOAD_DIR@") -set(SOURCE_DIR "@MBEDTLS_SOURCE_DIR@") -set(BINARY_DIR "@MBEDTLS_BINARY_DIR@") -set(INSTALL_DIR "@MBEDTLS_INSTALL_DIR@") -set(CMAKE_ARGS "@MBEDTLS_CMAKE_ARGS@") -set(LOGGING "@MBEDTLS_LOGGING@") - -include(ExternalProject) - -ExternalProject_Add( - mbedtls - GIT_REPOSITORY "https://github.com/ARMmbed/mbedtls.git" - GIT_TAG "v3.1.0" # Bump versions manually if necessary, do not rely on origin/master to be stable - BUILD_ALWAYS OFF - DOWNLOAD_DIR "${DOWNLOAD_DIR}" - SOURCE_DIR "${SOURCE_DIR}" - BINARY_DIR "${BINARY_DIR}" - INSTALL_DIR "${INSTALL_DIR}" - CMAKE_ARGS ${CMAKE_ARGS} - CONFIGURE_COMMAND "" - UPDATE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - LOG_DOWNLOAD ${LOGGING} - LOG_UPDATE ${LOGGING} - LOG_PATCH ${LOGGING} - LOG_CONFIGURE ${LOGGING} - LOG_BUILD ${LOGGING} - LOG_INSTALL ${LOGGING} - LOG_TEST ${LOGGING} - LOG_MERGED_STDOUTERR ${LOGGING} - LOG_OUTPUT_ON_FAILURE ${LOGGING} -) diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt index af2232abd..858454eee 100644 --- a/dependencies/CMakeLists.txt +++ b/dependencies/CMakeLists.txt @@ -265,15 +265,19 @@ if(ENABLE_DEV_NETWORK) set(DEFAULT_USE_SYSTEM_MBEDTLS_LIBS OFF PARENT_SCOPE) set(USE_SYSTEM_MBEDTLS_LIBS OFF) endif (NOT MBEDTLS_FOUND) - endif (USE_SYSTEM_MBEDTLS_LIBS) - - if (NOT USE_SYSTEM_MBEDTLS_LIBS) +else() cmake_minimum_required(VERSION 3.2) + + set(CMAKE_POLICY_DEFAULT_CMP0071 NEW) + set(DEFAULT_USE_SYSTEM_MBEDTLS_LIBS OFF CACHE BOOL "system mbedtls libraries not found, disable use system mbedtls libraries") set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared mbedtls libraries") set(ENABLE_TESTING OFF CACHE BOOL "Disable mbedTLS tests") + set(GEN_FILES OFF CACHE BOOL "Disable mbedTLS auto-generated files") set(ENABLE_PROGRAMS OFF CACHE BOOL "Disable mbedTLS programs") + #set(LINK_WITH_PTHREAD ON CACHE BOOL "Enable mbedTLS library linked to pthread.") + set(USE_SHARED_MBEDTLS_LIBRARY OFF CACHE BOOL "Disable mbedTLS shared libraries") set(USE_STATIC_MBEDTLS_LIBRARY ON CACHE BOOL "Enable mbedTLS static libraries") @@ -287,69 +291,7 @@ if(ENABLE_DEV_NETWORK) set(MBEDTLS_LOGGING 0) endif () - set(MBEDTLS_CMAKE_ARGS - -DCMAKE_INSTALL_PREFIX:PATH=${MBEDTLS_INSTALL_DIR} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} - -DUSE_SHARED_MBEDTLS_LIBRARY:BOOL=OFF - -DUSE_STATIC_MBEDTLS_LIBRARY:BOOL=ON - -DENABLE_TESTING:BOOL=OFF - -DENABLE_PROGRAMS:BOOL=OFF - -DLINK_WITH_PTHREAD:BOOL=ON - -Wno-dev - #-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=TRUE - ) - - set(ENABLE_MBEDTLS_FETCH_CONTENT ON) - - if (ENABLE_MBEDTLS_FETCH_CONTENT AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.11) - - include(FetchContent) - - FetchContent_Declare( - mbedtls - GIT_REPOSITORY https://github.com/ARMmbed/mbedtls.git - GIT_TAG "v3.1.0" # Bump versions manually if necessary, do not rely on origin/master to be stable - BUILD_ALWAYS OFF - GIT_PROGRESS 1 - DOWNLOAD_DIR "${MBEDTLS_DOWNLOAD_DIR}" - SOURCE_DIR "${MBEDTLS_SOURCE_DIR}" - BINARY_DIR "${MBEDTLS_BINARY_DIR}" - INSTALL_DIR "${MBEDTLS_INSTALL_DIR}" - CMAKE_ARGS ${MBEDTLS_CMAKE_ARGS} - BUILD_COMMAND "" - INSTALL_COMMAND "" - LOG_DOWNLOAD ${MBEDTLS_LOGGING} - LOG_UPDATE ${MBEDTLS_LOGGING} - LOG_PATCH ${MBEDTLS_LOGGING} - LOG_CONFIGURE ${MBEDTLS_LOGGING} - LOG_BUILD ${MBEDTLS_LOGGING} - LOG_INSTALL ${MBEDTLS_LOGGING} - LOG_TEST ${MBEDTLS_LOGGING} - LOG_MERGED_STDOUTERR ${MBEDTLS_LOGGING} - LOG_OUTPUT_ON_FAILURE ${MBEDTLS_LOGGING} - ) - - if (CMAKE_VERSION VERSION_LESS 3.14) - macro (FetchContent_MakeAvailable NAME) - FetchContent_GetProperties(${NAME}) - if (NOT ${NAME}_POPULATED) - FetchContent_Populate(${NAME}) - add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR}) - endif () - endmacro () - endif () - - FetchContent_MakeAvailable(mbedtls) - else () - set(ENABLE_MBEDTLS_FETCH_CONTENT OFF PARENT_SCOPE) - if(NOT DEFINED BUILD_MBEDTLS_ONCE) - set(BUILD_MBEDTLS_ONCE CACHE INTERNAL "Done") - configure_file(${CMAKE_SOURCE_DIR}/dependencies/CMakeLists-mbedtls.txt.in ${MBEDTLS_DOWNLOAD_DIR}/CMakeLists.txt @ONLY) - execute_process(COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX:PATH=${MBEDTLS_INSTALL_DIR} -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -G "${CMAKE_GENERATOR}" . WORKING_DIRECTORY ${MBEDTLS_DOWNLOAD_DIR}) - execute_process(COMMAND ${CMAKE_COMMAND} --build . WORKING_DIRECTORY ${MBEDTLS_DOWNLOAD_DIR}) - add_subdirectory(${MBEDTLS_SOURCE_DIR} ${MBEDTLS_BINARY_DIR}) - endif() - endif () + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/mbedtls) set (MBEDTLS_INCLUDE_DIR "${MBEDTLS_SOURCE_DIR}/include") set (MBEDTLS_INCLUDE_DIR ${MBEDTLS_INCLUDE_DIR} PARENT_SCOPE) @@ -387,5 +329,5 @@ if(ENABLE_DEV_NETWORK) mark_as_advanced (MBEDTLS_INCLUDE_DIR MBEDTLS_LIBRARIES MBEDTLS_SSL_LIBRARY MBEDTLS_X509_LIBRARY MBEDTLS_CRYPTO_LIBRARY) - endif (NOT USE_SYSTEM_MBEDTLS_LIBS) + endif (USE_SYSTEM_MBEDTLS_LIBS) endif(ENABLE_DEV_NETWORK) diff --git a/dependencies/external/mbedtls b/dependencies/external/mbedtls new file mode 160000 index 000000000..8c8922499 --- /dev/null +++ b/dependencies/external/mbedtls @@ -0,0 +1 @@ +Subproject commit 8c89224991adff88d53cd380f42a2baa36f91454 diff --git a/libsrc/leddevice/CMakeLists.txt b/libsrc/leddevice/CMakeLists.txt index 4da16a1da..233bb9fd2 100644 --- a/libsrc/leddevice/CMakeLists.txt +++ b/libsrc/leddevice/CMakeLists.txt @@ -118,7 +118,10 @@ if(ENABLE_DEV_NETWORK) string(REGEX MATCH "[0-9]+|-([A-Za-z0-9_.]+)" MBEDTLS_MAJOR ${MBEDTLS_VERSION}) if (MBEDTLS_MAJOR EQUAL "3") target_compile_definitions(leddevice PRIVATE USE_MBEDTLS3) - endif() + if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + target_compile_features(leddevice PRIVATE cxx_std_20) + endif() + endif() endif() if(ENABLE_DEV_SERIAL) @@ -160,3 +163,4 @@ endif() if(ENABLE_MDNS) target_link_libraries(leddevice mdns) endif() +