From cbe7550d998def869d297b2bf6e3d9b8689e33de Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 14 Apr 2022 13:04:43 -0400 Subject: FindThreads: Remove unnecessary condition The `THREADS_HAVE_PTHREAD_ARG` cache entry cannot be defined unless FindThreads has already been executed, perhaps by a previous run of CMake, or a previous `find_package(Threads)` call. In that case, the other alternatives will also already have been checked and results cached. --- Modules/FindThreads.cmake | 51 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake index 13c8c5c..ed0bb8b 100644 --- a/Modules/FindThreads.cmake +++ b/Modules/FindThreads.cmake @@ -152,33 +152,32 @@ if(CMAKE_HAVE_PTHREAD_H) # We have pthread.h # Let's check for the library now. # - 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(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) - _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 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(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) + _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) endif() _threads_check_flag_pthread() -- cgit v0.12