Updates will be applied April 15th at 12pm EDT (UTC-0400). GitLab could be a little slow between 12 - 12:45pm EDT.

FindOpenSceneGraph.cmake 9.22 KB
Newer Older
1 2
# - Find OpenSceneGraph
# This module searches for the OpenSceneGraph core "osg" library as well as
3
# OpenThreads, and whatever additional COMPONENTS (nodekits) that you specify.
4 5
#    See http://www.openscenegraph.org
#
6 7 8
# NOTE: To use this module effectively you must either require CMake >= 2.6.3
# with cmake_minimum_required(VERSION 2.6.3) or download and place
# FindOpenThreads.cmake, Findosg_functions.cmake, Findosg.cmake,
9
# and Find<etc>.cmake files into your CMAKE_MODULE_PATH.
10 11 12 13 14 15 16
#
#==================================
#
# This module accepts the following variables (note mixed case)
#
#    OpenSceneGraph_DEBUG - Enable debugging output
#
17
#    OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced
18 19 20 21 22 23 24 25 26 27 28
#                                      automatically
#
# The following environment variables are also respected for finding the OSG
# and it's various components.  CMAKE_PREFIX_PATH can also be used for this
# (see find_library() CMake documentation).
#
#    <MODULE>_DIR (where MODULE is of the form "OSGVOLUME" and there is a FindosgVolume.cmake file)
#    OSG_DIR
#    OSGDIR
#    OSG_ROOT
#
29 30 31 32
# [CMake 2.8.10]:
# The CMake variable OSG_DIR can now be used as well to influence detection, instead of needing
# to specify an environment variable.
#
33 34 35 36 37 38 39 40 41 42 43 44 45
# This module defines the following output variables:
#
#    OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
#
#    OPENSCENEGRAPH_VERSION - The version of the OSG which was found
#
#    OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers
#
#    OPENSCENEGRAPH_LIBRARIES - The OSG libraries
#
#==================================
# Example Usage:
#
46 47
#  find_package(OpenSceneGraph 2.0.0 REQUIRED osgDB osgUtil)
#      # libOpenThreads & libosg automatically searched
48 49 50 51 52
#  include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
#
#  add_executable(foo foo.cc)
#  target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES})
#
53

54 55
#=============================================================================
# Copyright 2009 Kitware, Inc.
56
# Copyright 2009-2012 Philip Lowman <philip@yhbt.com>
57 58 59 60 61 62 63 64
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
65
# (To distribute this file outside of CMake, substitute the full
66 67
#  License text for the above reference.)

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#
# Naming convention:
#  Local variables of the form _osg_foo
#  Input variables of the form OpenSceneGraph_FOO
#  Output variables of the form OPENSCENEGRAPH_FOO
#

include(Findosg_functions)

set(_osg_modules_to_process)
foreach(_osg_component ${OpenSceneGraph_FIND_COMPONENTS})
    list(APPEND _osg_modules_to_process ${_osg_component})
endforeach()
list(APPEND _osg_modules_to_process "osg" "OpenThreads")
list(REMOVE_DUPLICATES _osg_modules_to_process)

if(OpenSceneGraph_DEBUG)
85
    message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
86 87 88 89 90 91 92 93 94 95 96 97 98 99
        "Components = ${_osg_modules_to_process}")
endif()

#
# First we need to find and parse osg/Version
#
OSG_FIND_PATH(OSG osg/Version)
if(OpenSceneGraph_MARK_AS_ADVANCED)
    OSG_MARK_AS_ADVANCED(OSG)
endif()

# Try to ascertain the version...
if(OSG_INCLUDE_DIR)
    if(OpenSceneGraph_DEBUG)
100
        message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
101 102
            "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}")
    endif()
103

104 105 106 107
    set(_osg_Version_file "${OSG_INCLUDE_DIR}/osg/Version")
    if("${OSG_INCLUDE_DIR}" MATCHES "\\.framework$" AND NOT EXISTS "${_osg_Version_file}")
        set(_osg_Version_file "${OSG_INCLUDE_DIR}/Headers/Version")
    endif()
108

109
    if(EXISTS "${_osg_Version_file}")
110 111
      file(STRINGS "${_osg_Version_file}" _osg_Version_contents
           REGEX "#define (OSG_VERSION_[A-Z]+|OPENSCENEGRAPH_[A-Z]+_VERSION)[ \t]+[0-9]+")
112 113 114
    else()
      set(_osg_Version_contents "unknown")
    endif()
115 116

    string(REGEX MATCH ".*#define OSG_VERSION_MAJOR[ \t]+[0-9]+.*"
117
        _osg_old_defines "${_osg_Version_contents}")
118
    string(REGEX MATCH ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+[0-9]+.*"
119
        _osg_new_defines "${_osg_Version_contents}")
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    if(_osg_old_defines)
        string(REGEX REPLACE ".*#define OSG_VERSION_MAJOR[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
        string(REGEX REPLACE ".*#define OSG_VERSION_MINOR[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
        string(REGEX REPLACE ".*#define OSG_VERSION_PATCH[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
    elseif(_osg_new_defines)
        string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
        string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MINOR_VERSION[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
        string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
    else()
135
        message(WARNING "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
136 137
            "Failed to parse version number, please report this as a bug")
    endif()
138
    unset(_osg_Version_contents)
139 140 141 142

    set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}"
                                CACHE INTERNAL "The version of OSG which was detected")
    if(OpenSceneGraph_DEBUG)
143
        message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
144 145 146 147 148 149 150
            "Detected version ${OPENSCENEGRAPH_VERSION}")
    endif()
endif()

#
# Version checking
#
151
if(OpenSceneGraph_FIND_VERSION AND OPENSCENEGRAPH_VERSION)
152 153 154 155 156 157
    if(OpenSceneGraph_FIND_VERSION_EXACT)
        if(NOT OPENSCENEGRAPH_VERSION VERSION_EQUAL ${OpenSceneGraph_FIND_VERSION})
            set(_osg_version_not_exact TRUE)
        endif()
    else()
        # version is too low
158
        if(NOT OPENSCENEGRAPH_VERSION VERSION_EQUAL ${OpenSceneGraph_FIND_VERSION} AND
159 160 161
                NOT OPENSCENEGRAPH_VERSION VERSION_GREATER ${OpenSceneGraph_FIND_VERSION})
            set(_osg_version_not_high_enough TRUE)
        endif()
162 163 164 165 166 167 168 169
    endif()
endif()

set(_osg_quiet)
if(OpenSceneGraph_FIND_QUIETLY)
    set(_osg_quiet "QUIET")
endif()
#
170
# Here we call find_package() on all of the components
171 172 173
#
foreach(_osg_module ${_osg_modules_to_process})
    if(OpenSceneGraph_DEBUG)
174
        message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
175 176
            "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
    endif()
177
    find_package(${_osg_module} ${_osg_quiet})
178 179 180 181 182 183 184 185 186 187 188 189 190

    string(TOUPPER ${_osg_module} _osg_module_UC)
    list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
    list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})

    if(OpenSceneGraph_MARK_AS_ADVANCED)
        OSG_MARK_AS_ADVANCED(${_osg_module})
    endif()
endforeach()

if(OPENSCENEGRAPH_INCLUDE_DIR)
    list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
endif()
191

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
#
# Inform the users with an error message based on
# what version they have vs. what version was
# required.
#
if(OpenSceneGraph_FIND_REQUIRED)
    set(_osg_version_output_type FATAL_ERROR)
else()
    set(_osg_version_output_type STATUS)
endif()
if(_osg_version_not_high_enough)
    set(_osg_EPIC_FAIL TRUE)
    if(NOT OpenSceneGraph_FIND_QUIETLY)
        message(${_osg_version_output_type}
            "ERROR: Version ${OpenSceneGraph_FIND_VERSION} or higher of the OSG "
            "is required.  Version ${OPENSCENEGRAPH_VERSION} was found.")
    endif()
elseif(_osg_version_not_exact)
    set(_osg_EPIC_FAIL TRUE)
    if(NOT OpenSceneGraph_FIND_QUIETLY)
        message(${_osg_version_output_type}
            "ERROR: Version ${OpenSceneGraph_FIND_VERSION} of the OSG is required "
            "(exactly), version ${OPENSCENEGRAPH_VERSION} was found.")
    endif()
else()
217 218 219 220 221 222 223 224 225 226 227 228 229

    #
    # Check each module to see if it's found
    #
    if(OpenSceneGraph_FIND_REQUIRED)
        set(_osg_missing_message)
        foreach(_osg_module ${_osg_modules_to_process})
            string(TOUPPER ${_osg_module} _osg_module_UC)
            if(NOT ${_osg_module_UC}_FOUND)
                set(_osg_missing_nodekit_fail true)
                set(_osg_missing_message "${_osg_missing_message} ${_osg_module}")
            endif()
        endforeach()
230

231 232 233 234 235 236 237 238 239
        if(_osg_missing_nodekit_fail)
            message(FATAL_ERROR "ERROR: Missing the following osg "
                "libraries: ${_osg_missing_message}.\n"
                "Consider using CMAKE_PREFIX_PATH or the OSG_DIR "
                "environment variable.  See the "
                "${CMAKE_CURRENT_LIST_FILE} for more details.")
        endif()
    endif()

240
    include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
241 242 243 244 245 246 247 248 249 250 251 252
    FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph DEFAULT_MSG OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR)
endif()

if(_osg_EPIC_FAIL)
    # Zero out everything, we didn't meet version requirements
    set(OPENSCENEGRAPH_FOUND FALSE)
    set(OPENSCENEGRAPH_LIBRARIES)
    set(OPENSCENEGRAPH_INCLUDE_DIR)
endif()

set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})