# Build OpenSceneGraph

# The GitHub release (tag) we want to use
SET(OPENSCENEGRAPH_TAG OpenSceneGraph-3.6.5)

SET(OPENSCENEGRAPH_PREFIX openscenegraph)

SET(OPENSCENEGRAPH_URL https://github.com/openscenegraph/OpenSceneGraph)

# Configure OpenSceneGraph
SET(DYNAMIC_OPENSCENEGRAPH ON CACHE INTERNAL "")
SET(DYNAMIC_OPENTHREADS ON CACHE INTERNAL "")
SET(BUILD_OSG_EXAMPLES OFF CACHE INTERNAL "")
SET(BUILD_OSG_APPLICATIONS OFF CACHE INTERNAL "")
SET(OSG_TEXT_USE_FONTCONFIG OFF CACHE INTERNAL "")
SET(OSG_GL_LIBRARY_STATIC OFF CACHE INTERNAL "")

ADD_COMPILE_DEFINITIONS(OSG_LIBRARY_STATIC)

# Add OpenSceneGraph
FETCHCONTENT_DECLARE(
  ${OPENSCENEGRAPH_PREFIX}
  PREFIX ${OPENSCENEGRAPH_PREFIX}
  GIT_REPOSITORY ${OPENSCENEGRAPH_URL}
  GIT_TAG ${OPENSCENEGRAPH_TAG}
)

FETCHCONTENT_GETPROPERTIES(${OPENSCENEGRAPH_PREFIX})

IF(NOT ${OPENSCENEGRAPH_PREFIX}_POPULATED)
  FETCHCONTENT_POPULATE(${OPENSCENEGRAPH_PREFIX})
  ADD_SUBDIRECTORY(${${OPENSCENEGRAPH_PREFIX}_SOURCE_DIR} ${${OPENSCENEGRAPH_PREFIX}_BINARY_DIR})
ENDIF()
