FindOpenSceneGraph.cmake 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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<foo>.cmake files for whatever nodekits you need.
  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. #
  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 AND OPENSCENEGRAPH_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_quiet)
  134. if(OpenSceneGraph_FIND_QUIETLY)
  135. set(_osg_quiet "QUIET")
  136. endif()
  137. #
  138. # Here we call FIND_PACKAGE() on all of the components
  139. #
  140. foreach(_osg_module ${_osg_modules_to_process})
  141. if(OpenSceneGraph_DEBUG)
  142. message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  143. "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
  144. endif()
  145. find_package(${_osg_module} ${_osg_quiet})
  146. string(TOUPPER ${_osg_module} _osg_module_UC)
  147. list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
  148. list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})
  149. if(OpenSceneGraph_MARK_AS_ADVANCED)
  150. OSG_MARK_AS_ADVANCED(${_osg_module})
  151. endif()
  152. endforeach()
  153. if(OPENSCENEGRAPH_INCLUDE_DIR)
  154. list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
  155. endif()
  156. #
  157. # Inform the users with an error message based on
  158. # what version they have vs. what version was
  159. # required.
  160. #
  161. if(OpenSceneGraph_FIND_REQUIRED)
  162. set(_osg_version_output_type FATAL_ERROR)
  163. else()
  164. set(_osg_version_output_type STATUS)
  165. endif()
  166. if(_osg_version_not_high_enough)
  167. set(_osg_EPIC_FAIL TRUE)
  168. if(NOT OpenSceneGraph_FIND_QUIETLY)
  169. message(${_osg_version_output_type}
  170. "ERROR: Version ${OpenSceneGraph_FIND_VERSION} or higher of the OSG "
  171. "is required. Version ${OPENSCENEGRAPH_VERSION} was found.")
  172. endif()
  173. elseif(_osg_version_not_exact)
  174. set(_osg_EPIC_FAIL TRUE)
  175. if(NOT OpenSceneGraph_FIND_QUIETLY)
  176. message(${_osg_version_output_type}
  177. "ERROR: Version ${OpenSceneGraph_FIND_VERSION} of the OSG is required "
  178. "(exactly), version ${OPENSCENEGRAPH_VERSION} was found.")
  179. endif()
  180. else()
  181. #
  182. # Check each module to see if it's found
  183. #
  184. if(OpenSceneGraph_FIND_REQUIRED)
  185. set(_osg_missing_message)
  186. foreach(_osg_module ${_osg_modules_to_process})
  187. string(TOUPPER ${_osg_module} _osg_module_UC)
  188. if(NOT ${_osg_module_UC}_FOUND)
  189. set(_osg_missing_nodekit_fail true)
  190. set(_osg_missing_message "${_osg_missing_message} ${_osg_module}")
  191. endif()
  192. endforeach()
  193. if(_osg_missing_nodekit_fail)
  194. message(FATAL_ERROR "ERROR: Missing the following osg "
  195. "libraries: ${_osg_missing_message}.\n"
  196. "Consider using CMAKE_PREFIX_PATH or the OSG_DIR "
  197. "environment variable. See the "
  198. "${CMAKE_CURRENT_LIST_FILE} for more details.")
  199. endif()
  200. endif()
  201. include(FindPackageHandleStandardArgs)
  202. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph DEFAULT_MSG OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR)
  203. endif()
  204. if(_osg_EPIC_FAIL)
  205. # Zero out everything, we didn't meet version requirements
  206. set(OPENSCENEGRAPH_FOUND FALSE)
  207. set(OPENSCENEGRAPH_LIBRARIES)
  208. set(OPENSCENEGRAPH_INCLUDE_DIR)
  209. endif()
  210. set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})