Commit b18fe77e authored by Andreas Schuh's avatar Andreas Schuh

Fix check for pthreads library on Ubuntu.

parent b8f57174
...@@ -145,15 +145,25 @@ set (CMAKE_THREAD_PREFER_PTHREAD TRUE) ...@@ -145,15 +145,25 @@ set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package (ThreadsCXX) find_package (ThreadsCXX)
if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
set (GFLAGS_HAVE_PTHREAD TRUE) set (GFLAGS_HAVE_PTHREAD TRUE)
check_type_size (pthread_rwlock_t GFLAGS_HAVE_RWLOCK LANGUAGE CXX) check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX)
if (HAVE_RWLOCK)
set (GFLAGS_HAVE_RWLOCK TRUE)
else ()
set (GFLAGS_HAVE_RWLOCK FALSE)
endif ()
else () else ()
set (GFLAGS_HAVE_PTHREAD FALSE) set (GFLAGS_HAVE_PTHREAD FALSE)
endif () endif ()
if (UNIX AND NOT GFLAGS_HAVE_PTHREAD AND BUILD_gflags_LIB) if (UNIX AND NOT GFLAGS_HAVE_PTHREAD AND BUILD_gflags_LIB)
set_property (CACHE BUILD_gflags_LIB PROPERTY VALUE OFF) set_property (CACHE BUILD_gflags_LIB PROPERTY VALUE OFF)
if (CMAKE_HAVE_PTHREAD_H)
message (WARNING "Could not find the pthread(s) library."
" Disabling the build of the multi-threaded gflags library.")
else ()
message (WARNING "Could not find the <pthread.h> header file." message (WARNING "Could not find the <pthread.h> header file."
" Disabling the build of the multi-threaded gflags library.") " Disabling the build of the multi-threaded gflags library.")
endif ()
endif () endif ()
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
......
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void* runner(void*);
int res = 0;
#ifdef __CLASSIC_C__
int main(){
int ac;
char*av[];
#else
int main(int ac, char*av[]){
#endif
pthread_t tid[2];
pthread_create(&tid[0], 0, runner, (void*)1);
pthread_create(&tid[1], 0, runner, (void*)2);
#if defined(__BEOS__) && !defined(__ZETA__) // (no usleep on BeOS 5.)
usleep(1); // for strange behavior on single-processor sun
#endif
pthread_join(tid[0], 0);
pthread_join(tid[1], 0);
if(ac > 1000){return *av[0];}
return res;
}
void* runner(void* args)
{
int cc;
for ( cc = 0; cc < 10; cc ++ )
{
printf("%p CC: %d\n", args, cc);
}
res ++;
return 0;
}
...@@ -38,6 +38,7 @@ include (CheckCXXLibraryExists) ...@@ -38,6 +38,7 @@ include (CheckCXXLibraryExists)
include (CheckCXXSymbolExists) include (CheckCXXSymbolExists)
set(Threads_FOUND FALSE) set(Threads_FOUND FALSE)
# Do we have sproc? # Do we have sproc?
if(CMAKE_SYSTEM MATCHES IRIX AND NOT CMAKE_THREAD_PREFER_PTHREAD) if(CMAKE_SYSTEM MATCHES IRIX AND NOT CMAKE_THREAD_PREFER_PTHREAD)
CHECK_INCLUDE_FILES_CXX("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H) CHECK_INCLUDE_FILES_CXX("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H)
...@@ -95,14 +96,15 @@ else() ...@@ -95,14 +96,15 @@ else()
endif() endif()
if(NOT CMAKE_HAVE_THREADS_LIBRARY) if(NOT CMAKE_HAVE_THREADS_LIBRARY)
# If we did not found -lpthread, -lpthread, or -lthread, look for -pthread # If we did not found -lpthread, -lpthreads, or -lthread, look for -pthread
if("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG") if("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")
message(STATUS "Check if compiler accepts -pthread") message(STATUS "Check if compiler accepts -pthread")
configure_file ("${CMAKE_ROOT}/Modules/CheckForPthreads.c" "${CMAKE_BINARY_DIR}/CheckForPthreads.cxx" COPYONLY) configure_file ("${CMAKE_CURRENT_LIST_DIR}/CheckForPthreads.cxx"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckForPthreads.cxx" COPYONLY)
try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/CheckForPthreads.cxx ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckForPthreads.cxx
CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=-pthread;-DCMAKE_CXX_FLAGS:STRING=-fpermissive"
COMPILE_OUTPUT_VARIABLE OUTPUT) COMPILE_OUTPUT_VARIABLE OUTPUT)
if(THREADS_HAVE_PTHREAD_ARG) if(THREADS_HAVE_PTHREAD_ARG)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment