vcpkg/ports/mbedtls/enable-pthread.patch
Jia Yue Hua 31b799f92c
[mbedtls] update to 2.28.7 (#36431)
* [mbedtls] update to 2.28.7

* [mbedtls] update to 2.28.7
2024-01-29 11:44:37 -08:00

103 lines
2.8 KiB
Diff
Executable File

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b001bb7..b9fb566 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,6 +44,7 @@ set(MBEDTLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
option(USE_PKCS11_HELPER_LIBRARY "Build Mbed TLS with the pkcs11-helper library." OFF)
option(ENABLE_ZLIB_SUPPORT "Build Mbed TLS with zlib library." OFF)
+option(ENABLE_PTHREAD "Build Mbed TLS with pthread" OFF)
option(ENABLE_PROGRAMS "Build Mbed TLS programs." ON)
@@ -263,6 +264,8 @@ else()
set(LIB_INSTALL_DIR lib)
endif()
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
+
if(ENABLE_ZLIB_SUPPORT)
find_package(ZLIB)
@@ -271,6 +274,17 @@ if(ENABLE_ZLIB_SUPPORT)
endif(ZLIB_FOUND)
endif(ENABLE_ZLIB_SUPPORT)
+if(ENABLE_PTHREAD)
+ if(WIN32)
+ find_package(pthreads_windows REQUIRED)
+ include_directories(${PThreads4W_INCLUDE_DIR})
+ else()
+ set(CMAKE_THREAD_PREFER_PTHREAD ON)
+ find_package(Threads REQUIRED)
+ endif()
+ set(LINK_WITH_PTHREAD ON)
+endif()
+
add_subdirectory(include)
add_subdirectory(3rdparty)
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 11b417b..5ca44c3 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -1,10 +1,14 @@
option(INSTALL_MBEDTLS_HEADERS "Install Mbed TLS headers." ON)
+configure_file(mbedtls/config_threading.h.in mbedtls/config_threading.h)
+
if(INSTALL_MBEDTLS_HEADERS)
file(GLOB headers "mbedtls/*.h")
file(GLOB psa_headers "psa/*.h")
-
+
+ set(headers ${headers} ${CMAKE_CURRENT_BINARY_DIR}/mbedtls/config_threading.h)
+
install(FILES ${headers}
DESTINATION include/mbedtls
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
diff --git a/include/mbedtls/config.h b/include/mbedtls/config.h
index ac2146e..4cd831a 100644
--- a/include/mbedtls/config.h
+++ b/include/mbedtls/config.h
@@ -12,6 +12,8 @@
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/
+#include "mbedtls/config_threading.h"
+
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
diff --git a/include/mbedtls/config_threading.h.in b/include/mbedtls/config_threading.h.in
new file mode 100644
index 0000000..9d5d42e
--- /dev/null
+++ b/include/mbedtls/config_threading.h.in
@@ -0,0 +1,6 @@
+#cmakedefine ENABLE_PTHREAD
+
+#ifdef ENABLE_PTHREAD
+#define MBEDTLS_THREADING_C
+#define MBEDTLS_THREADING_PTHREAD
+#endif
\ No newline at end of file
diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt
index 1b2980d..8c495fe 100644
--- a/library/CMakeLists.txt
+++ b/library/CMakeLists.txt
@@ -149,7 +149,11 @@ if(ENABLE_ZLIB_SUPPORT)
endif(ENABLE_ZLIB_SUPPORT)
if(LINK_WITH_PTHREAD)
- set(libs ${libs} pthread)
+ if(WIN32)
+ set(libs ${libs} ${PThreads4W_LIBRARY})
+ else()
+ set(libs ${libs} pthread)
+ endif()
endif()
if(LINK_WITH_TRUSTED_STORAGE)