Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / FindOpenSceneGraph.cmake
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
5 #
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.
10 #
11 #==================================
12 #
13 # This module accepts the following variables (note mixed case)
14 #
15 #    OpenSceneGraph_DEBUG - Enable debugging output
16 #
17 #    OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced
18 #                                      automatically
19 #
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).
23 #
24 #    <MODULE>_DIR (where MODULE is of the form "OSGVOLUME" and there is a FindosgVolume.cmake file)
25 #    OSG_DIR
26 #    OSGDIR
27 #    OSG_ROOT
28 #
29 # [CMake 2.8.10]:
30 # The CMake variable OSG_DIR can now be used as well to influence detection, instead of needing
31 # to specify an environment variable.
32 #
33 # This module defines the following output variables:
34 #
35 #    OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
36 #
37 #    OPENSCENEGRAPH_VERSION - The version of the OSG which was found
38 #
39 #    OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers
40 #
41 #    OPENSCENEGRAPH_LIBRARIES - The OSG libraries
42 #
43 #==================================
44 # Example Usage:
45 #
46 #  find_package(OpenSceneGraph 2.0.0 REQUIRED osgDB osgUtil)
47 #      # libOpenThreads & libosg automatically searched
48 #  include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
49 #
50 #  add_executable(foo foo.cc)
51 #  target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES})
52 #
53
54 #=============================================================================
55 # Copyright 2009 Kitware, Inc.
56 # Copyright 2009-2012 Philip Lowman <philip@yhbt.com>
57 #
58 # Distributed under the OSI-approved BSD License (the "License");
59 # see accompanying file Copyright.txt for details.
60 #
61 # This software is distributed WITHOUT ANY WARRANTY; without even the
62 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
63 # See the License for more information.
64 #=============================================================================
65 # (To distribute this file outside of CMake, substitute the full
66 #  License text for the above reference.)
67
68 #
69 # Naming convention:
70 #  Local variables of the form _osg_foo
71 #  Input variables of the form OpenSceneGraph_FOO
72 #  Output variables of the form OPENSCENEGRAPH_FOO
73 #
74
75 include(Findosg_functions)
76
77 set(_osg_modules_to_process)
78 foreach(_osg_component ${OpenSceneGraph_FIND_COMPONENTS})
79     list(APPEND _osg_modules_to_process ${_osg_component})
80 endforeach()
81 list(APPEND _osg_modules_to_process "osg" "OpenThreads")
82 list(REMOVE_DUPLICATES _osg_modules_to_process)
83
84 if(OpenSceneGraph_DEBUG)
85     message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
86         "Components = ${_osg_modules_to_process}")
87 endif()
88
89 #
90 # First we need to find and parse osg/Version
91 #
92 OSG_FIND_PATH(OSG osg/Version)
93 if(OpenSceneGraph_MARK_AS_ADVANCED)
94     OSG_MARK_AS_ADVANCED(OSG)
95 endif()
96
97 # Try to ascertain the version...
98 if(OSG_INCLUDE_DIR)
99     if(OpenSceneGraph_DEBUG)
100         message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
101             "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}")
102     endif()
103
104     set(_osg_Version_file "${OSG_INCLUDE_DIR}/osg/Version")
105     if("${OSG_INCLUDE_DIR}" MATCHES "\\.framework$" AND NOT EXISTS "${_osg_Version_file}")
106         set(_osg_Version_file "${OSG_INCLUDE_DIR}/Headers/Version")
107     endif()
108
109     if(EXISTS "${_osg_Version_file}")
110       file(STRINGS "${_osg_Version_file}" _osg_Version_contents
111            REGEX "#define (OSG_VERSION_[A-Z]+|OPENSCENEGRAPH_[A-Z]+_VERSION)[ \t]+[0-9]+")
112     else()
113       set(_osg_Version_contents "unknown")
114     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     if(_osg_old_defines)
121         string(REGEX REPLACE ".*#define OSG_VERSION_MAJOR[ \t]+([0-9]+).*"
122             "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
123         string(REGEX REPLACE ".*#define OSG_VERSION_MINOR[ \t]+([0-9]+).*"
124             "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
125         string(REGEX REPLACE ".*#define OSG_VERSION_PATCH[ \t]+([0-9]+).*"
126             "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
127     elseif(_osg_new_defines)
128         string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+([0-9]+).*"
129             "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
130         string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MINOR_VERSION[ \t]+([0-9]+).*"
131             "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
132         string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*"
133             "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
134     else()
135         message(WARNING "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
136             "Failed to parse version number, please report this as a bug")
137     endif()
138     unset(_osg_Version_contents)
139
140     set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}"
141                                 CACHE INTERNAL "The version of OSG which was detected")
142     if(OpenSceneGraph_DEBUG)
143         message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
144             "Detected version ${OPENSCENEGRAPH_VERSION}")
145     endif()
146 endif()
147
148 set(_osg_quiet)
149 if(OpenSceneGraph_FIND_QUIETLY)
150     set(_osg_quiet "QUIET")
151 endif()
152 #
153 # Here we call find_package() on all of the components
154 #
155 foreach(_osg_module ${_osg_modules_to_process})
156     if(OpenSceneGraph_DEBUG)
157         message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
158             "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
159     endif()
160     find_package(${_osg_module} ${_osg_quiet})
161
162     string(TOUPPER ${_osg_module} _osg_module_UC)
163     list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
164     list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})
165
166     if(OpenSceneGraph_MARK_AS_ADVANCED)
167         OSG_MARK_AS_ADVANCED(${_osg_module})
168     endif()
169 endforeach()
170
171 if(OPENSCENEGRAPH_INCLUDE_DIR)
172     list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
173 endif()
174
175 #
176 # Check each module to see if it's found
177 #
178 set(_osg_component_founds)
179 if(OpenSceneGraph_FIND_REQUIRED)
180     foreach(_osg_module ${_osg_modules_to_process})
181         string(TOUPPER ${_osg_module} _osg_module_UC)
182         list(APPEND _osg_component_founds ${_osg_module_UC}_FOUND)
183     endforeach()
184 endif()
185
186 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
187 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph
188                                   REQUIRED_VARS OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR ${_osg_component_founds}
189                                   VERSION_VAR OPENSCENEGRAPH_VERSION)
190
191 unset(_osg_component_founds)
192
193 set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})
194