1 # - Find OpenSceneGraph
2 # This module searches for the OpenSceneGraph core "osg" library as well as
3 # OpenThreads, and whatever additional COMPONENTS (nodekits) that you specify.
4 # See http://www.openscenegraph.org
6 # NOTE: To use this module effectively you must either require CMake >= 2.6.3
7 # with cmake_minimum_required(VERSION 2.6.3) or download and place
8 # FindOpenThreads.cmake, Findosg_functions.cmake, Findosg.cmake,
9 # and Find<etc>.cmake files into your CMAKE_MODULE_PATH.
11 #==================================
13 # This module accepts the following variables (note mixed case)
15 # OpenSceneGraph_DEBUG - Enable debugging output
17 # OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced
20 # The following environment variables are also respected for finding the OSG
21 # and it's various components. CMAKE_PREFIX_PATH can also be used for this
22 # (see find_library() CMake documentation).
24 # <MODULE>_DIR (where MODULE is of the form "OSGVOLUME" and there is a FindosgVolume.cmake file)
29 # This module defines the following output variables:
31 # OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
33 # OPENSCENEGRAPH_VERSION - The version of the OSG which was found
35 # OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers
37 # OPENSCENEGRAPH_LIBRARIES - The OSG libraries
39 #==================================
42 # find_package(OpenSceneGraph 2.0.0 REQUIRED osgDB osgUtil)
43 # # libOpenThreads & libosg automatically searched
44 # include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
46 # add_executable(foo foo.cc)
47 # target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES})
52 # Local variables of the form _osg_foo
53 # Input variables of the form OpenSceneGraph_FOO
54 # Output variables of the form OPENSCENEGRAPH_FOO
56 # Copyright (c) 2009, Philip Lowman <philip@yhbt.com>
58 # Redistribution AND use is allowed according to the terms of the New
60 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
62 #==================================
64 include(Findosg_functions)
66 set(_osg_modules_to_process)
67 foreach(_osg_component ${OpenSceneGraph_FIND_COMPONENTS})
68 list(APPEND _osg_modules_to_process ${_osg_component})
70 list(APPEND _osg_modules_to_process "osg" "OpenThreads")
71 list(REMOVE_DUPLICATES _osg_modules_to_process)
73 if(OpenSceneGraph_DEBUG)
74 message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
75 "Components = ${_osg_modules_to_process}")
79 # First we need to find and parse osg/Version
81 OSG_FIND_PATH(OSG osg/Version)
82 if(OpenSceneGraph_MARK_AS_ADVANCED)
83 OSG_MARK_AS_ADVANCED(OSG)
86 # Try to ascertain the version...
88 if(OpenSceneGraph_DEBUG)
89 message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
90 "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}")
93 file(READ "${OSG_INCLUDE_DIR}/osg/Version" _osg_Version_contents)
95 string(REGEX MATCH ".*#define OSG_VERSION_MAJOR[ \t]+[0-9]+.*"
96 _osg_old_defines ${_osg_Version_contents})
97 string(REGEX MATCH ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+[0-9]+.*"
98 _osg_new_defines ${_osg_Version_contents})
100 string(REGEX REPLACE ".*#define OSG_VERSION_MAJOR[ \t]+([0-9]+).*"
101 "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
102 string(REGEX REPLACE ".*#define OSG_VERSION_MINOR[ \t]+([0-9]+).*"
103 "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
104 string(REGEX REPLACE ".*#define OSG_VERSION_PATCH[ \t]+([0-9]+).*"
105 "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
106 elseif(_osg_new_defines)
107 string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+([0-9]+).*"
108 "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
109 string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MINOR_VERSION[ \t]+([0-9]+).*"
110 "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
111 string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*"
112 "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
114 message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
115 "Failed to parse version number, please report this as a bug")
118 set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}"
119 CACHE INTERNAL "The version of OSG which was detected")
120 if(OpenSceneGraph_DEBUG)
121 message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
122 "Detected version ${OPENSCENEGRAPH_VERSION}")
129 if(OpenSceneGraph_FIND_VERSION AND OPENSCENEGRAPH_VERSION)
130 if(OpenSceneGraph_FIND_VERSION_EXACT)
131 if(NOT OPENSCENEGRAPH_VERSION VERSION_EQUAL ${OpenSceneGraph_FIND_VERSION})
132 set(_osg_version_not_exact TRUE)
136 if(NOT OPENSCENEGRAPH_VERSION VERSION_EQUAL ${OpenSceneGraph_FIND_VERSION} AND
137 NOT OPENSCENEGRAPH_VERSION VERSION_GREATER ${OpenSceneGraph_FIND_VERSION})
138 set(_osg_version_not_high_enough TRUE)
144 if(OpenSceneGraph_FIND_QUIETLY)
145 set(_osg_quiet "QUIET")
148 # Here we call FIND_PACKAGE() on all of the components
150 foreach(_osg_module ${_osg_modules_to_process})
151 if(OpenSceneGraph_DEBUG)
152 message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
153 "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
155 find_package(${_osg_module} ${_osg_quiet})
157 string(TOUPPER ${_osg_module} _osg_module_UC)
158 list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
159 list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})
161 if(OpenSceneGraph_MARK_AS_ADVANCED)
162 OSG_MARK_AS_ADVANCED(${_osg_module})
166 if(OPENSCENEGRAPH_INCLUDE_DIR)
167 list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
171 # Inform the users with an error message based on
172 # what version they have vs. what version was
175 if(OpenSceneGraph_FIND_REQUIRED)
176 set(_osg_version_output_type FATAL_ERROR)
178 set(_osg_version_output_type STATUS)
180 if(_osg_version_not_high_enough)
181 set(_osg_EPIC_FAIL TRUE)
182 if(NOT OpenSceneGraph_FIND_QUIETLY)
183 message(${_osg_version_output_type}
184 "ERROR: Version ${OpenSceneGraph_FIND_VERSION} or higher of the OSG "
185 "is required. Version ${OPENSCENEGRAPH_VERSION} was found.")
187 elseif(_osg_version_not_exact)
188 set(_osg_EPIC_FAIL TRUE)
189 if(NOT OpenSceneGraph_FIND_QUIETLY)
190 message(${_osg_version_output_type}
191 "ERROR: Version ${OpenSceneGraph_FIND_VERSION} of the OSG is required "
192 "(exactly), version ${OPENSCENEGRAPH_VERSION} was found.")
197 # Check each module to see if it's found
199 if(OpenSceneGraph_FIND_REQUIRED)
200 set(_osg_missing_message)
201 foreach(_osg_module ${_osg_modules_to_process})
202 string(TOUPPER ${_osg_module} _osg_module_UC)
203 if(NOT ${_osg_module_UC}_FOUND)
204 set(_osg_missing_nodekit_fail true)
205 set(_osg_missing_message "${_osg_missing_message} ${_osg_module}")
209 if(_osg_missing_nodekit_fail)
210 message(FATAL_ERROR "ERROR: Missing the following osg "
211 "libraries: ${_osg_missing_message}.\n"
212 "Consider using CMAKE_PREFIX_PATH or the OSG_DIR "
213 "environment variable. See the "
214 "${CMAKE_CURRENT_LIST_FILE} for more details.")
218 include(FindPackageHandleStandardArgs)
219 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph DEFAULT_MSG OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR)
223 # Zero out everything, we didn't meet version requirements
224 set(OPENSCENEGRAPH_FOUND FALSE)
225 set(OPENSCENEGRAPH_LIBRARIES)
226 set(OPENSCENEGRAPH_INCLUDE_DIR)
229 set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})