Merge topic 'cpack-innosetup-linux'
[kiteware-cmake.git] / Modules / FindOpenSceneGraph.cmake
blob9df2a62c952665c838bcb61bfa5b4a08c129be7d
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
5 FindOpenSceneGraph
6 ------------------
8 Find OpenSceneGraph (3D graphics application programming interface)
10 This module searches for the OpenSceneGraph core "osg" library as well
11 as :module:`FindOpenThreads`, and whatever additional ``COMPONENTS``
12 (nodekits) that you specify.
16     See http://www.openscenegraph.org
20 NOTE: To use this module effectively you must either require ``CMake >=
21 2.6.3`` with  :command:`cmake_minimum_required(VERSION 2.6.3)` or download
22 and place :module:`FindOpenThreads`, :module:`Findosg` functions,
23 :module:`Findosg` and ``Find<etc>.cmake`` files into your
24 :variable:`CMAKE_MODULE_PATH`.
26 ==================================
28 This module accepts the following variables (note mixed case)
32     OpenSceneGraph_DEBUG - Enable debugging output
38     OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced
39                                       automatically
43 The following environment variables are also respected for finding the
44 OSG and it's various components.  :variable:`CMAKE_PREFIX_PATH` can also be
45 used for this (see :command:`find_library` CMake documentation).
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   ..
58 [CMake 2.8.10]: The CMake variable ``OSG_DIR`` can now be used as well to
59 influence detection, instead of needing to specify an environment
60 variable.
62 This module defines the following output variables:
66     OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
72     OPENSCENEGRAPH_VERSION - The version of the OSG which was found
78     OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers
84     OPENSCENEGRAPH_LIBRARIES - The OSG libraries
88 ================================== Example Usage:
92   find_package(OpenSceneGraph 2.0.0 REQUIRED osgDB osgUtil)
93       # libOpenThreads & libosg automatically searched
94   include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
100   add_executable(foo foo.cc)
101   target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES})
102 #]=======================================================================]
104 cmake_policy(PUSH)
105 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
108 # Naming convention:
109 #  Local variables of the form _osg_foo
110 #  Input variables of the form OpenSceneGraph_FOO
111 #  Output variables of the form OPENSCENEGRAPH_FOO
114 include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
116 set(_osg_modules_to_process)
117 foreach(_osg_component ${OpenSceneGraph_FIND_COMPONENTS})
118     list(APPEND _osg_modules_to_process ${_osg_component})
119 endforeach()
120 list(APPEND _osg_modules_to_process "osg" "OpenThreads")
121 list(REMOVE_DUPLICATES _osg_modules_to_process)
123 if(OpenSceneGraph_DEBUG)
124     message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
125         "Components = ${_osg_modules_to_process}")
126 endif()
129 # First we need to find and parse osg/Version
131 OSG_FIND_PATH(OSG osg/Version)
132 if(OpenSceneGraph_MARK_AS_ADVANCED)
133     OSG_MARK_AS_ADVANCED(OSG)
134 endif()
136 # Try to ascertain the version...
137 if(OSG_INCLUDE_DIR)
138     if(OpenSceneGraph_DEBUG)
139         message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
140             "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}")
141     endif()
143     set(_osg_Version_file "${OSG_INCLUDE_DIR}/osg/Version")
144     if("${OSG_INCLUDE_DIR}" MATCHES "\\.framework$" AND NOT EXISTS "${_osg_Version_file}")
145         set(_osg_Version_file "${OSG_INCLUDE_DIR}/Headers/Version")
146     endif()
148     if(EXISTS "${_osg_Version_file}")
149       file(STRINGS "${_osg_Version_file}" _osg_Version_contents
150            REGEX "#define (OSG_VERSION_[A-Z]+|OPENSCENEGRAPH_[A-Z]+_VERSION)[ \t]+[0-9]+")
151     else()
152       set(_osg_Version_contents "unknown")
153     endif()
155     string(REGEX MATCH ".*#define OSG_VERSION_MAJOR[ \t]+[0-9]+.*"
156         _osg_old_defines "${_osg_Version_contents}")
157     string(REGEX MATCH ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+[0-9]+.*"
158         _osg_new_defines "${_osg_Version_contents}")
159     if(_osg_old_defines)
160         string(REGEX REPLACE ".*#define OSG_VERSION_MAJOR[ \t]+([0-9]+).*"
161             "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
162         string(REGEX REPLACE ".*#define OSG_VERSION_MINOR[ \t]+([0-9]+).*"
163             "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
164         string(REGEX REPLACE ".*#define OSG_VERSION_PATCH[ \t]+([0-9]+).*"
165             "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
166     elseif(_osg_new_defines)
167         string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+([0-9]+).*"
168             "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
169         string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MINOR_VERSION[ \t]+([0-9]+).*"
170             "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
171         string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*"
172             "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
173     else()
174         message(WARNING "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
175             "Failed to parse version number, please report this as a bug")
176     endif()
177     unset(_osg_Version_contents)
179     set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}"
180                                 CACHE INTERNAL "The version of OSG which was detected")
181     if(OpenSceneGraph_DEBUG)
182         message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
183             "Detected version ${OPENSCENEGRAPH_VERSION}")
184     endif()
185 endif()
187 set(_osg_quiet)
188 if(OpenSceneGraph_FIND_QUIETLY)
189     set(_osg_quiet "QUIET")
190 endif()
192 # Here we call find_package() on all of the components
194 foreach(_osg_module ${_osg_modules_to_process})
195     if(OpenSceneGraph_DEBUG)
196         message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
197             "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
198     endif()
199     find_package(${_osg_module} ${_osg_quiet})
201     string(TOUPPER ${_osg_module} _osg_module_UC)
202     # append to list if module was found OR is required
203     if( ${_osg_module_UC}_FOUND OR OpenSceneGraph_FIND_REQUIRED )
204       list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
205       list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})
206     endif()
208     if(OpenSceneGraph_MARK_AS_ADVANCED)
209         OSG_MARK_AS_ADVANCED(${_osg_module})
210     endif()
211 endforeach()
213 if(OPENSCENEGRAPH_INCLUDE_DIR)
214     list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
215 endif()
218 # Check each module to see if it's found
220 set(_osg_component_founds)
221 if(OpenSceneGraph_FIND_REQUIRED)
222     foreach(_osg_module ${_osg_modules_to_process})
223         string(TOUPPER ${_osg_module} _osg_module_UC)
224         list(APPEND _osg_component_founds ${_osg_module_UC}_FOUND)
225     endforeach()
226 endif()
228 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
229 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph
230                                   REQUIRED_VARS OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR ${_osg_component_founds}
231                                   VERSION_VAR OPENSCENEGRAPH_VERSION)
233 unset(_osg_component_founds)
235 set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})
237 cmake_policy(POP)