summaryrefslogtreecommitdiffstats
path: root/Modules/FindThreads.cmake
diff options
context:
space:
mode:
authorRolf Eike Beer <eike@sf-mail.de>2014-10-02 20:23:20 (GMT)
committerRolf Eike Beer <eike@sf-mail.de>2014-10-03 21:20:07 (GMT)
commit94a061d3729e203ba59e537470e230b9b493639d (patch)
treef01eb7a28288895ba671993e9dcc908ba84fe52d /Modules/FindThreads.cmake
parent99d34f46fa394a9daabb7ca959e1540ae3a41ef2 (diff)
downloadCMake-94a061d3729e203ba59e537470e230b9b493639d.zip
CMake-94a061d3729e203ba59e537470e230b9b493639d.tar.gz
CMake-94a061d3729e203ba59e537470e230b9b493639d.tar.bz2
FindThreads: use a macro for the repetitive thread library checks
Diffstat (limited to 'Modules/FindThreads.cmake')
-rw-r--r--Modules/FindThreads.cmake40
1 files changed, 17 insertions, 23 deletions
diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake
index 6050dcd..41444f5 100644
--- a/Modules/FindThreads.cmake
+++ b/Modules/FindThreads.cmake
@@ -45,6 +45,19 @@ if(CMAKE_SYSTEM_NAME MATCHES IRIX AND NOT CMAKE_THREAD_PREFER_PTHREAD)
CHECK_INCLUDE_FILES("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H)
endif()
+# Internal helper macro.
+# Do NOT even think about using it outside of this file!
+macro(_check_threads_lib LIBNAME FUNCNAME VARNAME)
+ if(NOT CMAKE_HAVE_THREADS_LIBRARY)
+ 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 ()
+endmacro()
+
if(CMAKE_HAVE_SPROC_H AND NOT CMAKE_THREAD_PREFER_PTHREAD)
# We have sproc
set(CMAKE_USE_SPROC_INIT 1)
@@ -67,30 +80,11 @@ else()
set(Threads_FOUND TRUE)
else()
- # 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)
- set(Threads_FOUND TRUE)
- else()
-
- # 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)
- set(Threads_FOUND TRUE)
-
- elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
+ _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_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)
- set(Threads_FOUND TRUE)
- endif()
- endif()
+ _check_threads_lib(thread thr_create CMAKE_HAVE_THR_CREATE)
endif()
endif()
endif()