From 19f2cbf0e7066753476ff8c38c07a6f0df73a622 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Sat, 30 Jan 2021 16:50:01 +0100 Subject: [PATCH] - CMake build: add new configuration option CONFIG_USE_EXTERNAL_MBEDTLS_DYNLIB to allow build using externally built mbedtls DLL/shared object --- CMakeLists.txt | 12 ++++++++++++ hal/CMakeLists.txt | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31c84c23..50c7a7c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,11 @@ option(CONFIG_MMS_THREADLESS_STACK "Optimize stack for threadless operation (war option(CONFIG_ACTIVATE_TCP_KEEPALIVE "Activate TCP keepalive" ON) option(CONFIG_INCLUDE_GOOSE_SUPPORT "Build with GOOSE support" ON) +option(CONFIG_USE_EXTERNAL_MBEDTLS_DYNLIB "Build with pre-compiled mbedtls dynamic library" OFF) + +set(CONFIG_EXTERNAL_MBEDTLS_DYNLIB_PATH "${CMAKE_CURRENT_LIST_DIR}/third_party/mbedtls/mbedtls-2.16/library" CACHE STRING "Path to search for the mbedtls dynamic libraries" ) +set(CONFIG_EXTERNAL_MBEDTLS_INCLUDE_PATH "${CMAKE_CURRENT_LIST_DIR}/third_party/mbedtls/mbedtls-2.16/include" CACHE STRING "Path to search for the mbedtls include files" ) + # choose the library features which shall be included option(CONFIG_IEC61850_CONTROL_SERVICE "Build with support for IEC 61850 control features" ON) option(CONFIG_IEC61850_REPORT_SERVICE "Build with support for IEC 61850 reporting services" ON) @@ -114,8 +119,15 @@ if(MSVC AND MSVC_VERSION LESS 1800) ) endif(MSVC AND MSVC_VERSION LESS 1800) +if(CONFIG_USE_EXTERNAL_MBEDTLS_DYNLIB) +set(WITH_MBEDTLS 1) +set(USE_PREBUILD_MBEDTLS 1) +set(MBEDTLS_INCLUDE_DIR ${CONFIG_EXTERNAL_MBEDTLS_INCLUDE_PATH}) +endif(CONFIG_USE_EXTERNAL_MBEDTLS_DYNLIB) + if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/third_party/mbedtls/mbedtls-2.16) set(WITH_MBEDTLS 1) +set(MBEDTLS_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/third_party/mbedtls/mbedtls-2.16/include") endif(EXISTS ${CMAKE_CURRENT_LIST_DIR}/third_party/mbedtls/mbedtls-2.16) if(WITH_MBEDTLS) diff --git a/hal/CMakeLists.txt b/hal/CMakeLists.txt index b50f9937..2ca0ea94 100644 --- a/hal/CMakeLists.txt +++ b/hal/CMakeLists.txt @@ -115,18 +115,22 @@ ENDIF(WIN32) #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" ) #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" ) -if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../third_party/mbedtls/mbedtls-2.16) -message("Found mbedtls -> can compile with TLS support") +if(WITH_MBEDTLS) +message("Found mbedtls -> can compile HAL with TLS support") set(WITH_MBEDTLS 1) -endif(EXISTS ${CMAKE_CURRENT_LIST_DIR}/../third_party/mbedtls/mbedtls-2.16) +endif(WITH_MBEDTLS) if(WITH_MBEDTLS) include_directories( ${CMAKE_CURRENT_LIST_DIR}/tls/mbedtls - ${CMAKE_CURRENT_LIST_DIR}/../third_party/mbedtls/mbedtls-2.16/include + ${MBEDTLS_INCLUDE_DIR} ) +if(CONFIG_USE_EXTERNAL_MBEDTLS_DYNLIB) +link_directories(${CONFIG_EXTERNAL_MBEDTLS_DYNLIB_PATH}) +else() file(GLOB tls_SRCS ${CMAKE_CURRENT_LIST_DIR}/../third_party/mbedtls/mbedtls-2.16/library/*.c) +endif(CONFIG_USE_EXTERNAL_MBEDTLS_DYNLIB) add_definitions(-DMBEDTLS_CONFIG_FILE="mbedtls_config.h") @@ -165,6 +169,11 @@ IF(UNIX) ) ENDIF (CONFIG_SYSTEM_HAS_CLOCK_GETTIME) ENDIF(UNIX) + +IF(CONFIG_USE_EXTERNAL_MBEDTLS_DYNLIB) + target_link_libraries(hal mbedcrypto mbedx509 mbedtls) +ENDIF(CONFIG_USE_EXTERNAL_MBEDTLS_DYNLIB) + IF(MINGW) target_link_libraries(hal ws2_32 iphlpapi) ENDIF(MINGW)