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