1 # - Find the Pthreads library
2 # This module searches for the Pthreads library (including the
3 # pthreads-win32 port).
5 # This module defines these variables:
8 # True if the Pthreads library was found
10 # The location of the Pthreads library
11 # PTHREADS_INCLUDE_DIR
12 # The include directory of the Pthreads library
13 # PTHREADS_DEFINITIONS
14 # Preprocessor definitions to define (HAVE_PTHREAD_H is a fairly common
17 # This module responds to the PTHREADS_EXCEPTION_SCHEME
18 # variable on Win32 to allow the user to control the
19 # library linked against. The Pthreads-win32 port
20 # provides the ability to link against a version of the
21 # library with exception handling. IT IS NOT RECOMMENDED
22 # THAT YOU CHANGE PTHREADS_EXCEPTION_SCHEME TO ANYTHING OTHER THAN
23 # "C" because most POSIX thread implementations do not support stack
26 # PTHREADS_EXCEPTION_SCHEME
27 # C = no exceptions (default)
28 # (NOTE: This is the default scheme on most POSIX thread
29 # implementations and what you should probably be using)
30 # CE = C++ Exception Handling
31 # SE = Structure Exception Handling (MSVC only)
35 # Define a default exception scheme to link against
36 # and validate user choice.
38 IF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
39 # Assign default if needed
40 SET(PTHREADS_EXCEPTION_SCHEME "C")
41 ELSE(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
43 IF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
44 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
45 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
47 MESSAGE(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed")
49 ENDIF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
50 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
51 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
53 IF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
54 MESSAGE(FATAL_ERROR "Structured Exception Handling is only allowed for MSVC")
55 ENDIF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
57 ENDIF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
60 # Find the header file
62 FIND_PATH(PTHREADS_INCLUDE_DIR pthread.h)
70 pthreadV${PTHREADS_EXCEPTION_SCHEME}2
75 pthreadG${PTHREADS_EXCEPTION_SCHEME}2
78 ELSE(MSVC) # Unix / Cygwin / Apple / Etc.
82 FIND_LIBRARY(PTHREADS_LIBRARY NAMES ${names}
83 DOC "The Portable Threads Library")
85 INCLUDE(FindPackageHandleStandardArgs)
86 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Pthreads DEFAULT_MSG
87 PTHREADS_LIBRARY PTHREADS_INCLUDE_DIR)
89 IF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
90 SET(PTHREADS_DEFINITIONS -DHAVE_PTHREAD_H)
91 SET(PTHREADS_INCLUDE_DIRS ${PTHREADS_INCLUDE_DIR})
92 SET(PTHREADS_LIBRARIES ${PTHREADS_LIBRARY})
93 ENDIF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
95 MARK_AS_ADVANCED(PTHREADS_INCLUDE_DIR)
96 MARK_AS_ADVANCED(PTHREADS_LIBRARY)