FindThreads: Revert "Honor THREADS_PREFER_PTHREAD_FLAG when ... in libc"

Revert commit 5efb6fb516 (FindThreads: Honor THREADS_PREFER_PTHREAD_FLAG
when pthread is found in libc, 2021-11-03, v3.21.5~4^2).  The check for
the `-pthread` flag can pass on compilers like XL, that interprets it as
`-p -t hread` and returns zero.  Prior to that commit, we did not use
the check in the `CMAKE_HAVE_LIBC_PTHREAD` code path.  Now we do, it
succeeds, and we incorrectly add the `-pthread` flag for XL.

This change was backported to the 3.21 and 3.22 release series long
after they initially came out.  Since there may be more cases where we
now add `-pthread` incorrectly, it is simplest to revert the change in
all release series pending further investigation.

Fixes: #23270
This commit is contained in:
Brad King
2022-02-28 12:53:15 -05:00
parent 6fe5df13c2
commit c6da90bd39

View File

@@ -164,21 +164,18 @@ if(CMAKE_HAVE_PTHREAD_H)
elseif(CMAKE_CXX_COMPILER_LOADED)
CHECK_CXX_SOURCE_COMPILES("${PTHREAD_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_PTHREAD)
endif()
# 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)
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()