SET(MKL_INCLUDE_SEARCH_PATHS
  /opt/intel/mkl/include
  $ENV{MKL_HOME}/include
)

SET(MKL_LIB_SEARCH_PATHS
	/opt/intel/lib/intel64_lin
	/opt/intel/mkl/lib/intel64_lin
	$ENV{INTEL_HOME}/lib/intel64_lin
	$ENV{MKL_HOME}/lib/intel64_lin
 )

FIND_PATH(MKL_INCLUDE_DIR NAMES mkl.h PATHS ${MKL_INCLUDE_SEARCH_PATHS})
FIND_LIBRARY(MKL_LIB1 NAMES mkl_intel_lp64 PATHS ${MKL_LIB_SEARCH_PATHS})
FIND_LIBRARY(MKL_LIB2 NAMES mkl_intel_thread PATHS ${MKL_LIB_SEARCH_PATHS})
FIND_LIBRARY(MKL_LIB3 NAMES mkl_core PATHS ${MKL_LIB_SEARCH_PATHS})
FIND_LIBRARY(MKL_LIB4 NAMES iomp5 PATHS ${MKL_LIB_SEARCH_PATHS})
FIND_LIBRARY(MKL_LIB5 NAMES mkl_avx512_mic PATHS ${MKL_LIB_SEARCH_PATHS})
FIND_LIBRARY(MKL_LIB6 NAMES mkl_def PATHS ${MKL_LIB_SEARCH_PATHS})

SET(MKL_FOUND ON)

#    Check include files
IF(NOT MKL_INCLUDE_DIR)
    SET(MKL_FOUND OFF)
    MESSAGE(STATUS "Could not find MKL include. Turning MKL_FOUND off")
ENDIF()

#    Check libraries
IF(NOT MKL_LIB1)
    SET(MKL_FOUND OFF)
    MESSAGE(STATUS "Could not find MKL lib. Turning MKL_FOUND off")
ENDIF()

IF (MKL_FOUND)
  IF (NOT MKL_FIND_QUIETLY)
    MESSAGE(STATUS "Found MKL libraries: ${MKL_LIB1} ${MKL_LIB2} ${MKL_LIB3} ${MKL_LIB4} ${MKL_LIB5} ${MKL_LIB6}")
    MESSAGE(STATUS "Found MKL include: ${MKL_INCLUDE_DIR}")
  ENDIF (NOT MKL_FIND_QUIETLY)
ELSE (MKL_FOUND)
  IF (MKL_FIND_REQUIRED)
    MESSAGE(FATAL_ERROR "Could not find MKL")
  ENDIF (MKL_FIND_REQUIRED)
ENDIF (MKL_FOUND)

MARK_AS_ADVANCED(
    MKL_INCLUDE_DIR
    MKL_LIB1
    MKL_LIB2
    MKL_LIB3
    MKL_LIB4
    MKL_LIB5
    MKL_LIB6
    MKL
)
