# Find TOBII
#
# This module defines
#  TOBII_FOUND
#  TOBII_INCLUDE_DIRS
#  TOBII_LIBRARIES
#
# Copyright (c) 2012 I-maginer
# 
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA, or go to
# http://www.gnu.org/copyleft/lesser.txt
#

# On a new cmake run, we do not need to be verbose
IF(TOBII_INCLUDE_DIR AND TOBII_LIBRARY)
	SET(TOBII_FIND_QUIETLY TRUE)
ENDIF()

# If TOBII_ROOT was defined in the environment, use it.
if (NOT TOBII_ROOT)
  if(NOT "$ENV{TOBII_ROOT}" STREQUAL "")
    set(TOBII_ROOT $ENV{TOBII_ROOT})
  else()
    set(TOBII_ROOT $ENV{SCOL_DEPENDENCIES_PATH}/tobii)
  endif()
endif()

# concat all the search paths
IF(TOBII_ROOT)
	SET(TOBII_INCLUDE_SEARCH_DIRS
	  ${TOBII_INCLUDE_SEARCH_DIRS}
	  ${TOBII_ROOT}/include/eyex
  )
  
  if(WIN32 AND (WIN64 OR (CMAKE_SIZEOF_VOID_P EQUAL 8)))
  SET(TOBII_LIBRARY_SEARCH_RELEASE_DIRS 
    ${TOBII_LIBRARY_SEARCH_DIRS}
    ${TOBII_ROOT}/lib/x64
  )
  SET(TOBII_LIBRARY_SEARCH_DEBUG_DIRS 
    ${TOBII_LIBRARY_SEARCH_DIRS}
    ${TOBII_ROOT}/lib/x64
  )
  else ()
  SET(TOBII_LIBRARY_SEARCH_RELEASE_DIRS 
    ${TOBII_LIBRARY_SEARCH_DIRS}
    ${TOBII_ROOT}/lib/x86
  )
  SET(TOBII_LIBRARY_SEARCH_DEBUG_DIRS 
    ${TOBII_LIBRARY_SEARCH_DIRS}
    ${TOBII_ROOT}/lib/x86
  )
  endif ()
ENDIF()

# log message
IF (NOT TOBII_FIND_QUIETLY)
	MESSAGE(STATUS "Checking for TOBII library")
ENDIF()

# Search for header files
FIND_PATH(TOBII_INCLUDE_DIR EyeX.h
  PATHS ${TOBII_INCLUDE_SEARCH_DIRS})

# Search for libraries files (release mode)
FIND_LIBRARY(TOBII_LIBRARY_RELEASE Tobii.EyeX.Client
  PATHS ${TOBII_LIBRARY_SEARCH_RELEASE_DIRS})

# Search for libraries files (debug mode)
FIND_LIBRARY(TOBII_LIBRARY_DEBUG Tobii.EyeX.Client
  PATHS ${TOBII_LIBRARY_SEARCH_DEBUG_DIRS})

# Configure libraries for debug/release
SET(TOBII_INCLUDE_DIRS ${TOBII_INCLUDE_DIR} ${TOBII_ROOT}/Src CACHE STRING "Directory containing TOBII header files")
SET(TOBII_LIBRARY debug ${TOBII_LIBRARY_DEBUG} optimized ${TOBII_LIBRARY_RELEASE})
SET(TOBII_LIBRARIES "${TOBII_LIBRARY}" CACHE STRING "TOBII libraries files")

IF(TOBII_INCLUDE_DIR AND TOBII_LIBRARY)
	SET(TOBII_FOUND TRUE)
ENDIF()

# Hide those variables in GUI
SET(TOBII_INCLUDE_DIR ${TOBII_INCLUDE_DIR} CACHE INTERNAL "")
SET(TOBII_LIBRARY_RELEASE ${TOBII_LIBRARY_RELEASE} CACHE INTERNAL "")
SET(TOBII_LIBRARY_DEBUG ${TOBII_LIBRARY_DEBUG} CACHE INTERNAL "")
SET(TOBII_LIBRARY ${TOBII_LIBRARY} CACHE INTERNAL "")

# log find result
IF(TOBII_FOUND)
	IF(NOT TOBII_FIND_QUIETLY)
		MESSAGE(STATUS "  libraries: ${TOBII_LIBRARIES}")
		MESSAGE(STATUS "  includes: ${TOBII_INCLUDE_DIRS}")
	ENDIF()
ELSE(TOBII_FOUND)
	IF(NOT TOBII_LIBRARIES)
		MESSAGE(STATUS, "TOBII library or one of it dependencies could not be found.")
	ENDIF()
	IF(NOT TOBII_INCLUDE_DIRS)
		MESSAGE(STATUS "TOBII include files could not be found.")
	ENDIF()
ENDIF(TOBII_FOUND)