vcpkg/ports/mbedtls/enable-pthread.patch

99 lines
2.8 KiB
Diff
Raw Normal View History

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5f7d0d886..d65cfeb2b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,6 +7,7 @@ endif()
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)
@@ -174,6 +175,7 @@ else()
endif()
include_directories(include/)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/)
if(ENABLE_ZLIB_SUPPORT)
find_package(ZLIB)
@@ -183,6 +185,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(library)
add_subdirectory(include)
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index c2f2bd4e6..e110cd50c 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -1,9 +1,13 @@
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")
+ 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 5df962ef6..f205bf599 100644
--- a/include/mbedtls/config.h
+++ b/include/mbedtls/config.h
@@ -26,6 +26,8 @@
* This file is part of mbed TLS (https://tls.mbed.org)
*/
+#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 000000000..f6286ed9c
--- /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
diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt
index 9330cff9b..54a815ee7 100644
--- a/library/CMakeLists.txt
+++ b/library/CMakeLists.txt
@@ -128,7 +128,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 (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)