Parcourir la source

cmake compile support mbedtls

HypoYoung il y a 1 an
Parent
commit
01d1034aa0
2 fichiers modifiés avec 21 ajouts et 9 suppressions
  1. 5 0
      CMakeLists.txt
  2. 16 9
      src/CMakeLists.txt

+ 5 - 0
CMakeLists.txt

@@ -231,6 +231,9 @@ message(STATUS "Compile for OpenSSL 1.1 API - ${CIVETWEB_SSL_OPENSSL_API_1_1}")
 option(CIVETWEB_SSL_OPENSSL_API_3_0 "Use the OpenSSL 3.0 API" OFF)
 message(STATUS "Compile for OpenSSL 3.0 API - ${CIVETWEB_SSL_OPENSSL_API_3_0}")
 
+option(CIVETWEB_ENABLE_MBEDTLS "Use the MbedTls" OFF)
+message(STATUS "SSL support - ${CIVETWEB_ENABLE_MBEDTLS}")
+
 # Dynamically load or link the SSL libraries
 cmake_dependent_option(
   CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING "Dynamically loads the SSL library rather than linking it" ON
@@ -523,6 +526,8 @@ if (CIVETWEB_ENABLE_MEMORY_DEBUGGING)
 endif()
 if (NOT CIVETWEB_ENABLE_SSL)
   add_definitions(-DNO_SSL)
+elseif (CIVETWEB_ENABLE_MBEDTLS)
+  add_definitions(-DUSE_MBEDTLS)
 elseif (NOT CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING)
   add_definitions(-DNO_SSL_DL)
 else()

+ 16 - 9
src/CMakeLists.txt

@@ -47,16 +47,23 @@ endif()
 
 # We need to link OpenSSL if not dynamically loading
 if (CIVETWEB_ENABLE_SSL)
-  if (CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING)
-    find_package(LibDl)
-    if (LIBDL_FOUND)
-      target_link_libraries(civetweb-c-library -ldl)
-    endif()
+  if (CIVETWEB_ENBALE_MBEDTLS)
+    find_package(MbedTLS)
+    include_directories(${MbedTLS_INCLUDE_DIR})
+    message(STATUS "MbedTLS include directory: {MbedTLS_INCLUDE_DIR}")
+    target_link_libraries(civetweb-c-library ${MbedTLS_LIBRARIES})
   else()
-    find_package(OpenSSL)
-    include_directories(${OPENSSL_INCLUDE_DIR})
-    message(STATUS "OpenSSL include directory: ${OPENSSL_INCLUDE_DIR}")
-    target_link_libraries(civetweb-c-library ${OPENSSL_LIBRARIES})
+    if (CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING)
+      find_package(LibDl)
+      if (LIBDL_FOUND)
+        target_link_libraries(civetweb-c-library -ldl)
+      endif()
+    else()
+      find_package(OpenSSL)
+      include_directories(${OPENSSL_INCLUDE_DIR})
+      message(STATUS "OpenSSL include directory: ${OPENSSL_INCLUDE_DIR}")
+      target_link_libraries(civetweb-c-library ${OPENSSL_LIBRARIES})
+    endif()
   endif()
 endif()