SCDoc: Use proper static string constants instead of comparing string literals.
[supercollider.git] / cmake_modules / FindPthreads.cmake
blob1b5683c5f783e12a45848730d88b0ff04a6c6c58
1 # - Find the Pthreads library
2 # This module searches for the Pthreads library (including the
3 # pthreads-win32 port).
5 # This module defines these variables:
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 directory of the Pthreads library
13 #  PTHREADS_DEFINITIONS
14 #      Preprocessor definitions to define (HAVE_PTHREAD_H is a fairly common
15 #      one)
17 # This module responds to the PTHREADS_EXCEPTION_SCHEME
18 # variable on Win32 to allow the user to control the
19 # library linked against.  The Pthreads-win32 port
20 # provides the ability to link against a version of the
21 # library with exception handling.  IT IS NOT RECOMMENDED
22 # THAT YOU CHANGE PTHREADS_EXCEPTION_SCHEME TO ANYTHING OTHER THAN
23 # "C" because most POSIX thread implementations do not support stack
24 # unwinding.
26 #  PTHREADS_EXCEPTION_SCHEME
27 #      C  = no exceptions (default)
28 #         (NOTE: This is the default scheme on most POSIX thread
29 #          implementations and what you should probably be using)
30 #      CE = C++ Exception Handling
31 #      SE = Structure Exception Handling (MSVC only)
35 # Define a default exception scheme to link against
36 # and validate user choice.
39 IF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
40     SET(PTHREADS_DEFINITIONS -DHAVE_PTHREAD_H)
41     SET(PTHREADS_INCLUDE_DIRS ${PTHREADS_INCLUDE_DIR})
42     SET(PTHREADS_LIBRARIES    ${PTHREADS_LIBRARY})
43     SET(FOUND_PTHREADS TRUE)
44 ENDIF()
46 IF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
47     # Assign default if needed
48     SET(PTHREADS_EXCEPTION_SCHEME "C")
49 ELSE(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
50     # Validate
51     IF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
52        NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
53        NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
55     MESSAGE(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed")
57     ENDIF(NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "C" AND
58           NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "CE" AND
59           NOT PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
61      IF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
62          MESSAGE(FATAL_ERROR "Structured Exception Handling is only allowed for MSVC")
63      ENDIF(NOT MSVC AND PTHREADS_EXCEPTION_SCHEME STREQUAL "SE")
65 ENDIF(NOT DEFINED PTHREADS_EXCEPTION_SCHEME)
68 # Find the header file
70 FIND_PATH(PTHREADS_INCLUDE_DIR pthread.h)
73 # Find the library
75 SET(names)
76 IF(MSVC)
77     SET(names
78             pthreadV${PTHREADS_EXCEPTION_SCHEME}2
79             pthread
80     )
81 ELSEIF(MINGW)
82     SET(names
83             pthreadG${PTHREADS_EXCEPTION_SCHEME}2
84             pthread
85     )
86 ELSE(MSVC) # Unix / Cygwin / Apple / Etc.
87     SET(names pthread)
88 ENDIF(MSVC)
89     
90 FIND_LIBRARY(PTHREADS_LIBRARY NAMES ${names}
91     DOC "The Portable Threads Library")
93 INCLUDE(FindPackageHandleStandardArgs)
94 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Pthreads DEFAULT_MSG
95     PTHREADS_LIBRARY PTHREADS_INCLUDE_DIR)
97 IF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
98     SET(PTHREADS_DEFINITIONS -DHAVE_PTHREAD_H)
99     SET(PTHREADS_INCLUDE_DIRS ${PTHREADS_INCLUDE_DIR})
100     SET(PTHREADS_LIBRARIES    ${PTHREADS_LIBRARY})
101 ENDIF(PTHREADS_INCLUDE_DIR AND PTHREADS_LIBRARY)
103 MARK_AS_ADVANCED(PTHREADS_INCLUDE_DIR)
104 MARK_AS_ADVANCED(PTHREADS_LIBRARY)