Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use FindThreads to check for pthreading
authorMatthieu Volat <mazhe@alkumuna.eu>
Tue, 23 May 2017 17:15:16 +0000 (19:15 +0200)
committerdegomme <augustin.degomme@unibas.ch>
Tue, 23 May 2017 19:31:55 +0000 (21:31 +0200)
It will prefer using threading as library if possible, and fallback
on -pthread only if necessary, which some compilers/systems
do not support anymore.

CMakeLists.txt
tools/cmake/MakeLib.cmake

index 06d2f1c..cde287e 100644 (file)
@@ -60,6 +60,9 @@ if(APPLE AND (CMAKE_C_COMPILER_VERSION VERSION_LESS "4.6"))
   set(HAVE_UCONTEXT_H 0)
 endif()
 
+### Check threading support
+set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
+find_package(Threads)
 
 ### Setup Options
 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Option.cmake)
@@ -274,7 +277,6 @@ endif()
 # Checks for header libraries functions.
 CHECK_LIBRARY_EXISTS(rt      clock_gettime           "" HAVE_POSIX_GETTIME)
 
-CHECK_LIBRARY_EXISTS(pthread pthread_create          "" HAVE_PTHREAD)
 if(NOT APPLE) # OS X El Capitan deprecates this function
   CHECK_LIBRARY_EXISTS(pthread sem_init                "" HAVE_SEM_INIT_LIB)
 endif()
@@ -460,7 +462,7 @@ endif()
 ### Initialize of CONTEXT THREADS
 
 set(HAVE_THREAD_CONTEXTS 0)
-if(HAVE_PTHREAD)
+if(CMAKE_USE_PTHREADS_INIT)
   ### Test that we have a way to create semaphores
 
   if(HAVE_SEM_OPEN_LIB)
index 1378bd4..d116926 100644 (file)
@@ -34,9 +34,8 @@ if (HAVE_BOOST_CONTEXTS)
   set(SIMGRID_DEP "${SIMGRID_DEP} ${Boost_CONTEXT_LIBRARY}")
 endif()
 
-if(HAVE_PTHREAD AND ${HAVE_THREAD_CONTEXTS} AND NOT APPLE)
-  # Clang on recent Mac OS X is not happy about -pthread.
-  SET(SIMGRID_DEP "${SIMGRID_DEP} -pthread")
+if(CMAKE_USE_PTHREADS_INIT AND ${HAVE_THREAD_CONTEXTS})
+  set(SIMGRID_DEP "${SIMGRID_DEP} ${CMAKE_THREAD_LIBS_INIT}")
 endif()
 
 if(SIMGRID_HAVE_LUA)