# Find SOIL
# Find the SOIL includes and library
#
#  SOIL_INCLUDE_DIRS - where to find SOIL.h, etc.
#  SOIL_LIBRARIES    - List of libraries when using SOIL.
#  SOIL_FOUND        - True if SOIL found.
#
# Based on the FindZLIB.cmake module.

IF (SOIL_INCLUDE_DIR)
  # Already in cache, be silent
  SET(SOIL_FIND_QUIETLY TRUE)
ENDIF (SOIL_INCLUDE_DIR)

FIND_PATH(SOIL_INCLUDE_DIR SOIL.h PATH_SUFFIXES include/SOIL include)
IF (APPLE)
	# For the case where SOIL is installed in a non-standard lib path such as /opt or /sw
	FIND_PATH(SOIL_INCLUDE_DIR_NO_SUFFIX SOIL/SOIL.h)
	INCLUDE_DIRECTORIES( "${SOIL_INCLUDE_DIR_NO_SUFFIX}")
ENDIF (APPLE)

IF (APPLE)
	# Prefer the Static lib.
	SET(SOIL_NAMES libSoil.a SOIL Soil soil)
ELSE (APPLE)
	SET(SOIL_NAMES SOIL Soil soil)
ENDIF (APPLE)
FIND_LIBRARY(SOIL_LIBRARY NAMES ${SOIL_NAMES} )
MARK_AS_ADVANCED( SOIL_LIBRARY SOIL_INCLUDE_DIR )

# Per-recommendation
SET(SOIL_INCLUDE_DIRS "${SOIL_INCLUDE_DIR}")
SET(SOIL_LIBRARIES    "${SOIL_LIBRARY}")

# handle the QUIETLY and REQUIRED arguments and set SOIL_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SOIL DEFAULT_MSG SOIL_LIBRARIES SOIL_INCLUDE_DIRS)
