1 # ==============================================================================
2 # This is a heavily modified version of FindPthreads.cmake for the pcap project.
3 # It's meant to find Pthreads-w32, an implementation of the
4 # Threads component of the POSIX 1003.1c 1995 Standard (or later)
5 # for Microsoft's WIndows.
7 # Apart from this notice, this module "enjoys" the following modifications:
9 # - changed its name to FindPthreads-w32.cmake to not conflict with FindThreads.cmake
11 # - users may be able to use the environment variable PTHREADS_ROOT to point
12 # cmake to the *root* of their Pthreads-w32 installation.
13 # Alternatively, PTHREADS_ROOT may also be set from cmake command line or GUI
14 # (-DPTHREADS_ROOT=/path/to/Pthreads-w32)
15 # Two other variables that can be defined in a similar fashion are
16 # PTHREAD_INCLUDE_PATH and PTHREAD_LIBRARY_PATH.
18 # - added some additional status/error messages
20 # - changed formating (uppercase to lowercare + indentation)
22 # - removed some stuff
24 # - when searching for Pthreads-win32 libraries, the directory structure of the
25 # pre-build binaries folder found in the pthreads-win32 CVS code repository is
26 # considered (e.i /Pre-built.2/lib/x64 /Pre-built.2/lib/x86)
28 # Send suggestion, patches, gifts and praises to pcap's developers.
29 # ==============================================================================
31 # Find the Pthreads library
32 # This module searches for the Pthreads-win32 library (including the
33 # pthreads-win32 port).
35 # This module defines these variables:
37 # PTHREADS_FOUND - True if the Pthreads library was found
38 # PTHREADS_LIBRARY - The location of the Pthreads library
39 # PTHREADS_INCLUDE_DIR - The include directory of the Pthreads library
40 # PTHREADS_DEFINITIONS - Preprocessor definitions to define (HAVE_PTHREAD_H is a fairly common one)
42 # This module responds to the PTHREADS_EXCEPTION_SCHEME
43 # variable on Win32 to allow the user to control the
44 # library linked against. The Pthreads-win32 port
45 # provides the ability to link against a version of the
46 # library with exception handling.
47 # IT IS NOT RECOMMENDED THAT YOU CHANGE PTHREADS_EXCEPTION_SCHEME
48 # TO ANYTHING OTHER THAN "C" because most POSIX thread implementations
49 # do not support stack unwinding.
51 # PTHREADS_EXCEPTION_SCHEME
52 # C = no exceptions (default)
53 # (NOTE: This is the default scheme on most POSIX thread
54 # implementations and what you should probably be using)
55 # CE = C++ Exception Handling
56 # SE = Structure Exception Handling (MSVC only)
60 # Define a default exception scheme to link against
61 # and validate user choice.
64 if(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
65 # Assign default if needed
66 set(PTHREADS_EXCEPTION_SCHEME "C")
67 else(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
69 if(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
70 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
71 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
73 message(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed")
75 endif(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
76 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
77 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
79 if(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
80 message(FATAL_ERROR "Structured Exception Handling is only allowed for MSVC")
81 endif(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
83 endif(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
86 set(PTHREADS_ROOT PATHS ${PTHREADS_ROOT} NO_DEFAULT_PATH)
88 set(PTHREADS_ROOT $ENV{PTHREADS_ROOT})
92 # Find the header file
94 find_path(PTHREADS_INCLUDE_DIR
97 $ENV{PTHREAD_INCLUDE_PATH}
98 ${PTHREADS_ROOT}/include
101 if(PTHREADS_INCLUDE_DIR)
102 message(STATUS "Found pthread.h: ${PTHREADS_INCLUDE_DIR}")
104 # message(FATAL_ERROR "Could not find pthread.h. See README.Win32 for more information.")
105 endif(PTHREADS_INCLUDE_DIR)
113 pthreadV${PTHREADS_EXCEPTION_SCHEME}2
118 pthreadG${PTHREADS_EXCEPTION_SCHEME}2
123 if(CMAKE_SIZEOF_VOID_P EQUAL 4)
125 elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
129 find_library(PTHREADS_LIBRARY NAMES ${names}
130 DOC "The Portable Threads Library"
132 ${CMAKE_SOURCE_DIR}/lib
133 $ENV{PTHREAD_LIBRARY_PATH}
136 PATH_SUFFIXES lib/${SUBDIR}
140 message(STATUS "Found PTHREADS library: ${PTHREADS_LIBRARY} (PTHREADS Exception Scheme: ${PTHREADS_EXCEPTION_SCHEME})")
142 # message(FATAL_ERROR "Could not find PTHREADS LIBRARY. See README.Win32 for more information.")
143 endif(PTHREADS_LIBRARY)
145 if(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
146 set(PTHREADS_DEFINITIONS -DHAVE_PTHREAD_H)
147 set(PTHREADS_INCLUDE_DIRS ${PTHREADS_INCLUDE_DIR})
148 set(PTHREADS_LIBRARIES ${PTHREADS_LIBRARY})
149 set(PTHREADS_FOUND TRUE)
150 endif(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
152 mark_as_advanced(PTHREADS_INCLUDE_DIR PTHREADS_LIBRARY)