summaryrefslogtreecommitdiff
path: root/Modules/FindThreads.cmake
diff options
context:
space:
mode:
authorCarlo Marcelo Arenas Belón <carenas@gmail.com>2022-04-30 21:21:43 -0700
committerBrad King <brad.king@kitware.com>2022-05-03 12:26:18 -0400
commit3257c34073e53b09ed1bf83b012eb026b9897d07 (patch)
treef82063bddb7eaba6b7fcb8c719c58724cb69892b /Modules/FindThreads.cmake
parent833e9525830a916f9997daf5ca04686e366bd210 (diff)
downloadcmake-3257c34073e53b09ed1bf83b012eb026b9897d07.tar.gz
FindThreads: avoid failing in AIX when using -D_XOPEN_SOURCE=500
Current FindThreads fails in AIX (tested on 7.1 and 7.2) when using additional compilation flags (ex: -D_XOPEN_SOURCE=500) because the linker might need additional flags to link and those aren't yet known by the time check_include("pthread.h") is run (which is also the first test). Remove the check for it and all supporting code and rely instead on the compilation test that will be done later to find the correct syntax to use, and that confirms it exists implicitly.
Diffstat (limited to 'Modules/FindThreads.cmake')
-rw-r--r--Modules/FindThreads.cmake52
1 files changed, 19 insertions, 33 deletions
diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake
index c1531a4c24..a2304c2eb1 100644
--- a/Modules/FindThreads.cmake
+++ b/Modules/FindThreads.cmake
@@ -156,41 +156,27 @@ macro(_threads_check_flag_pthread)
endif()
endmacro()
-# Do we have pthreads?
-if(CMAKE_C_COMPILER_LOADED)
- CHECK_INCLUDE_FILE("pthread.h" CMAKE_HAVE_PTHREAD_H)
-else()
- CHECK_INCLUDE_FILE_CXX("pthread.h" CMAKE_HAVE_PTHREAD_H)
+# 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)
-if(CMAKE_HAVE_PTHREAD_H)
- #
- # We have pthread.h
- # Let's check for the library now.
- #
-
- # 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)
-
- if (NOT THREADS_PREFER_PTHREAD_FLAG)
- _threads_check_flag_pthread()
- endif()
+if (NOT THREADS_PREFER_PTHREAD_FLAG)
+ _threads_check_flag_pthread()
endif()
if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_PTHREAD)