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
This commit is contained in:
LordGrey 2023-02-05 14:19:25 +00:00 committed by GitHub
parent f327b5063e
commit ef7ceb0bbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 105 deletions

3
.gitmodules vendored
View File

@ -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

View File

@ -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}
)

View File

@ -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)

1
dependencies/external/mbedtls vendored Submodule

@ -0,0 +1 @@
Subproject commit 8c89224991adff88d53cd380f42a2baa36f91454

View File

@ -118,6 +118,9 @@ 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)
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_features(leddevice PRIVATE cxx_std_20)
endif()
endif()
endif()
@ -160,3 +163,4 @@ endif()
if(ENABLE_MDNS)
target_link_libraries(leddevice mdns)
endif()