]> The Tcpdump Group git mirrors - libpcap/blob - cmake/Modules/FindPthreads-w32.cmake
Fix typpo.
[libpcap] / cmake / Modules / FindPthreads-w32.cmake
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.
6 #
7 # Apart from this notice, this module "enjoys" the following modifications:
8 #
9 # - changed its name to FindPthreads-w32.cmake to not conflict with FindThreads.cmake
10 #
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.
17 #
18 # - added some additional status/error messages
19 #
20 # - changed formating (uppercase to lowercare + indentation)
21 #
22 # - removed some stuff
23 #
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)
27 #
28 # Send suggestion, patches, gifts and praises to pcap's developers.
29 # ==============================================================================
30 #
31 # Find the Pthreads library
32 # This module searches for the Pthreads-win32 library (including the
33 # pthreads-win32 port).
34 #
35 # This module defines these variables:
36 #
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)
41 #
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.
50 #
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)
57 #
58
59 #
60 # Define a default exception scheme to link against
61 # and validate user choice.
62 #
63 #
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)
68 # Validate
69 if(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
70 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
71 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
72
73 message(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed")
74
75 endif(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
76 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
77 NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
78
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")
82
83 endif(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
84
85 if(PTHREADS_ROOT)
86 set(PTHREADS_ROOT PATHS ${PTHREADS_ROOT} NO_DEFAULT_PATH)
87 else()
88 set(PTHREADS_ROOT $ENV{PTHREADS_ROOT})
89 endif(PTHREADS_ROOT)
90
91 #
92 # Find the header file
93 #
94 find_path(PTHREADS_INCLUDE_DIR
95 NAMES pthread.h
96 HINTS
97 $ENV{PTHREAD_INCLUDE_PATH}
98 ${PTHREADS_ROOT}/include
99 )
100
101 if(PTHREADS_INCLUDE_DIR)
102 message(STATUS "Found pthread.h: ${PTHREADS_INCLUDE_DIR}")
103 # else()
104 # message(FATAL_ERROR "Could not find pthread.h. See README.Win32 for more information.")
105 endif(PTHREADS_INCLUDE_DIR)
106
107 #
108 # Find the library
109 #
110 set(names)
111 if(MSVC)
112 set(names
113 pthreadV${PTHREADS_EXCEPTION_SCHEME}2
114 libpthread
115 )
116 elseif(MINGW)
117 set(names
118 pthreadG${PTHREADS_EXCEPTION_SCHEME}2
119 pthread
120 )
121 endif(MSVC)
122
123 if(CMAKE_SIZEOF_VOID_P EQUAL 4)
124 set(SUBDIR "/x86")
125 elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
126 set(SUBDIR "/x64")
127 endif()
128
129 find_library(PTHREADS_LIBRARY NAMES ${names}
130 DOC "The Portable Threads Library"
131 HINTS
132 ${CMAKE_SOURCE_DIR}/lib
133 $ENV{PTHREAD_LIBRARY_PATH}
134 ${PTHREADS_ROOT}
135 C:/MinGW/lib/
136 PATH_SUFFIXES lib/${SUBDIR}
137 )
138
139 if(PTHREADS_LIBRARY)
140 message(STATUS "Found PTHREADS library: ${PTHREADS_LIBRARY} (PTHREADS Exception Scheme: ${PTHREADS_EXCEPTION_SCHEME})")
141 # else()
142 # message(FATAL_ERROR "Could not find PTHREADS LIBRARY. See README.Win32 for more information.")
143 endif(PTHREADS_LIBRARY)
144
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)
151
152 mark_as_advanced(PTHREADS_INCLUDE_DIR PTHREADS_LIBRARY)