Skip to content

Commit

Permalink
[CMake] Rewrite pthreads checks for compatibility with configure.
Browse files Browse the repository at this point in the history
Main point: pthreads must not be checked under Windows (e.g. MinGW)
since Windows always uses native Windows threads (unless Cygwin is used).


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12138 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Albrecht Schlosser committed Dec 6, 2016
1 parent da816df commit 307dd03
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 28 deletions.
91 changes: 64 additions & 27 deletions CMake/options.cmake
Expand Up @@ -63,6 +63,7 @@ if((NOT APPLE OR OPTION_APPLE_X11) AND NOT WIN32)
endif(X11_Xext_FOUND)
endif(X11_FOUND)
endif((NOT APPLE OR OPTION_APPLE_X11) AND NOT WIN32)

if (OPTION_APPLE_X11)
include_directories(AFTER SYSTEM /opt/X11/include/freetype2)
endif (OPTION_APPLE_X11)
Expand Down Expand Up @@ -175,33 +176,69 @@ else()
endif(OPENGL_FOUND)

#######################################################################
option(OPTION_USE_THREADS "use multi-threading" ON)

if(OPTION_USE_THREADS)
include(FindThreads)
endif(OPTION_USE_THREADS)

if(OPTION_USE_THREADS AND CMAKE_HAVE_THREADS_LIBRARY)
add_definitions("-D_THREAD_SAFE -D_REENTRANT")
set(USE_THREADS 1)
set(FLTK_THREADS_FOUND TRUE)
else()
set(FLTK_THREADS_FOUND FALSE)
endif(OPTION_USE_THREADS AND CMAKE_HAVE_THREADS_LIBRARY)

if(OPTION_USE_THREADS AND CMAKE_USE_PTHREADS_INIT)
set(HAVE_PTHREAD 1)
if(NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
endif(NOT APPLE)
list(APPEND FLTK_LDLIBS -lpthread)
list(APPEND FLTK_CFLAGS -D_THREAD_SAFE -D_REENTRANT)
set(FLTK_PTHREADS_FOUND TRUE)
else()
set(HAVE_PTHREAD 0)
set(HAVE_PTHREAD_H 0)
set(FLTK_PTHREADS_FOUND FALSE)
endif(OPTION_USE_THREADS AND CMAKE_USE_PTHREADS_INIT)
# Create an option whether we want to check for pthreads.
# We must not do it on Windows unless we run under Cygwin, since we
# always use native threads on Windows (even if libpthread is available).

# Note: HAVE_PTHREAD_H has already been determined in resources.cmake
# before this file is included (or set to 0 for WIN32).

if (WIN32 AND NOT CYGWIN)
# set(HAVE_PTHREAD_H 0) # (see resources.cmake)
set(OPTION_USE_THREADS FALSE)
else ()
option(OPTION_USE_THREADS "use multi-threading with pthreads" ON)
endif (WIN32 AND NOT CYGWIN)

# initialize more variables
set(USE_THREADS 0)
set(HAVE_PTHREAD 0)
set(FLTK_PTHREADS_FOUND FALSE)

if (OPTION_USE_THREADS)

include(FindThreads)

if (CMAKE_HAVE_THREADS_LIBRARY)
add_definitions("-D_THREAD_SAFE -D_REENTRANT")
set(USE_THREADS 1)
set(FLTK_THREADS_FOUND TRUE)
endif (CMAKE_HAVE_THREADS_LIBRARY)

if (CMAKE_USE_PTHREADS_INIT AND NOT WIN32)
set(HAVE_PTHREAD 1)
if (NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
endif (NOT APPLE)
list(APPEND FLTK_LDLIBS -lpthread)
list(APPEND FLTK_CFLAGS -D_THREAD_SAFE -D_REENTRANT)
set(FLTK_PTHREADS_FOUND TRUE)
else()
set(HAVE_PTHREAD 0)
set(HAVE_PTHREAD_H 0)
set(FLTK_PTHREADS_FOUND FALSE)
endif(CMAKE_USE_PTHREADS_INIT AND NOT WIN32)

else (OPTION_USE_THREADS)

set(HAVE_PTHREAD_H 0)

endif (OPTION_USE_THREADS)

set(debug_threads FALSE) # set to true to show debug info
if (debug_threads)
message ("")
message (STATUS "NOTE: set debug_threads to FALSE to disable this info!")
message (STATUS "WIN32 = '${WIN32}'")
message (STATUS "MINGW = '${MINGW}'")
message (STATUS "CYGWIN = '${CYGWIN}'")
message (STATUS "OPTION_USE_THREADS = '${OPTION_USE_THREADS}'")
message (STATUS "HAVE_PTHREAD = '${HAVE_PTHREAD}'")
message (STATUS "HAVE_PTHREAD_H = '${HAVE_PTHREAD_H}'")
message (STATUS "FLTK_THREADS_FOUND = '${FLTK_THREADS_FOUND}'")
message (STATUS "CMAKE_EXE_LINKER_FLAGS = '${CMAKE_EXE_LINKER_FLAGS}'")
endif (debug_threads)
unset(debug_threads)

#######################################################################
option(OPTION_LARGE_FILE "enable large file support" ON)
Expand Down
8 changes: 7 additions & 1 deletion CMake/resources.cmake
Expand Up @@ -30,14 +30,20 @@ find_file(HAVE_LIBPNG_PNG_H libpng/png.h)
find_file(HAVE_LOCALE_H locale.h)
find_file(HAVE_OPENGL_GLU_H OpenGL/glu.h)
find_file(HAVE_PNG_H png.h)
find_file(HAVE_PTHREAD_H pthread.h)
find_file(HAVE_STDIO_H stdio.h)
find_file(HAVE_STRINGS_H strings.h)
find_file(HAVE_SYS_SELECT_H sys/select.h)
find_file(HAVE_SYS_STDTYPES_H sys/stdtypes.h)
find_file(HAVE_X11_XREGION_H X11/Xregion.h)
find_path(HAVE_XDBE_H Xdbe.h PATH_SUFFIXES X11/extensions extensions)

if (WIN32 AND NOT CYGWIN)
# we don't use pthreads on Windows (except for Cygwin, see options.cmake)
set(HAVE_PTHREAD_H 0)
else ()
find_file(HAVE_PTHREAD_H pthread.h)
endif (WIN32 AND NOT CYGWIN)

if (MSVC)
message(STATUS "Note: The following three headers should all be found!")
message(STATUS "HAVE_GL_GL_H = '${HAVE_GL_GL_H}'")
Expand Down

0 comments on commit 307dd03

Please sign in to comment.