FindOpenSceneGraph.cmake 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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
  5. #
  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.)
  11. #
  12. #==================================
  13. #
  14. # This module accepts the following variables (note mixed case)
  15. #
  16. # OpenSceneGraph_DEBUG - Enable debugging output
  17. #
  18. # OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced
  19. # automatically
  20. #
  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).
  24. #
  25. # <MODULE>_DIR (where MODULE is of the form "OSGVOLUME" and there is a FindosgVolume.cmake file)
  26. # OSG_DIR
  27. # OSGDIR
  28. # OSG_ROOT
  29. #
  30. # This module defines the following output variables:
  31. #
  32. # OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
  33. #
  34. # OPENSCENEGRAPH_VERSION - The version of the OSG which was found
  35. #
  36. # OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers
  37. #
  38. # OPENSCENEGRAPH_LIBRARIES - The OSG libraries
  39. #
  40. #==================================
  41. # Example Usage:
  42. #
  43. # find_package(OpenSceneGraph 2.0.0 COMPONENTS osgDB osgUtil)
  44. # include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
  45. #
  46. # add_executable(foo foo.cc)
  47. # target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES})
  48. #
  49. #==================================
  50. #
  51. # Naming convention:
  52. # Local variables of the form _osg_foo
  53. # Input variables of the form OpenSceneGraph_FOO
  54. # Output variables of the form OPENSCENEGRAPH_FOO
  55. #
  56. # Copyright (c) 2009, Philip Lowman <[email protected]>
  57. #
  58. # Redistribution AND use is allowed according to the terms of the New
  59. # BSD license.
  60. # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
  61. #
  62. #==================================
  63. include(Findosg_functions)
  64. set(_osg_modules_to_process)
  65. foreach(_osg_component ${OpenSceneGraph_FIND_COMPONENTS})
  66. list(APPEND _osg_modules_to_process ${_osg_component})
  67. endforeach()
  68. list(APPEND _osg_modules_to_process "osg" "OpenThreads")
  69. list(REMOVE_DUPLICATES _osg_modules_to_process)
  70. if(OpenSceneGraph_DEBUG)
  71. message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  72. "Components = ${_osg_modules_to_process}")
  73. endif()
  74. #
  75. # First we need to find and parse osg/Version
  76. #
  77. OSG_FIND_PATH(OSG osg/Version)
  78. if(OpenSceneGraph_MARK_AS_ADVANCED)
  79. OSG_MARK_AS_ADVANCED(OSG)
  80. endif()
  81. # Try to ascertain the version...
  82. if(OSG_INCLUDE_DIR)
  83. if(OpenSceneGraph_DEBUG)
  84. message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  85. "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}")
  86. endif()
  87. file(READ "${OSG_INCLUDE_DIR}/osg/Version" _osg_Version_contents)
  88. string(REGEX MATCH ".*#define OSG_VERSION_MAJOR[ \t]+[0-9]+.*"
  89. _osg_old_defines ${_osg_Version_contents})
  90. string(REGEX MATCH ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+[0-9]+.*"
  91. _osg_new_defines ${_osg_Version_contents})
  92. if(_osg_old_defines)
  93. string(REGEX REPLACE ".*#define OSG_VERSION_MAJOR[ \t]+([0-9]+).*"
  94. "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
  95. string(REGEX REPLACE ".*#define OSG_VERSION_MINOR[ \t]+([0-9]+).*"
  96. "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
  97. string(REGEX REPLACE ".*#define OSG_VERSION_PATCH[ \t]+([0-9]+).*"
  98. "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
  99. elseif(_osg_new_defines)
  100. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+([0-9]+).*"
  101. "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
  102. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MINOR_VERSION[ \t]+([0-9]+).*"
  103. "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
  104. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*"
  105. "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
  106. else()
  107. message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  108. "Failed to parse version number, please report this as a bug")
  109. endif()
  110. set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}"
  111. CACHE INTERNAL "The version of OSG which was detected")
  112. if(OpenSceneGraph_DEBUG)
  113. message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  114. "Detected version ${OPENSCENEGRAPH_VERSION}")
  115. endif()
  116. endif()
  117. #
  118. # Version checking
  119. #
  120. if(OpenSceneGraph_FIND_VERSION)
  121. if(OpenSceneGraph_FIND_VERSION_EXACT)
  122. if(NOT OPENSCENEGRAPH_VERSION VERSION_EQUAL ${OpenSceneGraph_FIND_VERSION})
  123. set(_osg_version_not_exact TRUE)
  124. endif()
  125. else()
  126. # version is too low
  127. if(NOT OPENSCENEGRAPH_VERSION VERSION_EQUAL ${OpenSceneGraph_FIND_VERSION} AND
  128. NOT OPENSCENEGRAPH_VERSION VERSION_GREATER ${OpenSceneGraph_FIND_VERSION})
  129. set(_osg_version_not_high_enough TRUE)
  130. endif()
  131. endif()
  132. endif()
  133. set(_osg_required)
  134. set(_osg_quiet)
  135. if(OpenSceneGraph_FIND_REQUIRED)
  136. set(_osg_required "REQUIRED")
  137. endif()
  138. if(OpenSceneGraph_FIND_QUIETLY)
  139. set(_osg_quiet "QUIET")
  140. endif()
  141. #
  142. # Here we call FIND_PACKAGE() on all of the components
  143. #
  144. foreach(_osg_module ${_osg_modules_to_process})
  145. if(OpenSceneGraph_DEBUG)
  146. message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  147. "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
  148. endif()
  149. find_package(${_osg_module} ${_osg_required} ${_osg_quiet})
  150. string(TOUPPER ${_osg_module} _osg_module_UC)
  151. list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
  152. list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})
  153. if(OpenSceneGraph_MARK_AS_ADVANCED)
  154. OSG_MARK_AS_ADVANCED(${_osg_module})
  155. endif()
  156. endforeach()
  157. if(OPENSCENEGRAPH_INCLUDE_DIR)
  158. list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
  159. endif()
  160. #
  161. # Inform the users with an error message based on
  162. # what version they have vs. what version was
  163. # required.
  164. #
  165. if(OpenSceneGraph_FIND_REQUIRED)
  166. set(_osg_version_output_type FATAL_ERROR)
  167. else()
  168. set(_osg_version_output_type STATUS)
  169. endif()
  170. if(_osg_version_not_high_enough)
  171. set(_osg_EPIC_FAIL TRUE)
  172. if(NOT OpenSceneGraph_FIND_QUIETLY)
  173. message(${_osg_version_output_type}
  174. "ERROR: Version ${OpenSceneGraph_FIND_VERSION} or higher of the OSG "
  175. "is required. Version ${OPENSCENEGRAPH_VERSION} was found.")
  176. endif()
  177. elseif(_osg_version_not_exact)
  178. set(_osg_EPIC_FAIL TRUE)
  179. if(NOT OpenSceneGraph_FIND_QUIETLY)
  180. message(${_osg_version_output_type}
  181. "ERROR: Version ${OpenSceneGraph_FIND_VERSION} of the OSG is required "
  182. "(exactly), version ${OPENSCENEGRAPH_VERSION} was found.")
  183. endif()
  184. else()
  185. # If the version was OK, we should hit this case where we can do the
  186. # typical user notifications
  187. include(FindPackageHandleStandardArgs)
  188. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph DEFAULT_MSG OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR)
  189. endif()
  190. if(_osg_EPIC_FAIL)
  191. # Zero out everything, we didn't meet version requirements
  192. set(OPENSCENEGRAPH_FOUND FALSE)
  193. set(OPENSCENEGRAPH_LIBRARIES)
  194. set(OPENSCENEGRAPH_INCLUDE_DIR)
  195. endif()
  196. set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})