# This module defines

# OSG_LIBRARY
# OSG_FOUND, if false, do not try to link to osg
# OSG_INCLUDE_DIRS, where to find the headers
# OSG_INCLUDE_DIR, where to find the source headers
# OSG_GEN_INCLUDE_DIR, where to find the generated headers

# to use this module, set variables to point to the osg build
# directory, and source directory, respectively
# OSGDIR or OSG_SOURCE_DIR: osg source directory, typically OpenSceneGraph
# OSG_DIR or OSG_BUILD_DIR: osg build directory, place in which you've
#    built osg via cmake 

# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
# #include <osgUtil/SceneView>

###### headers ######

SET(OSG_DIR "" CACHE PATH "Set to base OpenSceneGraph install path")

FIND_PATH(OSG_INCLUDE_DIR osg/Node
    PATHS
        ${OSG_DIR}
        $ENV{OSG_SOURCE_DIR}
        $ENV{OSGDIR}
        $ENV{OSG_DIR}
        $ENV{OSG}
        $ENV{OSG}
        /usr/local/
        /usr/
        /sw/ # Fink
        /opt/local/ # DarwinPorts
        /opt/csw/ # Blastwave
        /opt/
        [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/
        ~/Library/Frameworks
        /Library/Frameworks
    PATH_SUFFIXES
        /include
)

FIND_PATH(OSG_GEN_INCLUDE_DIR osg/Config
    PATHS
        ${OSG_DIR}
        $ENV{OSG_SOURCE_DIR}
        $ENV{OSGDIR}
        $ENV{OSG_DIR}
        $ENV{OSG}
        /usr/local/
        /usr/
        /sw/ # Fink
        /opt/local/ # DarwinPorts
        /opt/csw/ # Blastwave
        /opt/
        [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/
        ~/Library/Frameworks
        /Library/Frameworks
    PATH_SUFFIXES
        /include
)

###### libraries ######

MACRO( FIND_OSG_LIBRARY MYLIBRARY MYLIBRARYNAME )

FIND_LIBRARY(${MYLIBRARY}
    NAMES
        ${MYLIBRARYNAME}
    PATHS
        ${OSG_DIR}
        $ENV{OSG_BUILD_DIR}
        $ENV{OSG_DIR}
        $ENV{OSGDIR}
        $ENV{OSG_ROOT}
        $ENV{OSG}
        ~/Library/Frameworks
        /Library/Frameworks
        /usr/local
        /usr
        /sw
        /opt/local
        /opt/csw
        /opt
        [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/lib
        /usr/freeware
    PATH_SUFFIXES
        /lib/
        /lib64/
        /build/lib/
        /build/lib64/
        /Build/lib/
        /Build/lib64/
     )

ENDMACRO(FIND_OSG_LIBRARY LIBRARY LIBRARYNAME)

FIND_OSG_LIBRARY( OSG_LIBRARY_RELEASE osg )
FIND_OSG_LIBRARY( OSG_LIBRARY_DEBUG osgd )
IF (OSG_LIBRARY_RELEASE)
    SET(OSG_LIBRARY ${OSG_LIBRARY_RELEASE})
ELSE (OSG_LIBRARY_RELEASE)
    SET(OSG_LIBRARY ${OSG_LIBRARY_DEBUG})
ENDIF (OSG_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGUTIL_LIBRARY_RELEASE osgUtil )
FIND_OSG_LIBRARY( OSGUTIL_LIBRARY_DEBUG osgUtild)
IF (OSGUTIL_LIBRARY_RELEASE)
    SET(OSGUTIL_LIBRARY ${OSGUTIL_LIBRARY_RELEASE})
ELSE (OSGUTIL_LIBRARY_RELEASE)
    SET(OSGUTIL_LIBRARY ${OSGUTIL_LIBRARY_DEBUG})
ENDIF (OSGUTIL_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGDB_LIBRARY_RELEASE osgDB )
FIND_OSG_LIBRARY( OSGDB_LIBRARY_DEBUG osgDBd)
IF (OSGDB_LIBRARY_RELEASE)
    SET(OSGDB_LIBRARY ${OSGDB_LIBRARY_RELEASE})
ELSE (OSGDB_LIBRARY_RELEASE)
    SET(OSGDB_LIBRARY ${OSGDB_LIBRARY_DEBUG})
ENDIF (OSGDB_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGTEXT_LIBRARY_RELEASE osgText )
FIND_OSG_LIBRARY( OSGTEXT_LIBRARY_DEBUG osgTextd )
IF (OSGTEXT_LIBRARY_RELEASE)
    SET(OSGTEXT_LIBRARY ${OSGTEXT_LIBRARY_RELEASE})
ELSE (OSGTEXT_LIBRARY_RELEASE)
    SET(OSGTEXT_LIBRARY ${OSGTEXT_LIBRARY_DEBUG})
ENDIF (OSGTEXT_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGTERRAIN_LIBRARY_RELEASE osgTerrain )
FIND_OSG_LIBRARY( OSGTERRAIN_LIBRARY_DEBUG osgTerraind )
IF (OSG_LIBRARY_RELEASE)
    SET(OSGTERRAIN ${OSGTERRAIN_LIBRARY_RELEASE})
ELSE (OSG_LIBRARY_RELEASE)
    SET(OSGTERRAIN ${OSGTERRAIN_LIBRARY_DEBUG})
ENDIF (OSG_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGFX_LIBRARY_RELEASE osgFX )
FIND_OSG_LIBRARY( OSGFX_LIBRARY_DEBUG osgFXd )
IF (OSGFX_LIBRARY_RELEASE)
SET( OSGFX_LIBRARY ${OSGFX_LIBRARY_RELEASE})
ELSE (OSGFX_LIBRARY_RELEASE)
    SET( OSGFX_LIBRARY ${OSGFX_LIBRARY_DEBUG})
ENDIF (OSGFX_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGSIM_LIBRARY_RELEASE osgSim )
FIND_OSG_LIBRARY( OSGSIM_LIBRARY_DEBUG osgSimd )
IF (OSGSIM_LIBRARY_RELEASE)
    SET(OSGSIM_LIBRARY ${OSGSIM_LIBRARY_RELEASE})
ELSE (OSGSIM_LIBRARY_RELEASE)
    SET(OSGSIM_LIBRARY ${OSGSIM_LIBRARY_DEBUG})
ENDIF (OSGSIM_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGVIEWER_LIBRARY_RELEASE osgViewer )
FIND_OSG_LIBRARY( OSGVIEWER_LIBRARY_DEBUG osgViewerd )
IF (OSG_LIBRARY_RELEASE)
    SET(OSGVIEWER_LIBRARY ${OSGVIEWER_LIBRARY_RELEASE})
ELSE (OSG_LIBRARY_RELEASE)
    SET(OSGVIEWER_LIBRARY ${OSGVIEWER_LIBRARY_DEBUG})
ENDIF (OSG_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGGA_LIBRARY_RELEASE osgGA )
FIND_OSG_LIBRARY( OSGGA_LIBRARY_DEBUG osgGAd )
IF (OSGGA_LIBRARY_RELEASE)
    SET(OSGGA_LIBRARY ${OSGGA_LIBRARY_RELEASE})
ELSE (OSGGA_LIBRARY_RELEASE)
    SET(OSGGA_LIBRARY ${OSGGA_LIBRARY_DEBUG})
ENDIF (OSGGA_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGWIDGET_LIBRARY_RELEASE osgWidget )
FIND_OSG_LIBRARY( OSGWIDGET_LIBRARY_DEBUG osgWidgetd )
IF (OSGWIDGET_LIBRARY_RELEASE)
    SET(OSGWIDGET_LIBRARY ${OSGWIDGET_LIBRARY_RELEASE})
ELSE (OSGWIDGET_LIBRARY_RELEASE)
    SET(OSGWIDGET_LIBRARY ${OSGWIDGET_LIBRARY_DEBUG})
ENDIF (OSGWIDGET_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGSHADOW_LIBRARY_RELEASE osgShadow )
FIND_OSG_LIBRARY( OSGSHADOW_LIBRARY_DEBUG osgShadowd )
IF (OSGSHADOW_LIBRARY_RELEASE)
    SET(OSGSHADOW_LIBRARY ${OSGSHADOW_LIBRARY_RELEASE})
ELSE (OSGSHADOW_LIBRARY_RELEASE)
    SET(OSGSHADOW_LIBRARY ${OSGSHADOW_LIBRARY_DEBUG})
ENDIF (OSGSHADOW_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGMANIPULATOR_LIBRARY_RELEASE osgManipulator )
FIND_OSG_LIBRARY( OSGMANIPULATOR_LIBRARY_DEBUG osgManipulatord )
IF (OSGMANIPULATOR_LIBRARY_RELEASE)
    SET(OSGMANIPULATOR_LIBRARY ${OSGMANIPULATOR_LIBRARY_RELEASE})
ELSE (OSGMANIPULATOR_LIBRARY_RELEASE)
    SET(OSGMANIPULATOR_LIBRARY ${OSGMANIPULATOR_LIBRARY_DEBUG})
ENDIF (OSGMANIPULATOR_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OSGPARTICLE_LIBRARY_RELEASE osgParticle )
FIND_OSG_LIBRARY( OSGPARTICLE_LIBRARY_DEBUG osgParticled )
IF (OSGPARTICLE_LIBRARY_RELEASE)
    SET(OSGPARTICLE_LIBRARY ${OSGPARTICLE_LIBRARY_RELEASE})
ELSE (OSGPARTICLE_LIBRARY_RELEASE)
    SET(OSGPARTICLE_LIBRARY ${OSGPARTICLE_LIBRARY_DEBUG})
ENDIF (OSGPARTICLE_LIBRARY_RELEASE)

FIND_OSG_LIBRARY( OPENTHREADS_LIBRARY_RELEASE OpenThreads )
FIND_OSG_LIBRARY( OPENTHREADS_LIBRARY_DEBUG OpenThreadsd )
IF (OPENTHREADS_LIBRARY_RELEASE)
    SET(OPENTHREADS_LIBRARY ${OPENTHREADS_LIBRARY_RELEASE})
ELSE (OPENTHREADS_LIBRARY_RELEASE)
    SET(OPENTHREADS_LIBRARY ${OPENTHREADS_LIBRARY_DEBUG})
ENDIF (OPENTHREADS_LIBRARY_RELEASE)

SET( OSG_FOUND "NO" )
IF( OSG_LIBRARY AND OSG_INCLUDE_DIR )
    SET( OSG_FOUND "YES" )
    SET( OSG_INCLUDE_DIRS ${OSG_INCLUDE_DIR} ${OSG_GEN_INCLUDE_DIR} )
    GET_FILENAME_COMPONENT( OSG_LIBRARIES_DIR ${OSG_LIBRARY} PATH )
ENDIF( OSG_LIBRARY AND OSG_INCLUDE_DIR )
