# Find Bullet
# Find the Bullet Physics includes and libraries. Bullet is spread out
#   over multiple libraries: SoftBody, Dynamics, LinearMath, and Collision.
#   Because of reasons, cmake only finds one at a time, so all 4 variables
#   that are set must be linked
#
#  BULLET_INCLUDE_DIRS - where to find headers
#  BULLET_<type>_FOUND - True if Bullet was found.
#                        <type> is one of COLLISION, DYNAMICS, LINEARMATH, or SOFTBODY
#  BULLET_<type>_LIBARIES - the library locations. each should be linked as needed.
#
# Based on the FindSOIL.cmake module.

IF (BULLET_INCLUDE_DIR)
  # Already in cache, be silent
  SET(BULLET_FIND_QUIETLY TRUE)
ENDIF (BULLET_INCLUDE_DIR)


FIND_PATH(BULLET_INCLUDE_DIR  bullet/btBulletDynamicsCommon.h)
INCLUDE_DIRECTORIES ("${BULLET_INCLUDE_DIR}/bullet")
IF(APPLE)
	# Certain parts of the code specify the bullet/ prefix when including bullet headers.
	INCLUDE_DIRECTORIES ("${BULLET_INCLUDE_DIR}")
ENDIF(APPLE)
FIND_LIBRARY(BULLET_SOFTBODY_LIBRARY  NAMES BulletSoftBody PATH_SUFFIXES lib64 )
FIND_LIBRARY(BULLET_DYNAMICS_LIBRARY  NAMES BulletDynamics PATH_SUFFIXES lib64 )
FIND_LIBRARY(BULLET_COLLISION_LIBRARY NAMES BulletCollision PATH_SUFFIXES lib64 )
FIND_LIBRARY(BULLET_LINEARMATH_LIBRARY NAMES LinearMath PATH_SUFFIXES lib64 )
MARK_AS_ADVANCED(   BULLET_SOFTBODY_LIBRARY
                    BULLET_DYNAMICS_LIBRARY
                    BULLET_COLLISION_LIBRARY
                    BULLET_LINEARMATH_LIBRARY
                    BULLET_INCLUDE_DIR)

# Per-recommendation
SET(BULLET_INCLUDE_DIRS "${BULLET_INCLUDE_DIR}")
SET(BULLET_SOFTBODY_LIBRARIES "${BULLET_SOFTBODY_LIBRARY}")
SET(BULLET_DYNAMICS_LIBRARIES "${BULLET_DYNAMICS_LIBRARY}")
SET(BULLET_COLLISION_LIBRARIES "${BULLET_COLLISION_LIBRARY}")
SET(BULLET_LINEARMATH_LIBRARIES "${BULLET_LINEARMATH_LIBRARY}")

# handle the QUIETLY and REQUIRED arguments and set BULLET_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(BULLET_SOFTBODY DEFAULT_MSG BULLET_SOFTBODY_LIBRARIES BULLET_INCLUDE_DIRS)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(BULLET_DYNAMICS DEFAULT_MSG BULLET_DYNAMICS_LIBRARIES BULLET_INCLUDE_DIRS)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(BULLET_COLLISION DEFAULT_MSG BULLET_COLLISION_LIBRARIES BULLET_INCLUDE_DIRS)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(BULLET_LINEARMATH DEFAULT_MSG BULLET_LINEARMATH_LIBRARIES BULLET_INCLUDE_DIRS)
