summaryrefslogtreecommitdiff
path: root/Modules/FindThreads.cmake
diff options
context:
space:
mode:
authorMattias Ellert <mattias.ellert@physics.uu.se>2021-11-03 09:43:37 +0100
committerBrad King <brad.king@kitware.com>2022-01-26 08:50:16 -0500
commit5efb6fb51602aa11d98a2baa1313ab9b857d2672 (patch)
tree70fe6c3ae98b9c06e93776d268fca155504af6c6 /Modules/FindThreads.cmake
parent74f14997c6b74ef596ee7be2a622056ae7cfe062 (diff)
downloadcmake-5efb6fb51602aa11d98a2baa1313ab9b857d2672.tar.gz
FindThreads: Honor THREADS_PREFER_PTHREAD_FLAG when pthread is found in libc
The `-pthread` flag tells the compiler/linker to link to additional libraries needed for thread support (e.g. libatomic on riscv64). The flag therefore should be used if requested using `THREADS_PREFER_PTHREAD_FLAG` also when the pthread functions are found in libc.
Diffstat (limited to 'Modules/FindThreads.cmake')
-rw-r--r--Modules/FindThreads.cmake19
1 files changed, 11 insertions, 8 deletions
diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake
index c6a3451f7b..ffd3352f96 100644
--- a/Modules/FindThreads.cmake
+++ b/Modules/FindThreads.cmake
@@ -164,18 +164,21 @@ if(CMAKE_HAVE_PTHREAD_H)
elseif(CMAKE_CXX_COMPILER_LOADED)
CHECK_CXX_SOURCE_COMPILES("${PTHREAD_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_PTHREAD)
endif()
- if(CMAKE_HAVE_LIBC_PTHREAD)
+
+ # Check for -pthread first if enabled. This is the recommended
+ # way, but not backwards compatible as one must also pass -pthread
+ # as compiler flag then.
+ if(THREADS_PREFER_PTHREAD_FLAG)
+ _check_pthreads_flag()
+ endif()
+
+ if(Threads_FOUND)
+ # do nothing, we are done
+ elseif(CMAKE_HAVE_LIBC_PTHREAD)
set(CMAKE_THREAD_LIBS_INIT "")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(Threads_FOUND TRUE)
else()
- # Check for -pthread first if enabled. This is the recommended
- # way, but not backwards compatible as one must also pass -pthread
- # as compiler flag then.
- if (THREADS_PREFER_PTHREAD_FLAG)
- _check_pthreads_flag()
- endif ()
-
if(CMAKE_SYSTEM MATCHES "GHS-MULTI")
_check_threads_lib(posix pthread_create CMAKE_HAVE_PTHREADS_CREATE)
endif()