# Find OGREBullet includes and library
#
# This module defines
#  OGREBULLET_INCLUDE_DIR
#  OGREBULLET_LIBRARIES, the libraries to link against to use Bullet.
#  OGREBULLET_LIB_DIR, the location of the libraries
#  OGREBULLET_FOUND, If false, do not try to use Bullet
#
# Copyright 2007, Matt Williams
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

IF (OGREBULLET_LIBRARIES AND OGREBULLET_INCLUDE_DIR)
	SET(OGREBULLET_FIND_QUIETLY TRUE) # Already in cache, be silent
ENDIF (OGREBULLET_LIBRARIES AND OGREBULLET_INCLUDE_DIR)

IF (WIN32) #Windows
	MESSAGE(STATUS "Looking for OGREBullet")
	##SET(OGRESDK $ENV{OGRE_HOME})
	SET(OGREBULLETSOURCE $ENV{OGREBULLET_HOME})
	#IF (OGRESDK)
	#	MESSAGE(STATUS "Using OGRE SDK")
	#	STRING(REGEX REPLACE "[\\]" "/" OGRESDK "${OGRESDK}")
	#	SET(OGRE_INCLUDE_DIR ${OGRESDK}/include)
	#	SET(OGRE_LIB_DIR ${OGRESDK}/lib)
	#	SET(OGRE_LIBRARIES debug OgreMain_d optimized OgreMain)
	#ENDIF (OGRESDK)
	IF (OGREBULLETSOURCE)
		MESSAGE(STATUS "Using OGREBullet built from source")
		SET(OGREBULLET_INCLUDE_DIR $ENV{OGREBULLET_HOME}/Collisions/include $ENV{OGREBULLET_HOME}/Dynamics/include)
		SET(OGREBULLET_LIB_DIR $ENV{OGREBULLET_HOME}/lib/Debug $ENV{OGREBULLET_HOME}/lib/Release)
		SET(OGREBULLET_LIBRARIES debug OgreBulletCollisions_d debug OgreBulletDynamics_d optimized OgreBulletCollisions optimized OgreBulletDynamics)
	ENDIF (OGREBULLETSOURCE)
ELSE (WIN32) #Unix
	SET(OGREBULLET_INCLUDE_DIR ${OGREBULLET_HOME}/include/OgreBullet/Collisions ${OGREBULLET_HOME}/include/OgreBullet/Dynamics)
	SET(OGREBULLET_LIB_DIR ${OGREBULLET_HOME}/lib)
	SET(OGREBULLET_LIBRARIES debug OgreBulletCol_d debug OgreBulletDyn_d optimized OgreBulletCol optimized OgreBulletDyn)
ENDIF (WIN32)

#Do some preparation
SEPARATE_ARGUMENTS(OGREBULLET_INCLUDE_DIR)
SEPARATE_ARGUMENTS(OGREBULLET_LIBRARIES)

SET(OGREBULLET_INCLUDE_DIR ${OGREBULLET_INCLUDE_DIR} CACHE PATH "")
SET(OGREBULLET_LIBRARIES ${OGREBULLET_LIBRARIES} CACHE STRING "")
SET(OGREBULLET_LIB_DIR ${OGREBULLET_LIB_DIR} CACHE PATH "")

IF (OGREBULLET_INCLUDE_DIR AND OGREBULLET_LIBRARIES)
	SET(OGREBULLET_FOUND TRUE)
ENDIF (OGREBULLET_INCLUDE_DIR AND OGREBULLET_LIBRARIES)

IF (OGREBULLET_FOUND)
	IF (NOT OGREBULLET_FIND_QUIETLY)
		MESSAGE(STATUS "  libraries : ${OGREBULLET_LIBRARIES} from ${OGREBULLET_LIB_DIR}")
		MESSAGE(STATUS "  includes  : ${OGREBULLET_INCLUDE_DIR}")
	ENDIF (NOT OGREBULLET_FIND_QUIETLY)
ELSE (OGREBULLET_FOUND)
	IF (OGREBULLET_FIND_REQUIRED)
		MESSAGE(FATAL_ERROR "Could not find OGREBullet")
	ENDIF (OGREBULLET_FIND_REQUIRED)
ENDIF (OGREBULLET_FOUND)
