# Check CUDA installation
FIND_PATH(CUDA_FOUND_INCLUDE_PATH cublas_v2.h
  HINTS ${CUDA_INSTALL_PATH}/include
  NO_DEFAULT_PATH
)
FIND_LIBRARY(CUBLAS_FOUND_LIBRARY NAMES cublas 
  HINTS ${CUDA_INSTALL_PATH}/lib ${CUDA_INSTALL_PATH}/lib64
  NO_DEFAULT_PATH
)
# FIND_LIBRARY(CUSOLVER_FOUND_LIBRARY NAMES cusolver
#   HINTS ${CUDA_INSTALL_PATH}/lib ${CUDA_INSTALL_PATH}/lib64
#   NO_DEFAULT_PATH
# )
# FIND_LIBRARY(CUSPARSE_FOUND_LIBRARY NAMES cusparse
#   HINTS ${CUDA_INSTALL_PATH}/lib ${CUDA_INSTALL_PATH}/lib64
#   NO_DEFAULT_PATH
# )

IF (CUDA_FOUND_INCLUDE_PATH)
  IF (CUBLAS_FOUND_LIBRARY)
    ADD_LIBRARY(cublas INTERFACE)
    SET_TARGET_PROPERTIES(cublas PROPERTIES
      INTERFACE_INCLUDE_DIRECTORIES ${CUDA_FOUND_INCLUDE_PATH}
      INTERFACE_COMPILE_OPTIONS "-I${CUDA_FOUND_INCLUDE_PATH}"
      INTERFACE_LINK_LIBRARIES ${CUBLAS_FOUND_LIBRARY} 
    )
    INSTALL(TARGETS cublas
      EXPORT tines-targets
      LIBRARY DESTINATION "${TINES_INSTALL_LIB_PATH}"
      ARCHIVE DESTINATION "${TINES_INSTALL_LIB_PATH}"
    )
    SET(CUBLAS_FOUND ON)
    MESSAGE("-- CUBLAS is found at ${CUBLAS_FOUND_LIBRARY}")
  ENDIF()
  # IF (CUSOLVER_FOUND_LIBRARY)
  #   ADD_LIBRARY(cusolver INTERFACE)
  #   SET_TARGET_PROPERTIES(cusolver PROPERTIES
  #     INTERFACE_LINK_LIBRARIES ${CUSOLVER_FOUND_LIBRARY}
  #   )
  #   INSTALL(TARGETS cusolver
  #     EXPORT tines-targets
  #     LIBRARY DESTINATION "${TINES_INSTALL_LIB_PATH}"
  #     ARCHIVE DESTINATION "${TINES_INSTALL_LIB_PATH}"
  #   )
  #   SET(CUSOLVER_FOUND ON)
  #   MESSAGE("-- CUSOLVER  is found at ${CUSOLVER_FOUND_LIBRARY}")
  # ENDIF()

ELSE()
   MESSAGE(FATAL_ERROR "-- CUDA LIBS (CUBLAS) are not found at ${CUDA_INSTALL_PATH}")
ENDIF()
