Refactor common PThreads CMake code

Move the flags and find of Threads to root CMakeLists.txt, rather
than duplicate these everywhere. Make explicit linking of library with
PThreads use the same mechanism.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
Paul Elliott 2024-01-24 18:05:53 +00:00
parent ed3ba3cc8e
commit 7fd162ec26
15 changed files with 6 additions and 52 deletions

View file

@ -114,6 +114,11 @@ if(MBEDTLS_PYTHON_EXECUTABLE)
endif() 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 this is the root project add longer list of available CMAKE_BUILD_TYPE values
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}

View file

@ -231,7 +231,7 @@ if(HAIKU)
endif(HAIKU) endif(HAIKU)
if(LINK_WITH_PTHREAD) if(LINK_WITH_PTHREAD)
set(libs ${libs} pthread) set(libs ${libs} ${CMAKE_THREAD_LIBS_INIT})
endif() endif()
if(LINK_WITH_TRUSTED_STORAGE) if(LINK_WITH_TRUSTED_STORAGE)

View file

@ -1,7 +1,3 @@
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
set(executables set(executables
crypt_and_hash crypt_and_hash
) )

View file

@ -1,7 +1,3 @@
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
set(executables set(executables
cipher_aead_demo cipher_aead_demo
) )

View file

@ -1,7 +1,3 @@
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
set(libs set(libs
${mbedtls_target} ${mbedtls_target}
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}

View file

@ -1,7 +1,3 @@
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
set(executables set(executables
generic_sum generic_sum
hello hello

View file

@ -1,7 +1,3 @@
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
set(executables_mbedtls set(executables_mbedtls
dh_client dh_client
dh_server dh_server

View file

@ -1,7 +1,3 @@
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
set(executables set(executables
aead_demo aead_demo
crypto_examples crypto_examples

View file

@ -1,7 +1,3 @@
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
set(executables set(executables
gen_entropy gen_entropy
gen_random_ctr_drbg gen_random_ctr_drbg

View file

@ -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) find_package(Threads)
set(libs set(libs

View file

@ -1,7 +1,3 @@
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
set(libs set(libs
${mbedtls_target} ${mbedtls_target}
) )

View file

@ -1,9 +1,5 @@
cmake_minimum_required(VERSION 3.5.1) 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 # Test the target renaming support by adding a prefix to the targets built
set(MBEDTLS_TARGET_PREFIX subproject_test_) set(MBEDTLS_TARGET_PREFIX subproject_test_)

View file

@ -1,7 +1,3 @@
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
set(libs set(libs
${mbedcrypto_target} ${mbedcrypto_target}
) )

View file

@ -1,7 +1,3 @@
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
set(libs set(libs
${mbedx509_target} ${mbedx509_target}
) )

View file

@ -1,7 +1,3 @@
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
set(libs set(libs
${mbedtls_target} ${mbedtls_target}
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}