FindOpenSceneGraph.cmake 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. # This module defines the following output variables:
  30. #
  31. # OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
  32. #
  33. # OPENSCENEGRAPH_VERSION - The version of the OSG which was found
  34. #
  35. # OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers
  36. #
  37. # OPENSCENEGRAPH_LIBRARIES - The OSG libraries
  38. #
  39. #==================================
  40. # Example Usage:
  41. #
  42. # find_package(OpenSceneGraph 2.0.0 REQUIRED osgDB osgUtil)
  43. # # libOpenThreads & libosg automatically searched
  44. # include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
  45. #
  46. # add_executable(foo foo.cc)
  47. # target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES})
  48. #
  49. #=============================================================================
  50. # Copyright 2009 Kitware, Inc.
  51. # Copyright 2009 Philip Lowman <[email protected]>
  52. #
  53. # Distributed under the OSI-approved BSD License (the "License");
  54. # see accompanying file Copyright.txt for details.
  55. #
  56. # This software is distributed WITHOUT ANY WARRANTY; without even the
  57. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  58. # See the License for more information.
  59. #=============================================================================
  60. # (To distribute this file outside of CMake, substitute the full
  61. # License text for the above reference.)
  62. #
  63. # Naming convention:
  64. # Local variables of the form _osg_foo
  65. # Input variables of the form OpenSceneGraph_FOO
  66. # Output variables of the form OPENSCENEGRAPH_FOO
  67. #
  68. include(Findosg_functions)
  69. set(_osg_modules_to_process)
  70. foreach(_osg_component ${OpenSceneGraph_FIND_COMPONENTS})
  71. list(APPEND _osg_modules_to_process ${_osg_component})
  72. endforeach()
  73. list(APPEND _osg_modules_to_process "osg" "OpenThreads")
  74. list(REMOVE_DUPLICATES _osg_modules_to_process)
  75. if(OpenSceneGraph_DEBUG)
  76. message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  77. "Components = ${_osg_modules_to_process}")
  78. endif()
  79. #
  80. # First we need to find and parse osg/Version
  81. #
  82. OSG_FIND_PATH(OSG osg/Version)
  83. if(OpenSceneGraph_MARK_AS_ADVANCED)
  84. OSG_MARK_AS_ADVANCED(OSG)
  85. endif()
  86. # Try to ascertain the version...
  87. if(OSG_INCLUDE_DIR)
  88. if(OpenSceneGraph_DEBUG)
  89. message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  90. "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}")
  91. endif()
  92. set(_osg_Version_file "${OSG_INCLUDE_DIR}/osg/Version")
  93. if("${OSG_INCLUDE_DIR}" MATCHES "\\.framework$" AND NOT EXISTS "${_osg_Version_file}")
  94. set(_osg_Version_file "${OSG_INCLUDE_DIR}/Headers/Version")
  95. endif()
  96. if(EXISTS "${_osg_Version_file}")
  97. file(READ "${_osg_Version_file}" _osg_Version_contents)
  98. else()
  99. set(_osg_Version_contents "unknown")
  100. endif()
  101. string(REGEX MATCH ".*#define OSG_VERSION_MAJOR[ \t]+[0-9]+.*"
  102. _osg_old_defines "${_osg_Version_contents}")
  103. string(REGEX MATCH ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+[0-9]+.*"
  104. _osg_new_defines "${_osg_Version_contents}")
  105. if(_osg_old_defines)
  106. string(REGEX REPLACE ".*#define OSG_VERSION_MAJOR[ \t]+([0-9]+).*"
  107. "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
  108. string(REGEX REPLACE ".*#define OSG_VERSION_MINOR[ \t]+([0-9]+).*"
  109. "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
  110. string(REGEX REPLACE ".*#define OSG_VERSION_PATCH[ \t]+([0-9]+).*"
  111. "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
  112. elseif(_osg_new_defines)
  113. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+([0-9]+).*"
  114. "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
  115. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MINOR_VERSION[ \t]+([0-9]+).*"
  116. "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
  117. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*"
  118. "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
  119. else()
  120. message(WARNING "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  121. "Failed to parse version number, please report this as a bug")
  122. endif()
  123. set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}"
  124. CACHE INTERNAL "The version of OSG which was detected")
  125. if(OpenSceneGraph_DEBUG)
  126. message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  127. "Detected version ${OPENSCENEGRAPH_VERSION}")
  128. endif()
  129. endif()
  130. #
  131. # Version checking
  132. #
  133. if(OpenSceneGraph_FIND_VERSION AND OPENSCENEGRAPH_VERSION)
  134. if(OpenSceneGraph_FIND_VERSION_EXACT)
  135. if(NOT OPENSCENEGRAPH_VERSION VERSION_EQUAL ${OpenSceneGraph_FIND_VERSION})
  136. set(_osg_version_not_exact TRUE)
  137. endif()
  138. else()
  139. # version is too low
  140. if(NOT OPENSCENEGRAPH_VERSION VERSION_EQUAL ${OpenSceneGraph_FIND_VERSION} AND
  141. NOT OPENSCENEGRAPH_VERSION VERSION_GREATER ${OpenSceneGraph_FIND_VERSION})
  142. set(_osg_version_not_high_enough TRUE)
  143. endif()
  144. endif()
  145. endif()
  146. set(_osg_quiet)
  147. if(OpenSceneGraph_FIND_QUIETLY)
  148. set(_osg_quiet "QUIET")
  149. endif()
  150. #
  151. # Here we call FIND_PACKAGE() on all of the components
  152. #
  153. foreach(_osg_module ${_osg_modules_to_process})
  154. if(OpenSceneGraph_DEBUG)
  155. message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  156. "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
  157. endif()
  158. find_package(${_osg_module} ${_osg_quiet})
  159. string(TOUPPER ${_osg_module} _osg_module_UC)
  160. list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
  161. list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})
  162. if(OpenSceneGraph_MARK_AS_ADVANCED)
  163. OSG_MARK_AS_ADVANCED(${_osg_module})
  164. endif()
  165. endforeach()
  166. if(OPENSCENEGRAPH_INCLUDE_DIR)
  167. list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
  168. endif()
  169. #
  170. # Inform the users with an error message based on
  171. # what version they have vs. what version was
  172. # required.
  173. #
  174. if(OpenSceneGraph_FIND_REQUIRED)
  175. set(_osg_version_output_type FATAL_ERROR)
  176. else()
  177. set(_osg_version_output_type STATUS)
  178. endif()
  179. if(_osg_version_not_high_enough)
  180. set(_osg_EPIC_FAIL TRUE)
  181. if(NOT OpenSceneGraph_FIND_QUIETLY)
  182. message(${_osg_version_output_type}
  183. "ERROR: Version ${OpenSceneGraph_FIND_VERSION} or higher of the OSG "
  184. "is required. Version ${OPENSCENEGRAPH_VERSION} was found.")
  185. endif()
  186. elseif(_osg_version_not_exact)
  187. set(_osg_EPIC_FAIL TRUE)
  188. if(NOT OpenSceneGraph_FIND_QUIETLY)
  189. message(${_osg_version_output_type}
  190. "ERROR: Version ${OpenSceneGraph_FIND_VERSION} of the OSG is required "
  191. "(exactly), version ${OPENSCENEGRAPH_VERSION} was found.")
  192. endif()
  193. else()
  194. #
  195. # Check each module to see if it's found
  196. #
  197. if(OpenSceneGraph_FIND_REQUIRED)
  198. set(_osg_missing_message)
  199. foreach(_osg_module ${_osg_modules_to_process})
  200. string(TOUPPER ${_osg_module} _osg_module_UC)
  201. if(NOT ${_osg_module_UC}_FOUND)
  202. set(_osg_missing_nodekit_fail true)
  203. set(_osg_missing_message "${_osg_missing_message} ${_osg_module}")
  204. endif()
  205. endforeach()
  206. if(_osg_missing_nodekit_fail)
  207. message(FATAL_ERROR "ERROR: Missing the following osg "
  208. "libraries: ${_osg_missing_message}.\n"
  209. "Consider using CMAKE_PREFIX_PATH or the OSG_DIR "
  210. "environment variable. See the "
  211. "${CMAKE_CURRENT_LIST_FILE} for more details.")
  212. endif()
  213. endif()
  214. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  215. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph DEFAULT_MSG OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR)
  216. endif()
  217. if(_osg_EPIC_FAIL)
  218. # Zero out everything, we didn't meet version requirements
  219. set(OPENSCENEGRAPH_FOUND FALSE)
  220. set(OPENSCENEGRAPH_LIBRARIES)
  221. set(OPENSCENEGRAPH_INCLUDE_DIR)
  222. endif()
  223. set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})