Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / FindOpenThreads.cmake
1 # OpenThreads is a C++ based threading library. Its largest userbase
2 # seems to OpenSceneGraph so you might notice I accept OSGDIR as an
3 # environment path.
4 # I consider this part of the Findosg* suite used to find OpenSceneGraph
5 # components.
6 # Each component is separate and you must opt in to each module.
7 #
8 # Locate OpenThreads
9 # This module defines
10 # OPENTHREADS_LIBRARY
11 # OPENTHREADS_FOUND, if false, do not try to link to OpenThreads
12 # OPENTHREADS_INCLUDE_DIR, where to find the headers
13 #
14 # $OPENTHREADS_DIR is an environment variable that would
15 # correspond to the ./configure --prefix=$OPENTHREADS_DIR
16 # used in building osg.
17 #
18 # [CMake 2.8.10]:
19 # The CMake variables OPENTHREADS_DIR or OSG_DIR can now be used as well to influence
20 # detection, instead of needing to specify an environment variable.
21 #
22 # Created by Eric Wing.
23
24 #=============================================================================
25 # Copyright 2007-2009 Kitware, Inc.
26 # Copyright 2012 Philip Lowman <philip@yhbt.com>
27 #
28 # Distributed under the OSI-approved BSD License (the "License");
29 # see accompanying file Copyright.txt for details.
30 #
31 # This software is distributed WITHOUT ANY WARRANTY; without even the
32 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
33 # See the License for more information.
34 #=============================================================================
35 # (To distribute this file outside of CMake, substitute the full
36 #  License text for the above reference.)
37
38 # Header files are presumed to be included like
39 # #include <OpenThreads/Thread>
40
41 # To make it easier for one-step automated configuration/builds,
42 # we leverage environmental paths. This is preferable
43 # to the -DVAR=value switches because it insulates the
44 # users from changes we may make in this script.
45 # It also offers a little more flexibility than setting
46 # the CMAKE_*_PATH since we can target specific components.
47 # However, the default CMake behavior will search system paths
48 # before anything else. This is problematic in the cases
49 # where you have an older (stable) version installed, but
50 # are trying to build a newer version.
51 # CMake doesn't offer a nice way to globally control this behavior
52 # so we have to do a nasty "double FIND_" in this module.
53 # The first FIND disables the CMAKE_ search paths and only checks
54 # the environmental paths.
55 # If nothing is found, then the second find will search the
56 # standard install paths.
57 # Explicit -DVAR=value arguments should still be able to override everything.
58
59 find_path(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread
60     HINTS
61         ENV OPENTHREADS_INCLUDE_DIR
62         ENV OPENTHREADS_DIR
63         ENV OSG_INCLUDE_DIR
64         ENV OSG_DIR
65         ENV OSGDIR
66         ENV OpenThreads_ROOT
67         ENV OSG_ROOT
68         ${OPENTHREADS_DIR}
69         ${OSG_DIR}
70     PATHS
71         /sw # Fink
72         /opt/local # DarwinPorts
73         /opt/csw # Blastwave
74         /opt
75         /usr/freeware
76     PATH_SUFFIXES include
77 )
78
79
80 find_library(OPENTHREADS_LIBRARY
81     NAMES OpenThreads OpenThreadsWin32
82     HINTS
83         ENV OPENTHREADS_LIBRARY_DIR
84         ENV OPENTHREADS_DIR
85         ENV OSG_LIBRARY_DIR
86         ENV OSG_DIR
87         ENV OSGDIR
88         ENV OpenThreads_ROOT
89         ENV OSG_ROOT
90         ${OPENTHREADS_DIR}
91         ${OSG_DIR}
92     PATHS
93         /sw
94         /opt/local
95         /opt/csw
96         /opt
97         /usr/freeware
98     PATH_SUFFIXES lib
99 )
100
101 find_library(OPENTHREADS_LIBRARY_DEBUG
102     NAMES OpenThreadsd OpenThreadsWin32d
103     HINTS
104         ENV OPENTHREADS_DEBUG_LIBRARY_DIR
105         ENV OPENTHREADS_LIBRARY_DIR
106         ENV OPENTHREADS_DIR
107         ENV OSG_LIBRARY_DIR
108         ENV OSG_DIR
109         ENV OSGDIR
110         ENV OpenThreads_ROOT
111         ENV OSG_ROOT
112         ${OPENTHREADS_DIR}
113         ${OSG_DIR}
114     PATHS
115         /sw
116         /opt/local
117         /opt/csw
118         /opt
119         /usr/freeware
120     PATH_SUFFIXES lib
121 )
122
123 if(OPENTHREADS_LIBRARY_DEBUG)
124     set(OPENTHREADS_LIBRARIES
125         optimized ${OPENTHREADS_LIBRARY}
126         debug ${OPENTHREADS_LIBRARY_DEBUG})
127 else()
128     set(OPENTHREADS_LIBRARIES ${OPENTHREADS_LIBRARY})
129 endif()
130
131 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
132 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenThreads DEFAULT_MSG
133     OPENTHREADS_LIBRARY OPENTHREADS_INCLUDE_DIR)