summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/FindThreads.cmake71
1 files changed, 43 insertions, 28 deletions
diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake
index 403f98f..c183f42 100644
--- a/Modules/FindThreads.cmake
+++ b/Modules/FindThreads.cmake
@@ -9,14 +9,46 @@
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake)
+# Do we have sproc?
IF(CMAKE_SYSTEM MATCHES IRIX)
CHECK_INCLUDE_FILE("sys/prctl.h" CMAKE_HAVE_SPROC_H)
ENDIF(CMAKE_SYSTEM MATCHES IRIX)
-CHECK_INCLUDE_FILE("pthread.h" CMAKE_HAVE_PTHREAD_H)
-IF(CMAKE_HAVE_PTHREAD_H)
- IF(NOT CMAKE_HAVE_SPROC_H)
- IF(NOT APPLE)
+IF(CMAKE_HAVE_SPROC_H)
+ # We have sproc
+ SET(CMAKE_USE_SPROC_INIT 1)
+ELSE(CMAKE_HAVE_SPROC_H)
+ # Do we have pthreads?
+ CHECK_INCLUDE_FILE("pthread.h" CMAKE_HAVE_PTHREAD_H)
+ 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)
+ # Do we have -lpthreads
+ CHECK_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE)
+ IF(CMAKE_HAVE_PTHREADS_CREATE)
+ SET(CMAKE_THREAD_LIBS_INIT "-lpthreads")
+ SET(CMAKE_HAVE_THREADS_LIBRARY 1)
+ ENDIF(CMAKE_HAVE_PTHREADS_CREATE)
+ # Ok, how about -lpthread
+ CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE)
+ IF(CMAKE_HAVE_PTHREAD_CREATE)
+ SET(CMAKE_THREAD_LIBS_INIT "-lpthread")
+ SET(CMAKE_HAVE_THREADS_LIBRARY 1)
+ ENDIF(CMAKE_HAVE_PTHREAD_CREATE)
+ IF(CMAKE_SYSTEM MATCHES "SunOS.*")
+ # On sun also check for -lthread
+ CHECK_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE)
+ IF(CMAKE_HAVE_THR_CREATE)
+ SET(CMAKE_THREAD_LIBS_INIT "-lthread")
+ SET(CMAKE_HAVE_THREADS_LIBRARY 1)
+ ENDIF(CMAKE_HAVE_THR_CREATE)
+ ENDIF(CMAKE_SYSTEM MATCHES "SunOS.*")
+ ENDIF(NOT THREADS_HAVE_PTHREAD_ARG)
+
+ IF(NOT CMAKE_HAVE_THREADS_LIBRARY)
+ # If we did not found -lpthread, -lpthread, or -lthread, look for -pthread
IF("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")
MESSAGE(STATUS "Check if compiler accepts -pthread")
TRY_RUN(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG
@@ -38,31 +70,14 @@ IF(CMAKE_HAVE_PTHREAD_H)
"Determining if compiler accepts -pthread failed with the following output:\n${OUTPUT}\n\n")
ENDIF(THREADS_HAVE_PTHREAD_ARG)
ENDIF("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")
- ENDIF(NOT APPLE)
- IF(THREADS_HAVE_PTHREAD_ARG)
- SET(CMAKE_THREAD_LIBS_INIT "-pthread")
- ELSE(THREADS_HAVE_PTHREAD_ARG)
- CHECK_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE)
- IF(CMAKE_HAVE_PTHREADS_CREATE)
- SET(CMAKE_THREAD_LIBS_INIT "-lpthreads")
- ENDIF(CMAKE_HAVE_PTHREADS_CREATE)
- CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE)
- IF(CMAKE_HAVE_PTHREAD_CREATE)
- SET(CMAKE_THREAD_LIBS_INIT "-lpthread")
- ENDIF(CMAKE_HAVE_PTHREAD_CREATE)
- IF(CMAKE_SYSTEM MATCHES "SunOS.*")
- CHECK_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE)
- IF(CMAKE_HAVE_THR_CREATE)
- SET(CMAKE_THREAD_LIBS_INIT "-lthread")
- ENDIF(CMAKE_HAVE_THR_CREATE)
- ENDIF(CMAKE_SYSTEM MATCHES "SunOS.*")
- ENDIF(THREADS_HAVE_PTHREAD_ARG)
- ENDIF(NOT CMAKE_HAVE_SPROC_H)
-ENDIF(CMAKE_HAVE_PTHREAD_H)
-
-IF(CMAKE_HAVE_SPROC_H)
- SET(CMAKE_USE_SPROC_INIT 1)
+ IF(THREADS_HAVE_PTHREAD_ARG)
+ SET(CMAKE_THREAD_LIBS_INIT "-pthread")
+ ELSE(THREADS_HAVE_PTHREAD_ARG)
+ ENDIF(THREADS_HAVE_PTHREAD_ARG)
+ ENDIF(NOT CMAKE_HAVE_THREADS_LIBRARY)
+ ENDIF(CMAKE_HAVE_PTHREAD_H)
ENDIF(CMAKE_HAVE_SPROC_H)
+
IF(CMAKE_THREAD_LIBS_INIT)
SET(CMAKE_USE_PTHREADS_INIT 1)
ENDIF(CMAKE_THREAD_LIBS_INIT)