FindOpenSceneGraph.cmake 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. Find OpenSceneGraph (3D graphics application programming interface)
  7. This module searches for the OpenSceneGraph core "osg" library as well
  8. as :module:`FindOpenThreads`, and whatever additional ``COMPONENTS``
  9. (nodekits) that you specify.
  10. ::
  11. See http://www.openscenegraph.org
  12. NOTE: To use this module effectively you must either require ``CMake >=
  13. 2.6.3`` with :command:`cmake_minimum_required(VERSION 2.6.3)` or download
  14. and place :module:`FindOpenThreads`, :module:`Findosg` functions,
  15. :module:`Findosg` and ``Find<etc>.cmake`` files into your
  16. :variable:`CMAKE_MODULE_PATH`.
  17. ==================================
  18. This module accepts the following variables (note mixed case)
  19. ::
  20. OpenSceneGraph_DEBUG - Enable debugging output
  21. ::
  22. OpenSceneGraph_MARK_AS_ADVANCED - Mark cache variables as advanced
  23. automatically
  24. The following environment variables are also respected for finding the
  25. OSG and it's various components. :variable:`CMAKE_PREFIX_PATH` can also be
  26. used for this (see :command:`find_library` CMake documentation).
  27. ``<MODULE>_DIR``
  28. (where ``MODULE`` is of the form "OSGVOLUME" and there is
  29. a :module:`FindosgVolume`.cmake` file)
  30. ``OSG_DIR``
  31. ..
  32. ``OSGDIR``
  33. ..
  34. ``OSG_ROOT``
  35. ..
  36. [CMake 2.8.10]: The CMake variable ``OSG_DIR`` can now be used as well to
  37. influence detection, instead of needing to specify an environment
  38. variable.
  39. This module defines the following output variables:
  40. ::
  41. OPENSCENEGRAPH_FOUND - Was the OSG and all of the specified components found?
  42. ::
  43. OPENSCENEGRAPH_VERSION - The version of the OSG which was found
  44. ::
  45. OPENSCENEGRAPH_INCLUDE_DIRS - Where to find the headers
  46. ::
  47. OPENSCENEGRAPH_LIBRARIES - The OSG libraries
  48. ================================== Example Usage:
  49. ::
  50. find_package(OpenSceneGraph 2.0.0 REQUIRED osgDB osgUtil)
  51. # libOpenThreads & libosg automatically searched
  52. include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
  53. ::
  54. add_executable(foo foo.cc)
  55. target_link_libraries(foo ${OPENSCENEGRAPH_LIBRARIES})
  56. #]=======================================================================]
  57. #
  58. # Naming convention:
  59. # Local variables of the form _osg_foo
  60. # Input variables of the form OpenSceneGraph_FOO
  61. # Output variables of the form OPENSCENEGRAPH_FOO
  62. #
  63. include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)
  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(STATUS "[ 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(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  85. "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}")
  86. endif()
  87. set(_osg_Version_file "${OSG_INCLUDE_DIR}/osg/Version")
  88. if("${OSG_INCLUDE_DIR}" MATCHES "\\.framework$" AND NOT EXISTS "${_osg_Version_file}")
  89. set(_osg_Version_file "${OSG_INCLUDE_DIR}/Headers/Version")
  90. endif()
  91. if(EXISTS "${_osg_Version_file}")
  92. file(STRINGS "${_osg_Version_file}" _osg_Version_contents
  93. REGEX "#define (OSG_VERSION_[A-Z]+|OPENSCENEGRAPH_[A-Z]+_VERSION)[ \t]+[0-9]+")
  94. else()
  95. set(_osg_Version_contents "unknown")
  96. endif()
  97. string(REGEX MATCH ".*#define OSG_VERSION_MAJOR[ \t]+[0-9]+.*"
  98. _osg_old_defines "${_osg_Version_contents}")
  99. string(REGEX MATCH ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+[0-9]+.*"
  100. _osg_new_defines "${_osg_Version_contents}")
  101. if(_osg_old_defines)
  102. string(REGEX REPLACE ".*#define OSG_VERSION_MAJOR[ \t]+([0-9]+).*"
  103. "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
  104. string(REGEX REPLACE ".*#define OSG_VERSION_MINOR[ \t]+([0-9]+).*"
  105. "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
  106. string(REGEX REPLACE ".*#define OSG_VERSION_PATCH[ \t]+([0-9]+).*"
  107. "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
  108. elseif(_osg_new_defines)
  109. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+([0-9]+).*"
  110. "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
  111. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MINOR_VERSION[ \t]+([0-9]+).*"
  112. "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
  113. string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*"
  114. "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
  115. else()
  116. message(WARNING "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  117. "Failed to parse version number, please report this as a bug")
  118. endif()
  119. unset(_osg_Version_contents)
  120. set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}"
  121. CACHE INTERNAL "The version of OSG which was detected")
  122. if(OpenSceneGraph_DEBUG)
  123. message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  124. "Detected version ${OPENSCENEGRAPH_VERSION}")
  125. endif()
  126. endif()
  127. set(_osg_quiet)
  128. if(OpenSceneGraph_FIND_QUIETLY)
  129. set(_osg_quiet "QUIET")
  130. endif()
  131. #
  132. # Here we call find_package() on all of the components
  133. #
  134. foreach(_osg_module ${_osg_modules_to_process})
  135. if(OpenSceneGraph_DEBUG)
  136. message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
  137. "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
  138. endif()
  139. find_package(${_osg_module} ${_osg_quiet})
  140. string(TOUPPER ${_osg_module} _osg_module_UC)
  141. # append to list if module was found OR is required
  142. if( ${_osg_module_UC}_FOUND OR OpenSceneGraph_FIND_REQUIRED )
  143. list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
  144. list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})
  145. endif()
  146. if(OpenSceneGraph_MARK_AS_ADVANCED)
  147. OSG_MARK_AS_ADVANCED(${_osg_module})
  148. endif()
  149. endforeach()
  150. if(OPENSCENEGRAPH_INCLUDE_DIR)
  151. list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
  152. endif()
  153. #
  154. # Check each module to see if it's found
  155. #
  156. set(_osg_component_founds)
  157. if(OpenSceneGraph_FIND_REQUIRED)
  158. foreach(_osg_module ${_osg_modules_to_process})
  159. string(TOUPPER ${_osg_module} _osg_module_UC)
  160. list(APPEND _osg_component_founds ${_osg_module_UC}_FOUND)
  161. endforeach()
  162. endif()
  163. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  164. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSceneGraph
  165. REQUIRED_VARS OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR ${_osg_component_founds}
  166. VERSION_VAR OPENSCENEGRAPH_VERSION)
  167. unset(_osg_component_founds)
  168. set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})