# Find LAPACK (finds BLAS also) if not already found
IF(NOT LAPACK_FOUND)
  IF(DEFINED LAPACK_DIR)
    set(BLA_STATIC ON)
	# Make sure we have an absolute path
	GET_FILENAME_COMPONENT(LAPACK_DIR_ABS "${LAPACK_DIR}" ABSOLUTE)
	#MESSAGE("LAPACK_DIR_ABS: ${LAPACK_DIR_ABS}")
	SET(BLAS_PATH "${LAPACK_DIR_ABS}/blas${CMAKE_STATIC_LIBRARY_SUFFIX}")
	SET(LAPACK_PATH "${LAPACK_DIR_ABS}/lapack${CMAKE_STATIC_LIBRARY_SUFFIX}")
	
	SET(BLAS_FOUND ON CACHE BOOL "Blas found?" FORCE)
	SET(LAPACK_FOUND ON CACHE BOOL "Lapack found?" FORCE)
	SET(BLAS_LIBRARIES "${BLAS_PATH}" CACHE FILEPATH "Blas path" FORCE)
	SET(LAPACK_LIBRARIES "${LAPACK_PATH};${BLAS_PATH}" CACHE FILEPATH "Lapack path" FORCE)
	
	# MESSAGE("BLAS_FOUND: ${BLAS_FOUND}")
	# MESSAGE("LAPACK_FOUND: ${LAPACK_FOUND}")
	# MESSAGE("BLAS_LIBRARIES: ${BLAS_LIBRARIES}")
	# MESSAGE("LAPACK_LIBRARIES: ${LAPACK_LIBRARIES}")
	# MESSAGE("BLA_STATIC: ${BLA_STATIC}")
  ELSE(DEFINED LAPACK_DIR)
    FIND_PACKAGE(LAPACK REQUIRED)
  ENDIF(DEFINED LAPACK_DIR)
ENDIF(NOT LAPACK_FOUND)
