summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2016-12-06 19:20:34 +0000
committerAlbrecht Schlosser <albrechts.fltk@online.de>2016-12-06 19:20:34 +0000
commit307dd033f0a803265a04db51a003a71c4be383dc (patch)
tree31890bd765f79abfb9f5c1d964d7be3b6bfe3bc4
parentda816dff5d8b5d3b49a19eeeddcdf9e8b80037cd (diff)
[CMake] Rewrite pthreads checks for compatibility with configure.
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
-rw-r--r--CMake/options.cmake91
-rw-r--r--CMake/resources.cmake8
2 files changed, 71 insertions, 28 deletions
diff --git a/CMake/options.cmake b/CMake/options.cmake
index 75c6946e4..3ffe574be 100644
--- a/CMake/options.cmake
+++ b/CMake/options.cmake
@@ -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)
@@ -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)
diff --git a/CMake/resources.cmake b/CMake/resources.cmake
index 37c0c08ef..4f380ecd5 100644
--- a/CMake/resources.cmake
+++ b/CMake/resources.cmake
@@ -30,7 +30,6 @@ 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)
@@ -38,6 +37,13 @@ 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}'")