[Openvpn-devel,S] Change in openvpn[master]: Fix building with cmake and mbed TLS

Message ID bc6f35d39a842decb186e0992745d9e6f2817291-HTML@gerrit.openvpn.net
State Superseded
Headers show
Series [Openvpn-devel,S] Change in openvpn[master]: Fix building with cmake and mbed TLS | expand

Commit Message

ordex (Code Review) Oct. 28, 2023, 2:54 p.m. UTC
Attention is currently required from: flichtenheld.

Hello flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/377?usp=email

to review the following change.


Change subject: Fix building with cmake and mbed TLS
......................................................................

Fix building with cmake and mbed TLS

Change-Id: I7fd9e730e87210d2b7d090c8f9c7c6734bd7374e
---
M CMakeLists.txt
M config.h.cmake.in
2 files changed, 19 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/77/377/1

Patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 376a060..2f57771 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,6 +32,8 @@ 
 endif ()
 
 option(MBED "BUILD with mbed" OFF)
+set(MBED_INCLUDE_PATH "" CACHE STRING "Path to mbed TLS include directory")
+set(MBED_LIBRARY_PATH "" CACHE STRING "Path to mbed library directory")
 option(WOLFSSL "BUILD with wolfSSL" OFF)
 option(ENABLE_LZ4 "BUILD with lz4" ON)
 option(ENABLE_LZO "BUILD with lzo" ON)
@@ -219,6 +221,13 @@ 
 check_type_size("struct msghdr" MSGHDR)
 set(CMAKE_EXTRA_INCLUDE_FILES)
 
+if (${MBED})
+    check_symbol_exists(mbedtls_ctr_drbg_update_ret mbedtls/ctr_drbg.h HAVE_CTR_DRBG_UPDATE_RET)
+    check_symbol_exists(mbedtls_ssl_conf_export_keys_ext_cb mbedtls/ssl.h HAVE_EXPORT_KEYING_MATERIAL)
+else ()
+    set (HAVE_EXPORT_KEYING_MATERIAL TRUE)
+endif ()
+
 find_program(IFCONFIG_PATH ifconfig)
 find_program(IPROUTE_PATH ip)
 find_program(ROUTE_PATH route)
@@ -237,7 +246,14 @@ 
 
 function(add_library_deps target)
     if (${MBED})
-        target_link_libraries(${target} -lmbedtls -lmbedx509 -lmbedcrypto)
+        if (NOT (MBED_INCLUDE_PATH STREQUAL "") )
+            target_include_directories(${target} PRIVATE ${MBED_INCLUDE_PATH})
+        endif ()
+        if(NOT (MBED_LIBRARY_PATH STREQUAL ""))
+            target_link_directories(${target} PRIVATE ${MBED_LIBRARY_PATH})
+        endif ()
+        
+        target_link_libraries(${target} PRIVATE -lmbedtls -lmbedx509 -lmbedcrypto)
     elseif (${WOLFSSL})
         pkg_search_module(wolfssl wolfssl REQUIRED)
         target_link_libraries(${target} PUBLIC ${wolfssl_LINK_LIBRARIES})
diff --git a/config.h.cmake.in b/config.h.cmake.in
index f2cdd39..633dfd6 100644
--- a/config.h.cmake.in
+++ b/config.h.cmake.in
@@ -118,7 +118,7 @@ 
 #cmakedefine HAVE_ERR_H
 
 /* Crypto library supports keying material exporter */
-#define HAVE_EXPORT_KEYING_MATERIAL 1
+#cmakedefine HAVE_EXPORT_KEYING_MATERIAL 1
 
 /* Define to 1 if you have the <fcntl.h> header file. */
 #cmakedefine HAVE_FCNTL_H
@@ -387,7 +387,7 @@ 
 #undef HAVE_VSNPRINTF
 
 /* we always assume a recent mbed TLS version */
-#define HAVE_CTR_DRBG_UPDATE_RET 1
+#cmakedefine HAVE_CTR_DRBG_UPDATE_RET
 
 /* Path to ifconfig tool */
 #define IFCONFIG_PATH "@IFCONFIG_PATH@"