1# Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2# file Copyright.txt or https://cmake.org/licensing for details. 3 4#[=======================================================================[.rst: 5FindOpenSceneGraph 6------------------ 7 8Find OpenSceneGraph (3D graphics application programming interface) 9 10This module searches for the OpenSceneGraph core "osg" library as well 11as :module:`FindOpenThreads`, and whatever additional ``COMPONENTS`` 12(nodekits) that you specify. 13 14:: 15 16 See http://www.openscenegraph.org 17 18 19 20NOTE: To use this module effectively you must either require ``CMake >= 212.6.3`` with :command:`cmake_minimum_required(VERSION 2.6.3)` or download 22and place :module:`FindOpenThreads`, :module:`Findosg` functions, 23:module:`Findosg` and ``Find<etc>.cmake`` files into your 24:variable:`CMAKE_MODULE_PATH`. 25 26================================== 27 28This module accepts the following variables (note mixed case) 29 30:: 31 32 OpenSceneGraph_DEBUG - Enable debugging output 33 34 35 36:: 37 38 OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced 39 automatically 40 41 42 43The following environment variables are also respected for finding the 44OSG and it's various components. :variable:`CMAKE_PREFIX_PATH` can also be 45used for this (see :command:`find_library` CMake documentation). 46 47``<MODULE>_DIR`` 48 (where ``MODULE`` is of the form "OSGVOLUME" and there is 49 a :module:`FindosgVolume`.cmake` file) 50``OSG_DIR`` 51 .. 52``OSGDIR`` 53 .. 54``OSG_ROOT`` 55 .. 56 57 58[CMake 2.8.10]: The CMake variable ``OSG_DIR`` can now be used as well to 59influence detection, instead of needing to specify an environment 60variable. 61 62This module defines the following output variables: 63 64:: 65 66 OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found? 67 68 69 70:: 71 72 OPENSCENEGRAPH_VERSION - The version of the OSG which was found 73 74 75 76:: 77 78 OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers 79 80 81 82:: 83 84 OPENSCENEGRAPH_LIBRARIES - The OSG libraries 85 86 87 88================================== Example Usage: 89 90:: 91 92 find_package(OpenSceneGraph 2.0.0 REQUIRED osgDB osgUtil) 93 # libOpenThreads & libosg automatically searched 94 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}) 95 96 97 98:: 99 100 add_executable(foo foo.cc) 101 target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES}) 102#]=======================================================================] 103 104# 105# Naming convention: 106# Local variables of the form _osg_foo 107# Input variables of the form OpenSceneGraph_FOO 108# Output variables of the form OPENSCENEGRAPH_FOO 109# 110 111include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake) 112 113set(_osg_modules_to_process) 114foreach(_osg_component ${OpenSceneGraph_FIND_COMPONENTS}) 115 list(APPEND _osg_modules_to_process ${_osg_component}) 116endforeach() 117list(APPEND _osg_modules_to_process "osg" "OpenThreads") 118list(REMOVE_DUPLICATES _osg_modules_to_process) 119 120if(OpenSceneGraph_DEBUG) 121 message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " 122 "Components = ${_osg_modules_to_process}") 123endif() 124 125# 126# First we need to find and parse osg/Version 127# 128OSG_FIND_PATH(OSG osg/Version) 129if(OpenSceneGraph_MARK_AS_ADVANCED) 130 OSG_MARK_AS_ADVANCED(OSG) 131endif() 132 133# Try to ascertain the version... 134if(OSG_INCLUDE_DIR) 135 if(OpenSceneGraph_DEBUG) 136 message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " 137 "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}") 138 endif() 139 140 set(_osg_Version_file "${OSG_INCLUDE_DIR}/osg/Version") 141 if("${OSG_INCLUDE_DIR}" MATCHES "\\.framework$" AND NOT EXISTS "${_osg_Version_file}") 142 set(_osg_Version_file "${OSG_INCLUDE_DIR}/Headers/Version") 143 endif() 144 145 if(EXISTS "${_osg_Version_file}") 146 file(STRINGS "${_osg_Version_file}" _osg_Version_contents 147 REGEX "#define (OSG_VERSION_[A-Z]+|OPENSCENEGRAPH_[A-Z]+_VERSION)[ \t]+[0-9]+") 148 else() 149 set(_osg_Version_contents "unknown") 150 endif() 151 152 string(REGEX MATCH ".*#define OSG_VERSION_MAJOR[ \t]+[0-9]+.*" 153 _osg_old_defines "${_osg_Version_contents}") 154 string(REGEX MATCH ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+[0-9]+.*" 155 _osg_new_defines "${_osg_Version_contents}") 156 if(_osg_old_defines) 157 string(REGEX REPLACE ".*#define OSG_VERSION_MAJOR[ \t]+([0-9]+).*" 158 "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents}) 159 string(REGEX REPLACE ".*#define OSG_VERSION_MINOR[ \t]+([0-9]+).*" 160 "\\1" _osg_VERSION_MINOR ${_osg_Version_contents}) 161 string(REGEX REPLACE ".*#define OSG_VERSION_PATCH[ \t]+([0-9]+).*" 162 "\\1" _osg_VERSION_PATCH ${_osg_Version_contents}) 163 elseif(_osg_new_defines) 164 string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+([0-9]+).*" 165 "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents}) 166 string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MINOR_VERSION[ \t]+([0-9]+).*" 167 "\\1" _osg_VERSION_MINOR ${_osg_Version_contents}) 168 string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*" 169 "\\1" _osg_VERSION_PATCH ${_osg_Version_contents}) 170 else() 171 message(WARNING "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " 172 "Failed to parse version number, please report this as a bug") 173 endif() 174 unset(_osg_Version_contents) 175 176 set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}" 177 CACHE INTERNAL "The version of OSG which was detected") 178 if(OpenSceneGraph_DEBUG) 179 message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " 180 "Detected version ${OPENSCENEGRAPH_VERSION}") 181 endif() 182endif() 183 184set(_osg_quiet) 185if(OpenSceneGraph_FIND_QUIETLY) 186 set(_osg_quiet "QUIET") 187endif() 188# 189# Here we call find_package() on all of the components 190# 191foreach(_osg_module ${_osg_modules_to_process}) 192 if(OpenSceneGraph_DEBUG) 193 message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " 194 "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})") 195 endif() 196 find_package(${_osg_module} ${_osg_quiet}) 197 198 string(TOUPPER ${_osg_module} _osg_module_UC) 199 # append to list if module was found OR is required 200 if( ${_osg_module_UC}_FOUND OR OpenSceneGraph_FIND_REQUIRED ) 201 list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR}) 202 list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES}) 203 endif() 204 205 if(OpenSceneGraph_MARK_AS_ADVANCED) 206 OSG_MARK_AS_ADVANCED(${_osg_module}) 207 endif() 208endforeach() 209 210if(OPENSCENEGRAPH_INCLUDE_DIR) 211 list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR) 212endif() 213 214# 215# Check each module to see if it's found 216# 217set(_osg_component_founds) 218if(OpenSceneGraph_FIND_REQUIRED) 219 foreach(_osg_module ${_osg_modules_to_process}) 220 string(TOUPPER ${_osg_module} _osg_module_UC) 221 list(APPEND _osg_component_founds ${_osg_module_UC}_FOUND) 222 endforeach() 223endif() 224 225include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) 226FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph 227 REQUIRED_VARS OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR ${_osg_component_founds} 228 VERSION_VAR OPENSCENEGRAPH_VERSION) 229 230unset(_osg_component_founds) 231 232set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR}) 233