Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / cmake / FindPthreads.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012, by the GROMACS development team, led by
5 # David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 # others, as listed in the AUTHORS file in the top-level source
7 # directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34 #
35 # - Find the Pthreads library
36 # This module searches for the Pthreads library (including the
37 # pthreads-win32 port).
38 #
39 # This module defines these variables:
40 #
41 #  PTHREADS_FOUND
42 #      True if the Pthreads library was found
43 #  PTHREADS_LIBRARY
44 #      The location of the Pthreads library
45 #  PTHREADS_INCLUDE_DIR
46 #      The include path of the Pthreads library
47 #  PTHREADS_DEFINITIONS
48 #      Preprocessor definitions to define
49 #
50 # This module responds to the PTHREADS_EXCEPTION_SCHEME
51 # variable on Win32 to allow the user to control the
52 # library linked against.  The Pthreads-win32 port
53 # provides the ability to link against a version of the
54 # library with exception handling.  IT IS NOT RECOMMENDED
55 # THAT YOU USE THIS because most POSIX thread implementations
56 # do not support stack unwinding.
57 #
58 #  PTHREADS_EXCEPTION_SCHEME
59 #      C  = no exceptions (default)
60 #         (NOTE: This is the default scheme on most POSIX thread
61 #          implementations and what you should probably be using)
62 #      CE = C++ Exception Handling
63 #      SE = Structure Exception Handling (MSVC only)
64 #
65
66 #
67 # Define a default exception scheme to link against
68 # and validate user choice.
69 #
70 IF(PTHREADS_INCLUDE_DIR)
71   # Already in cache, be silent
72   SET(PTHREADS_FIND_QUIETLY TRUE)
73 ENDIF(PTHREADS_INCLUDE_DIR)
74
75
76 IF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
77     # Assign default if needed
78     SET(PTHREADS_EXCEPTION_SCHEME "C")
79 ELSE(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
80     # Validate
81     IF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
82        NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
83        NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
84
85     MESSAGE(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed")
86
87     ENDIF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
88           NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
89           NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
90
91      IF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
92          MESSAGE(FATAL_ERROR "Structured Exception Handling is only allowed for MSVC")
93      ENDIF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
94
95 ENDIF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
96
97 #
98 # Find the header file
99 #
100 FIND_PATH(PTHREADS_INCLUDE_DIR pthread.h)
101
102 #
103 # Find the library
104 #
105 SET(names)
106 IF(MSVC)
107     SET(names
108             pthreadV${PTHREADS_EXCEPTION_SCHEME}2
109             pthread
110     )
111 ELSEIF(MINGW)
112     SET(names
113             pthreadG${PTHREADS_EXCEPTION_SCHEME}2
114             pthread
115     )
116 ELSE(MSVC) # Unix / Cygwin / Apple
117     SET(names pthread)
118 ENDIF(MSVC)
119     
120 FIND_LIBRARY(PTHREADS_LIBRARY ${names}
121     DOC "The Portable Threads Library")
122
123 IF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
124     SET(PTHREADS_FOUND true)
125     SET(PTHREADS_DEFINITIONS -DHAVE_PTHREAD_H)
126     SET(PTHREADS_INCLUDE_DIRS ${PTHREADS_INCLUDE_DIR})
127     SET(PTHREADS_LIBRARIES    ${PTHREADS_LIBRARY})
128 ENDIF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
129
130 IF(PTHREADS_FOUND)
131     IF(NOT PTHREADS_FIND_QUIETLY)
132         MESSAGE(STATUS "Found Pthreads: ${PTHREADS_LIBRARY}")
133     ENDIF(NOT PTHREADS_FIND_QUIETLY)
134 ELSE(PTHREADS_FOUND) 
135     IF(PTHREADS_FIND_REQUIRED)
136         MESSAGE(FATAL_ERROR "Could not find the Pthreads Library")
137     ENDIF(PTHREADS_FIND_REQUIRED)
138 ENDIF(PTHREADS_FOUND)