Skip to content

Commit

Permalink
Update to Mbed TLS 3.3.0 (#1558)
Browse files Browse the repository at this point in the history
* Convert mbedtls to subproject

* Align cmake to subproject and mbedtls 3.3.0

* mdebtls 3.3.0

* Add cxx_std_20 for Windows build
  • Loading branch information
Lord-Grey authored Feb 5, 2023
1 parent f327b50 commit ef7ceb0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 105 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 0 additions & 37 deletions dependencies/CMakeLists-mbedtls.txt.in

This file was deleted.

76 changes: 9 additions & 67 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)
Expand Down Expand Up @@ -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 change: 1 addition & 0 deletions dependencies/external/mbedtls
Submodule mbedtls added at 8c8922
6 changes: 5 additions & 1 deletion libsrc/leddevice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -160,3 +163,4 @@ endif()
if(ENABLE_MDNS)
target_link_libraries(leddevice mdns)
endif()

0 comments on commit ef7ceb0

Please sign in to comment.