A number of changes to gromacs_mrs. Almost working for new changes added Aug 4th,
[gromacs/rigid-bodies.git] / cmake / FindPthreads.cmake
blob5b0b1b635600fd457002d574500a510f70e9d5b9
1 # - Find the Pthreads library\r
2 # This module searches for the Pthreads library (including the\r
3 # pthreads-win32 port).\r
4 #\r
5 # This module defines these variables:\r
6 #\r
7 #  PTHREADS_FOUND\r
8 #      True if the Pthreads library was found\r
9 #  PTHREADS_LIBRARY\r
10 #      The location of the Pthreads library\r
11 #  PTHREADS_INCLUDE_DIR\r
12 #      The include path of the Pthreads library\r
13 #  PTHREADS_DEFINITIONS\r
14 #      Preprocessor definitions to define\r
15 #\r
16 # This module responds to the PTHREADS_EXCEPTION_SCHEME\r
17 # variable on Win32 to allow the user to control the\r
18 # library linked against.  The Pthreads-win32 port\r
19 # provides the ability to link against a version of the\r
20 # library with exception handling.  IT IS NOT RECOMMENDED\r
21 # THAT YOU USE THIS because most POSIX thread implementations\r
22 # do not support stack unwinding.\r
23 #\r
24 #  PTHREADS_EXCEPTION_SCHEME\r
25 #      C  = no exceptions (default)\r
26 #         (NOTE: This is the default scheme on most POSIX thread\r
27 #          implementations and what you should probably be using)\r
28 #      CE = C++ Exception Handling\r
29 #      SE = Structure Exception Handling (MSVC only)\r
30 #\r
32 #\r
33 # Define a default exception scheme to link against\r
34 # and validate user choice.\r
35 #\r
36 IF(PTHREADS_INCLUDE_DIR)\r
37   # Already in cache, be silent\r
38   SET(PTHREADS_FIND_QUIETLY TRUE)\r
39 ENDIF(PTHREADS_INCLUDE_DIR)\r
42 IF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)\r
43     # Assign default if needed\r
44     SET(PTHREADS_EXCEPTION_SCHEME "C")\r
45 ELSE(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)\r
46     # Validate\r
47     IF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND\r
48        NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND\r
49        NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")\r
51     MESSAGE(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed")\r
53     ENDIF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND\r
54           NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND\r
55           NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")\r
57      IF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")\r
58          MESSAGE(FATAL_ERROR "Structured Exception Handling is only allowed for MSVC")\r
59      ENDIF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")\r
61 ENDIF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)\r
63 #\r
64 # Find the header file\r
65 #\r
66 FIND_PATH(PTHREADS_INCLUDE_DIR pthread.h)\r
68 #\r
69 # Find the library\r
70 #\r
71 SET(names)\r
72 IF(MSVC)\r
73     SET(names\r
74             pthreadV${PTHREADS_EXCEPTION_SCHEME}2\r
75             pthread\r
76     )\r
77 ELSEIF(MINGW)\r
78     SET(names\r
79             pthreadG${PTHREADS_EXCEPTION_SCHEME}2\r
80             pthread\r
81     )\r
82 ELSE(MSVC) # Unix / Cygwin / Apple\r
83     SET(names pthread)\r
84 ENDIF(MSVC)\r
85     \r
86 FIND_LIBRARY(PTHREADS_LIBRARY ${names}\r
87     DOC "The Portable Threads Library")\r
89 IF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)\r
90     SET(PTHREADS_FOUND true)\r
91     SET(PTHREADS_DEFINITIONS -DHAVE_PTHREAD_H)\r
92     SET(PTHREADS_INCLUDE_DIRS ${PTHREADS_INCLUDE_DIR})\r
93     SET(PTHREADS_LIBRARIES    ${PTHREADS_LIBRARY})\r
94 ENDIF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)\r
96 IF(PTHREADS_FOUND)\r
97     IF(NOT PTHREADS_FIND_QUIETLY)\r
98         MESSAGE(STATUS "Found Pthreads: ${PTHREADS_LIBRARY}")\r
99     ENDIF(NOT PTHREADS_FIND_QUIETLY)\r
100 ELSE(PTHREADS_FOUND) \r
101     IF(PTHREADS_FIND_REQUIRED)\r
102         MESSAGE(FATAL_ERROR "Could not find the Pthreads Library")\r
103     ENDIF(PTHREADS_FIND_REQUIRED)\r
104 ENDIF(PTHREADS_FOUND)\r