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.
39 IF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
40 SET(PTHREADS_DEFINITIONS -DHAVE_PTHREAD_H)
41 SET(PTHREADS_INCLUDE_DIRS ${PTHREADS_INCLUDE_DIR})
42 SET(PTHREADS_LIBRARIES ${PTHREADS_LIBRARY})
43 SET(FOUND_PTHREADS TRUE)
46 IF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
47 # Assign default if needed
48 SET(PTHREADS_EXCEPTION_SCHEME "C")
49 ELSE(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
51 IF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
52 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
53 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
55 MESSAGE(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed")
57 ENDIF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
58 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
59 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
61 IF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
62 MESSAGE(FATAL_ERROR "Structured Exception Handling is only allowed for MSVC")
63 ENDIF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
65 ENDIF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
68 # Find the header file
70 FIND_PATH(PTHREADS_INCLUDE_DIR pthread.h)
78 pthreadV${PTHREADS_EXCEPTION_SCHEME}2
83 pthreadG${PTHREADS_EXCEPTION_SCHEME}2
86 ELSE(MSVC) # Unix / Cygwin / Apple / Etc.
90 FIND_LIBRARY(PTHREADS_LIBRARY NAMES ${names}
91 DOC "The Portable Threads Library")
93 INCLUDE(FindPackageHandleStandardArgs)
94 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Pthreads DEFAULT_MSG
95 PTHREADS_LIBRARY PTHREADS_INCLUDE_DIR)
97 IF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
98 SET(PTHREADS_DEFINITIONS -DHAVE_PTHREAD_H)
99 SET(PTHREADS_INCLUDE_DIRS ${PTHREADS_INCLUDE_DIR})
100 SET(PTHREADS_LIBRARIES ${PTHREADS_LIBRARY})
101 ENDIF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
103 MARK_AS_ADVANCED(PTHREADS_INCLUDE_DIR)
104 MARK_AS_ADVANCED(PTHREADS_LIBRARY)