FindOpenSceneGraph.cmake 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #.rst:
  4. # FindOpenSceneGraph
  5. # ------------------
  6. #
  7. # Find OpenSceneGraph
  8. #
  9. # This module searches for the OpenSceneGraph core "osg" library as well
  10. # as OpenThreads, and whatever additional COMPONENTS (nodekits) that you
  11. # specify.
  12. #
  13. # ::
  14. #
  15. # See http://www.openscenegraph.org
  16. #
  17. #
  18. #
  19. # NOTE: To use this module effectively you must either require CMake >=
  20. # 2.6.3 with cmake_minimum_required(VERSION 2.6.3) or download and place
  21. # FindOpenThreads.cmake, Findosg_functions.cmake, Findosg.cmake, and
  22. # Find<etc>.cmake files into your CMAKE_MODULE_PATH.
  23. #
  24. # ==================================
  25. #
  26. # This module accepts the following variables (note mixed case)
  27. #
  28. # ::
  29. #
  30. # OpenSceneGraph_DEBUG - Enable debugging output
  31. #
  32. #
  33. #
  34. # ::
  35. #
  36. # OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced
  37. # automatically
  38. #
  39. #
  40. #
  41. # The following environment variables are also respected for finding the
  42. # OSG and it's various components. CMAKE_PREFIX_PATH can also be used
  43. # for this (see find_library() CMake documentation).
  44. #
  45. # ``<MODULE>_DIR``
  46. # (where MODULE is of the form "OSGVOLUME" and there is a FindosgVolume.cmake file)
  47. # ``OSG_DIR``
  48. # ..
  49. # ``OSGDIR``
  50. # ..
  51. # ``OSG_ROOT``
  52. # ..
  53. #
  54. #
  55. # [CMake 2.8.10]: The CMake variable OSG_DIR can now be used as well to
  56. # influence detection, instead of needing to specify an environment
  57. # variable.
  58. #
  59. # This module defines the following output variables:
  60. #
  61. # ::
  62. #
  63. # OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
  64. #
  65. #
  66. #
  67. # ::
  68. #
  69. # OPENSCENEGRAPH_VERSION - The version of the OSG which was found
  70. #
  71. #
  72. #
  73. # ::
  74. #
  75. # OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers
  76. #
  77. #
  78. #
  79. # ::
  80. #
  81. # OPENSCENEGRAPH_LIBRARIES - The OSG libraries
  82. #
  83. #
  84. #
  85. # ================================== Example Usage:
  86. #
  87. # ::
  88. #
  89. # find_package(OpenSceneGraph 2.0.0 REQUIRED osgDB osgUtil)
  90. # # libOpenThreads & libosg automatically searched
  91. # include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
  92. #
  93. #
  94. #
  95. # ::
  96. #
  97. # add_executable(foo foo.cc)
  98. # target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES})
  99. #
  100. # Naming convention:
  101. # Local variables of the form _osg_foo
  102. # Input variables of the form OpenSceneGraph_FOO
  103. # Output variables of the form OPENSCENEGRAPH_FOO
  104. #
  105. include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
  106. set(_osg_modules_to_process)
  107. foreach(_osg_component ${OpenSceneGraph_FIND_COMPONENTS})
  108. list(APPEND _osg_modules_to_process ${_osg_component})
  109. endforeach()
  110. list(APPEND _osg_modules_to_process "osg" "OpenThreads")
  111. list(REMOVE_DUPLICATES _osg_modules_to_process)
  112. if(OpenSceneGraph_DEBUG)
  113. message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  114. "Components = ${_osg_modules_to_process}")
  115. endif()
  116. #
  117. # First we need to find and parse osg/Version
  118. #
  119. OSG_FIND_PATH(OSG osg/Version)
  120. if(OpenSceneGraph_MARK_AS_ADVANCED)
  121. OSG_MARK_AS_ADVANCED(OSG)
  122. endif()
  123. # Try to ascertain the version...
  124. if(OSG_INCLUDE_DIR)
  125. if(OpenSceneGraph_DEBUG)
  126. message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  127. "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}")
  128. endif()
  129. set(_osg_Version_file "${OSG_INCLUDE_DIR}/osg/Version")
  130. if("${OSG_INCLUDE_DIR}" MATCHES "\\.framework$" AND NOT EXISTS "${_osg_Version_file}")
  131. set(_osg_Version_file "${OSG_INCLUDE_DIR}/Headers/Version")
  132. endif()
  133. if(EXISTS "${_osg_Version_file}")
  134. file(STRINGS "${_osg_Version_file}" _osg_Version_contents
  135. REGEX "#define (OSG_VERSION_[A-Z]+|OPENSCENEGRAPH_[A-Z]+_VERSION)[ \t]+[0-9]+")
  136. else()
  137. set(_osg_Version_contents "unknown")
  138. endif()
  139. string(REGEX MATCH ".*#define OSG_VERSION_MAJOR[ \t]+[0-9]+.*"
  140. _osg_old_defines "${_osg_Version_contents}")
  141. string(REGEX MATCH ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+[0-9]+.*"
  142. _osg_new_defines "${_osg_Version_contents}")
  143. if(_osg_old_defines)
  144. string(REGEX REPLACE ".*#define OSG_VERSION_MAJOR[ \t]+([0-9]+).*"
  145. "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
  146. string(REGEX REPLACE ".*#define OSG_VERSION_MINOR[ \t]+([0-9]+).*"
  147. "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
  148. string(REGEX REPLACE ".*#define OSG_VERSION_PATCH[ \t]+([0-9]+).*"
  149. "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
  150. elseif(_osg_new_defines)
  151. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+([0-9]+).*"
  152. "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
  153. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MINOR_VERSION[ \t]+([0-9]+).*"
  154. "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
  155. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*"
  156. "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
  157. else()
  158. message(WARNING "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  159. "Failed to parse version number, please report this as a bug")
  160. endif()
  161. unset(_osg_Version_contents)
  162. set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}"
  163. CACHE INTERNAL "The version of OSG which was detected")
  164. if(OpenSceneGraph_DEBUG)
  165. message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  166. "Detected version ${OPENSCENEGRAPH_VERSION}")
  167. endif()
  168. endif()
  169. set(_osg_quiet)
  170. if(OpenSceneGraph_FIND_QUIETLY)
  171. set(_osg_quiet "QUIET")
  172. endif()
  173. #
  174. # Here we call find_package() on all of the components
  175. #
  176. foreach(_osg_module ${_osg_modules_to_process})
  177. if(OpenSceneGraph_DEBUG)
  178. message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  179. "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
  180. endif()
  181. find_package(${_osg_module} ${_osg_quiet})
  182. string(TOUPPER ${_osg_module} _osg_module_UC)
  183. # append to list if module was found OR is required
  184. if( ${_osg_module_UC}_FOUND OR OpenSceneGraph_FIND_REQUIRED )
  185. list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
  186. list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})
  187. endif()
  188. if(OpenSceneGraph_MARK_AS_ADVANCED)
  189. OSG_MARK_AS_ADVANCED(${_osg_module})
  190. endif()
  191. endforeach()
  192. if(OPENSCENEGRAPH_INCLUDE_DIR)
  193. list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
  194. endif()
  195. #
  196. # Check each module to see if it's found
  197. #
  198. set(_osg_component_founds)
  199. if(OpenSceneGraph_FIND_REQUIRED)
  200. foreach(_osg_module ${_osg_modules_to_process})
  201. string(TOUPPER ${_osg_module} _osg_module_UC)
  202. list(APPEND _osg_component_founds ${_osg_module_UC}_FOUND)
  203. endforeach()
  204. endif()
  205. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  206. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph
  207. REQUIRED_VARS OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR ${_osg_component_founds}
  208. VERSION_VAR OPENSCENEGRAPH_VERSION)
  209. unset(_osg_component_founds)
  210. set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})