diff --git a/CMakeLists.txt b/CMakeLists.txt index ad056466a..68dfcb03d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,6 +114,11 @@ if(MBEDTLS_PYTHON_EXECUTABLE) endif() +# We now potentially need to link all executables against PThreads, if available +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +set(THREADS_PREFER_PTHREAD_FLAG TRUE) +find_package(Threads) + # If this is the root project add longer list of available CMAKE_BUILD_TYPE values if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 5c297e0a1..49803416d 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -231,7 +231,7 @@ if(HAIKU) endif(HAIKU) if(LINK_WITH_PTHREAD) - set(libs ${libs} pthread) + set(libs ${libs} ${CMAKE_THREAD_LIBS_INIT}) endif() if(LINK_WITH_TRUSTED_STORAGE) diff --git a/programs/aes/CMakeLists.txt b/programs/aes/CMakeLists.txt index 81741020f..ccb8db564 100644 --- a/programs/aes/CMakeLists.txt +++ b/programs/aes/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables crypt_and_hash ) diff --git a/programs/cipher/CMakeLists.txt b/programs/cipher/CMakeLists.txt index b497e8a48..e925524f6 100644 --- a/programs/cipher/CMakeLists.txt +++ b/programs/cipher/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables cipher_aead_demo ) diff --git a/programs/fuzz/CMakeLists.txt b/programs/fuzz/CMakeLists.txt index 97b8fd2eb..c389029bc 100644 --- a/programs/fuzz/CMakeLists.txt +++ b/programs/fuzz/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(libs ${mbedtls_target} ${CMAKE_THREAD_LIBS_INIT} diff --git a/programs/hash/CMakeLists.txt b/programs/hash/CMakeLists.txt index 504a4052f..fcacf3ba4 100644 --- a/programs/hash/CMakeLists.txt +++ b/programs/hash/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables generic_sum hello diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt index 2f55c6122..cd0387a88 100644 --- a/programs/pkey/CMakeLists.txt +++ b/programs/pkey/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables_mbedtls dh_client dh_server diff --git a/programs/psa/CMakeLists.txt b/programs/psa/CMakeLists.txt index dd1b1a2a8..a8e4b0e37 100644 --- a/programs/psa/CMakeLists.txt +++ b/programs/psa/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables aead_demo crypto_examples diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt index c1184d118..594039535 100644 --- a/programs/random/CMakeLists.txt +++ b/programs/random/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(executables gen_entropy gen_random_ctr_drbg diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index 8047b9f15..ec2c86fb4 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -1,6 +1,3 @@ -set(THREADS_USE_PTHREADS_WIN32 true) -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) set(libs diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 3709276f5..f91f786b9 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(libs ${mbedtls_target} ) diff --git a/programs/test/cmake_subproject/CMakeLists.txt b/programs/test/cmake_subproject/CMakeLists.txt index 2f8ab2a3a..78bd5e792 100644 --- a/programs/test/cmake_subproject/CMakeLists.txt +++ b/programs/test/cmake_subproject/CMakeLists.txt @@ -1,9 +1,5 @@ cmake_minimum_required(VERSION 3.5.1) -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - # Test the target renaming support by adding a prefix to the targets built set(MBEDTLS_TARGET_PREFIX subproject_test_) diff --git a/programs/util/CMakeLists.txt b/programs/util/CMakeLists.txt index 6a8659e9b..cb6bc3d2d 100644 --- a/programs/util/CMakeLists.txt +++ b/programs/util/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(libs ${mbedcrypto_target} ) diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt index e41b4069e..43437f070 100644 --- a/programs/x509/CMakeLists.txt +++ b/programs/x509/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(libs ${mbedx509_target} ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cb54ea408..70f5bc929 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,3 @@ -set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -set(THREADS_PREFER_PTHREAD_FLAG TRUE) -find_package(Threads) - set(libs ${mbedtls_target} ${CMAKE_THREAD_LIBS_INIT}