diff options
author | Brad King <brad.king@kitware.com> | 2022-04-27 12:53:10 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-04-27 12:53:18 (GMT) |
commit | 4b63f2ca4aeda1206012942378463ec2894991c2 (patch) | |
tree | 6343523b926d521bca238442d3f0a86c8550eb59 | |
parent | 54f795538247e00dc6b61adf42d93fc7f6e612e2 (diff) | |
parent | c53748a3772ab7419e82e27fd49bf30ca7821383 (diff) | |
download | CMake-4b63f2ca4aeda1206012942378463ec2894991c2.zip CMake-4b63f2ca4aeda1206012942378463ec2894991c2.tar.gz CMake-4b63f2ca4aeda1206012942378463ec2894991c2.tar.bz2 |
Merge topic 'FindThreads-cleanup'
c53748a377 FindThreads: Factor out helper macro for libc check
564385194b FindThreads: Avoid repeating check for -pthread flag
41ef904e81 FindThreads: Simplify conditions for not-in-libc checks
cbe7550d99 FindThreads: Remove unnecessary condition
1ee8c545dd FindThreads: Clarify internal helper macro names
5b5cd92363 FindThreads: Drop strange SunOS+pthread.h+thr_create combination
c9bd462c08 FindThreads: Drop unused internal CMAKE_HAVE_THREADS_LIBRARY variable
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Acked-by: Rolf Eike Beer <eike@sf-mail.de>
Merge-request: !7207
-rw-r--r-- | Modules/FindThreads.cmake | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake index e4d6cf3..c1531a4 100644 --- a/Modules/FindThreads.cmake +++ b/Modules/FindThreads.cmake @@ -91,12 +91,27 @@ int main(void) # Internal helper macro. # Do NOT even think about using it outside of this file! -macro(_check_threads_lib LIBNAME FUNCNAME VARNAME) +macro(_threads_check_libc) + if(NOT Threads_FOUND) + if(CMAKE_C_COMPILER_LOADED) + CHECK_C_SOURCE_COMPILES("${PTHREAD_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_PTHREAD) + elseif(CMAKE_CXX_COMPILER_LOADED) + CHECK_CXX_SOURCE_COMPILES("${PTHREAD_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_PTHREAD) + endif() + if(CMAKE_HAVE_LIBC_PTHREAD) + set(CMAKE_THREAD_LIBS_INIT "") + set(Threads_FOUND TRUE) + endif() + endif () +endmacro() + +# Internal helper macro. +# Do NOT even think about using it outside of this file! +macro(_threads_check_lib LIBNAME FUNCNAME VARNAME) if(NOT Threads_FOUND) CHECK_LIBRARY_EXISTS(${LIBNAME} ${FUNCNAME} "" ${VARNAME}) if(${VARNAME}) set(CMAKE_THREAD_LIBS_INIT "-l${LIBNAME}") - set(CMAKE_HAVE_THREADS_LIBRARY 1) set(Threads_FOUND TRUE) endif() endif () @@ -104,7 +119,7 @@ endmacro() # Internal helper macro. # Do NOT even think about using it outside of this file! -macro(_check_pthreads_flag) +macro(_threads_check_flag_pthread) if(NOT Threads_FOUND) # If we did not find -lpthreads, -lpthread, or -lthread, look for -pthread if(NOT DEFINED THREADS_HAVE_PTHREAD_ARG) @@ -153,42 +168,29 @@ if(CMAKE_HAVE_PTHREAD_H) # We have pthread.h # Let's check for the library now. # - set(CMAKE_HAVE_THREADS_LIBRARY) - if(NOT THREADS_HAVE_PTHREAD_ARG) - # Check if pthread functions are in normal C library. - # We list some pthread functions in PTHREAD_C_CXX_TEST_SOURCE test code. - # If the pthread functions already exist in C library, we could just use - # them instead of linking to the additional pthread library. - if(CMAKE_C_COMPILER_LOADED) - CHECK_C_SOURCE_COMPILES("${PTHREAD_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_PTHREAD) - elseif(CMAKE_CXX_COMPILER_LOADED) - CHECK_CXX_SOURCE_COMPILES("${PTHREAD_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_PTHREAD) - endif() - if(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() - _check_threads_lib(pthreads pthread_create CMAKE_HAVE_PTHREADS_CREATE) - _check_threads_lib(pthread pthread_create CMAKE_HAVE_PTHREAD_CREATE) - if(CMAKE_SYSTEM_NAME MATCHES "SunOS") - # On sun also check for -lthread - _check_threads_lib(thread thr_create CMAKE_HAVE_THR_CREATE) - endif() - endif() + + # Check if pthread functions are in normal C library. + # We list some pthread functions in PTHREAD_C_CXX_TEST_SOURCE test code. + # If the pthread functions already exist in C library, we could just use + # them instead of linking to the additional pthread library. + _threads_check_libc() + + # 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) + _threads_check_flag_pthread() + endif () + + if(CMAKE_SYSTEM MATCHES "GHS-MULTI") + _threads_check_lib(posix pthread_create CMAKE_HAVE_PTHREADS_CREATE) endif() + _threads_check_lib(pthreads pthread_create CMAKE_HAVE_PTHREADS_CREATE) + _threads_check_lib(pthread pthread_create CMAKE_HAVE_PTHREAD_CREATE) - _check_pthreads_flag() + if (NOT THREADS_PREFER_PTHREAD_FLAG) + _threads_check_flag_pthread() + endif() endif() if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_PTHREAD) |