ENH: fix for Vista
[cmake.git] / Modules / FindOpenThreads.cmake
blob75fdbdd365e99a73173cd0e04af78ea2c6a370b0
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
14 # $OPENTHREADS_DIR is an environment variable that would
15 # correspond to the ./configure --prefix=$OPENTHREADS_DIR
16 # used in building osg.
18 # Created by Eric Wing.
20 # Header files are presumed to be included like
21 # #include <OpenThreads/Thread>
23 # To make it easier for one-step automated configuration/builds,
24 # we leverage environmental paths. This is preferable 
25 # to the -DVAR=value switches because it insulates the 
26 # users from changes we may make in this script.
27 # It also offers a little more flexibility than setting
28 # the CMAKE_*_PATH since we can target specific components.
29 # However, the default CMake behavior will search system paths
30 # before anything else. This is problematic in the cases
31 # where you have an older (stable) version installed, but
32 # are trying to build a newer version.
33 # CMake doesn't offer a nice way to globally control this behavior
34 # so we have to do a nasty "double FIND_" in this module.
35 # The first FIND disables the CMAKE_ search paths and only checks
36 # the environmental paths.
37 # If nothing is found, then the second find will search the
38 # standard install paths.
39 # Explicit -DVAR=value arguments should still be able to override everything.
41 FIND_PATH(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread
42     HINTS
43     $ENV{OPENTHREADS_INCLUDE_DIR}
44     $ENV{OPENTHREADS_DIR}/include
45     $ENV{OPENTHREADS_DIR}
46     $ENV{OSG_INCLUDE_DIR}
47     $ENV{OSG_DIR}/include
48     $ENV{OSG_DIR}
49     $ENV{OSGDIR}/include
50     $ENV{OSGDIR}
51     PATHS
52     ~/Library/Frameworks
53     /Library/Frameworks
54     /usr/local/include
55     /usr/include
56     /sw/include # Fink
57     /opt/local/include # DarwinPorts
58     /opt/csw/include # Blastwave
59     /opt/include
60     [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OpenThreads_ROOT]/include
61     [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/include
65 FIND_LIBRARY(OPENTHREADS_LIBRARY 
66     NAMES OpenThreads OpenThreadsWin32 
67     HINTS
68     $ENV{OPENTHREADS_LIBRARY_DIR}
69     $ENV{OPENTHREADS_DIR}/lib64
70     $ENV{OPENTHREADS_DIR}/lib
71     $ENV{OPENTHREADS_DIR}
72     $ENV{OSG_LIBRARY_DIR}
73     $ENV{OSG_DIR}/lib64
74     $ENV{OSG_DIR}/lib
75     $ENV{OSG_DIR}
76     $ENV{OSGDIR}/lib64
77     $ENV{OSGDIR}/lib
78     $ENV{OSGDIR}
79     PATHS
80     ~/Library/Frameworks
81     /Library/Frameworks
82     /usr/local/lib64
83     /usr/local/lib
84     /usr/lib64
85     /usr/lib
86     /sw/lib64
87     /sw/lib
88     /opt/local/lib64
89     /opt/local/lib
90     /opt/csw/lib64
91     /opt/csw/lib
92     /opt/lib64
93     /opt/lib
94     [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OpenThreads_ROOT]/lib
95     [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/lib
99 FIND_LIBRARY(OPENTHREADS_LIBRARY_DEBUG 
100     NAMES OpenThreadsd OpenThreadsWin32d
101     HINTS
102     $ENV{OPENTHREADS_DEBUG_LIBRARY_DIR}
103     $ENV{OPENTHREADS_LIBRARY_DIR}
104     $ENV{OPENTHREADS_DIR}/lib64
105     $ENV{OPENTHREADS_DIR}/lib
106     $ENV{OPENTHREADS_DIR}
107     $ENV{OSG_LIBRARY_DIR}
108     $ENV{OSG_DIR}/lib64
109     $ENV{OSG_DIR}/lib
110     $ENV{OSG_DIR}
111     $ENV{OSGDIR}/lib64
112     $ENV{OSGDIR}/lib
113     $ENV{OSGDIR}
114     PATHS
115     /usr/local/lib64
116     /usr/local/lib
117     /usr/lib64
118     /usr/lib
119     /sw/lib64
120     /sw/lib
121     /opt/local/lib64
122     /opt/local/lib
123     /opt/csw/lib64
124     /opt/csw/lib
125     /opt/lib64
126     /opt/lib
127     [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OpenThreads_ROOT]/lib
128     [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/lib
132 IF(OPENTHREADS_LIBRARY)
133   IF(NOT OPENTHREADS_LIBRARY_DEBUG)
134       #MESSAGE("-- Warning Debug OpenThreads not found, using: ${OPENTHREADS_LIBRARY}")
135       #SET(OPENTHREADS_LIBRARY_DEBUG "${OPENTHREADS_LIBRARY}")
136       SET(OPENTHREADS_LIBRARY_DEBUG "${OPENTHREADS_LIBRARY}" CACHE FILEPATH "Debug version of OpenThreads Library (use regular version if not available)" FORCE)
137   ENDIF(NOT OPENTHREADS_LIBRARY_DEBUG)
138 ENDIF(OPENTHREADS_LIBRARY)
139     
140 SET(OPENTHREADS_FOUND "NO")
141 IF(OPENTHREADS_INCLUDE_DIR AND OPENTHREADS_LIBRARY)
142   SET(OPENTHREADS_FOUND "YES")
143   # MESSAGE("-- Found OpenThreads: "${OPENTHREADS_LIBRARY})
144 ENDIF(OPENTHREADS_INCLUDE_DIR AND OPENTHREADS_LIBRARY)