# this module look for tbb support
#
# TBB_FOUND = boolean
# TBB_INCLUDE_DIR = where tbb/tbb.h can be found
# TBB_LIBRARIES =  -L${TBB_LIBDIR} -ltbbmalloc -ltbb
#
SET(TBB_FOUND FALSE)
FIND_PATH(TBB_INCLUDE_DIR tbb/tbb.h ${TBB_HOME}/include $ENV{TBB_HOME}/include)
SET(TBB_LIBRARIES)

IF(TBB_INCLUDE_DIR)

  SET(TBB_FOUND TRUE)

  STRING(REGEX REPLACE "include" "lib" TBB_LIBDIR "${TBB_INCLUDE_DIR}")

  if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386")
    set(TBB_LIBDIR "${TBB_LIBDIR}/ia32")
  endif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386")
  if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
    set(TBB_LIBDIR "${TBB_LIBDIR}/intel64")
  endif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")

  find_library(TBBMALLOC_LIB tbbmalloc ${TBB_LIBDIR})
  find_library(TBB_LIB tbb ${TBB_LIBDIR})

  SET(TBB_LIBRARIES ${TBBMALLOC_LIB} ${TBB_LIB})
  MESSAGE(STATUS "TBB_INCLUDE_DIR=${TBB_INCLUDE_DIR}")
  MESSAGE(STATUS "TBB_LIBRARIES=${TBB_LIBRARIES}")

ENDIF(TBB_INCLUDE_DIR)

MARK_AS_ADVANCED (
   TBB_FOUND
   TBB_INCLUDE_DIR
   TBB_LIBRARIES
)
