1 # - Find OpenSceneGraph
2 # This module searches for the OpenSceneGraph core "osg" library as well as
3 # OpenThreads, and whatever additional COMPONENTS that you specify.
4 # See http://www.openscenegraph.org
6 # NOTE: If you would like to use this module in your CMAKE_MODULE_PATH instead
7 # of requiring CMake >= 2.6.3, you will also need to download
8 # FindOpenThreads.cmake, Findosg_functions.cmake, Findosg.cmake, as well as
9 # files for any Components you need to call (FindosgDB.cmake,
10 # FindosgUtil.cmake, etc.)
12 #==================================
14 # This module accepts the following variables (note mixed case)
16 # OpenSceneGraph_DEBUG - Enable debugging output
18 # OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced
21 # The following environment variables are also respected for finding the OSG
22 # and it's various components. CMAKE_PREFIX_PATH can also be used for this
23 # (see find_library() CMake documentation).
25 # <MODULE>_DIR (where MODULE is of the form "OSGVOLUME" and there is a FindosgVolume.cmake file)
30 # This module defines the following output variables:
32 # OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
34 # OPENSCENEGRAPH_VERSION - The version of the OSG which was found
36 # OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers
38 # OPENSCENEGRAPH_LIBRARIES - The OSG libraries
40 #==================================
43 # find_package(OpenSceneGraph 2.0.0 COMPONENTS osgDB osgUtil)
44 # include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
46 # add_executable(foo foo.cc)
47 # target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES})
49 #==================================
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)
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)
145 if(OpenSceneGraph_FIND_REQUIRED)
146 set(_osg_required "REQUIRED")
148 if(OpenSceneGraph_FIND_QUIETLY)
149 set(_osg_quiet "QUIET")
152 # Here we call FIND_PACKAGE() on all of the components
154 foreach(_osg_module ${_osg_modules_to_process})
155 if(OpenSceneGraph_DEBUG)
156 message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
157 "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
159 find_package(${_osg_module} ${_osg_required} ${_osg_quiet})
161 string(TOUPPER ${_osg_module} _osg_module_UC)
162 list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
163 list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})
165 if(OpenSceneGraph_MARK_AS_ADVANCED)
166 OSG_MARK_AS_ADVANCED(${_osg_module})
170 if(OPENSCENEGRAPH_INCLUDE_DIR)
171 list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
175 # Inform the users with an error message based on
176 # what version they have vs. what version was
179 if(OpenSceneGraph_FIND_REQUIRED)
180 set(_osg_version_output_type FATAL_ERROR)
182 set(_osg_version_output_type STATUS)
184 if(_osg_version_not_high_enough)
185 set(_osg_EPIC_FAIL TRUE)
186 if(NOT OpenSceneGraph_FIND_QUIETLY)
187 message(${_osg_version_output_type}
188 "ERROR: Version ${OpenSceneGraph_FIND_VERSION} or higher of the OSG "
189 "is required. Version ${OPENSCENEGRAPH_VERSION} was found.")
191 elseif(_osg_version_not_exact)
192 set(_osg_EPIC_FAIL TRUE)
193 if(NOT OpenSceneGraph_FIND_QUIETLY)
194 message(${_osg_version_output_type}
195 "ERROR: Version ${OpenSceneGraph_FIND_VERSION} of the OSG is required "
196 "(exactly), version ${OPENSCENEGRAPH_VERSION} was found.")
199 # If the version was OK, we should hit this case where we can do the
200 # typical user notifications
201 include(FindPackageHandleStandardArgs)
202 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph DEFAULT_MSG OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR)
206 # Zero out everything, we didn't meet version requirements
207 set(OPENSCENEGRAPH_FOUND FALSE)
208 set(OPENSCENEGRAPH_LIBRARIES)
209 set(OPENSCENEGRAPH_INCLUDE_DIR)
212 set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})