ERR: Reorganize to try to fix the -pthread problem on some systems

This commit is contained in:
Andy Cedilnik 2003-08-22 09:52:05 -04:00
parent a413160fec
commit 21ec23413e
2 changed files with 55 additions and 34 deletions

View File

@ -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)

View File

@ -218,12 +218,14 @@ cmake_try_run ()
# Run a make test. First argument is the make interpreter.
cmake_try_make ()
{
MAKE_PROC=$1
MAKE_PROC="$1"
MAKE_FLAGS="$2"
echo "Try: ${MAKE_PROC}"
${MAKE_PROC}
"${MAKE_PROC}" ${MAKE_FLAGS}
RES=$?
if [ "${RES}" -ne "0" ]; then
echo "${MAKE_PROC} does not work";return 1
echo "${MAKE_PROC} does not work"
return 1
fi
if [ ! -f "test" ] && [ ! -f "test.exe" ]; then
echo "${COMPILER} does not produce output"
@ -397,6 +399,7 @@ echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"
# Test Make
cmake_make_processor=
cmake_make_flags=
# If MAKE is set, use that for make processor, otherwise use list of known make
if [ -n "${MAKE}" ]; then
@ -411,14 +414,17 @@ mkdir "${cmake_bootstrap_dir}/${TMPFILE}"
cd "${cmake_bootstrap_dir}/${TMPFILE}"
cat>"Makefile"<<EOF
test: test.c
${cmake_c_compiler} -o test test.c
"${cmake_c_compiler}" -o test test.c
EOF
cat>"test.c"<<EOF
#include <stdio.h>
int main(){ printf("1\n"); return 0; }
EOF
if [ "x${cmake_parallel_make}" != "x" ]; then
cmake_make_flags="${cmake_make_flags} -j ${cmake_parallel_make}"
fi
for a in ${cmake_make_processors}; do
if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" >> cmake_bootstrap.log 2>&1; then
if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> cmake_bootstrap.log 2>&1; then
cmake_make_processor="${a}"
fi
done
@ -680,7 +686,7 @@ echo "---------------------------------------------"
# Run make to build bootstrap cmake
if [ "x${cmake_parallel_make}" != "x" ]; then
${cmake_make_processor} -j ${cmake_parallel_make}
${cmake_make_processor} ${cmake_make_flags}
else
${cmake_make_processor}
fi