diff --git a/CMakeLists.txt b/CMakeLists.txt index 844491778..aa81d01f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,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) @@ -264,6 +265,8 @@ if(LIB_INSTALL_DIR) set(CMAKE_INSTALL_LIBDIR "${LIB_INSTALL_DIR}") endif() +include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) + if(ENABLE_ZLIB_SUPPORT) find_package(ZLIB) @@ -272,6 +275,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 11b417bd3..5ca44c341 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 4842fd494..fbce34128 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 48e51a158..4e752f777 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)