FindOpenThreads.cmake 3.7 KB
Newer Older
1 2 3
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

4 5 6 7 8 9 10
#.rst:
# FindOpenThreads
# ---------------
#
#
#
# OpenThreads is a C++ based threading library.  Its largest userbase
11
# seems to OpenSceneGraph so you might notice I accept OSGDIR as an
12 13 14 15 16
# environment path.  I consider this part of the Findosg* suite used to
# find OpenSceneGraph components.  Each component is separate and you
# must opt in to each module.
#
# Locate OpenThreads This module defines OPENTHREADS_LIBRARY
17 18 19
# OPENTHREADS_FOUND, if false, do not try to link to OpenThreads
# OPENTHREADS_INCLUDE_DIR, where to find the headers
#
20 21
# $OPENTHREADS_DIR is an environment variable that would correspond to
# the ./configure --prefix=$OPENTHREADS_DIR used in building osg.
22
#
23 24 25
# [CMake 2.8.10]: The CMake variables OPENTHREADS_DIR or OSG_DIR can now
# be used as well to influence detection, instead of needing to specify
# an environment variable.
26
#
27 28 29 30 31 32
# Created by Eric Wing.

# Header files are presumed to be included like
# #include <OpenThreads/Thread>

# To make it easier for one-step automated configuration/builds,
33 34
# we leverage environmental paths. This is preferable
# to the -DVAR=value switches because it insulates the
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
# users from changes we may make in this script.
# It also offers a little more flexibility than setting
# the CMAKE_*_PATH since we can target specific components.
# However, the default CMake behavior will search system paths
# before anything else. This is problematic in the cases
# where you have an older (stable) version installed, but
# are trying to build a newer version.
# CMake doesn't offer a nice way to globally control this behavior
# so we have to do a nasty "double FIND_" in this module.
# The first FIND disables the CMAKE_ search paths and only checks
# the environmental paths.
# If nothing is found, then the second find will search the
# standard install paths.
# Explicit -DVAR=value arguments should still be able to override everything.

50
find_path(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread
51
    HINTS
52 53 54 55 56 57 58
        ENV OPENTHREADS_INCLUDE_DIR
        ENV OPENTHREADS_DIR
        ENV OSG_INCLUDE_DIR
        ENV OSG_DIR
        ENV OSGDIR
        ENV OpenThreads_ROOT
        ENV OSG_ROOT
59 60
        ${OPENTHREADS_DIR}
        ${OSG_DIR}
61
    PATHS
62 63 64 65 66 67
        /sw # Fink
        /opt/local # DarwinPorts
        /opt/csw # Blastwave
        /opt
        /usr/freeware
    PATH_SUFFIXES include
68 69 70
)


71 72
find_library(OPENTHREADS_LIBRARY
    NAMES OpenThreads OpenThreadsWin32
73
    HINTS
74 75 76 77 78 79 80
        ENV OPENTHREADS_LIBRARY_DIR
        ENV OPENTHREADS_DIR
        ENV OSG_LIBRARY_DIR
        ENV OSG_DIR
        ENV OSGDIR
        ENV OpenThreads_ROOT
        ENV OSG_ROOT
81 82
        ${OPENTHREADS_DIR}
        ${OSG_DIR}
83
    PATHS
84 85 86 87 88
        /sw
        /opt/local
        /opt/csw
        /opt
        /usr/freeware
89
    PATH_SUFFIXES lib
90 91
)

92
find_library(OPENTHREADS_LIBRARY_DEBUG
93
    NAMES OpenThreadsd OpenThreadsWin32d
94
    HINTS
95 96 97 98 99 100 101 102
        ENV OPENTHREADS_DEBUG_LIBRARY_DIR
        ENV OPENTHREADS_LIBRARY_DIR
        ENV OPENTHREADS_DIR
        ENV OSG_LIBRARY_DIR
        ENV OSG_DIR
        ENV OSGDIR
        ENV OpenThreads_ROOT
        ENV OSG_ROOT
103 104
        ${OPENTHREADS_DIR}
        ${OSG_DIR}
105
    PATHS
106 107 108 109 110
        /sw
        /opt/local
        /opt/csw
        /opt
        /usr/freeware
111
    PATH_SUFFIXES lib
112 113
)

114 115 116 117 118 119 120
if(OPENTHREADS_LIBRARY_DEBUG)
    set(OPENTHREADS_LIBRARIES
        optimized ${OPENTHREADS_LIBRARY}
        debug ${OPENTHREADS_LIBRARY_DEBUG})
else()
    set(OPENTHREADS_LIBRARIES ${OPENTHREADS_LIBRARY})
endif()
121

122
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
123
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenThreads DEFAULT_MSG
124
    OPENTHREADS_LIBRARY OPENTHREADS_INCLUDE_DIR)