# Pastix lib requires linking to a blas library.
# It is up to the user of this module to find a BLAS and link to it.
# Pastix requires SCOTCH 

IF( DEFINED ENV{SCOTCH_ROOT} )

   SET(SCOTCH_ROOT $ENV{SCOTCH_ROOT} CACHE PATH "scotch library location")

ENDIF()

FIND_PATH(SCOTCH_INCLUDE_DIRS
		NAMES scotch.h scotchf.h 
		HINTS ${SCOTCH_ROOT}
		PATH_SUFFIXES include Include INCLUDE
		DOC "PATH TO scotch.h and scotchf.h")

FIND_LIBRARY(SCOTCH_LIBRARY
		NAMES scotch
		HINTS ${SCOTCH_ROOT}
		PATH_SUFFIXES lib Lib LIB
		DOC "PATH TO libscotch.a")

FIND_LIBRARY(SCOTCHERR_LIBRARY
		NAMES scotcherr
		HINTS ${SCOTCH_ROOT}
		PATH_SUFFIXES lib Lib LIB
		DOC "PATH TO libscotcherr.a")

FIND_LIBRARY(SCOTCHERREXIT_LIBRARY
		NAMES scotcherrexit
		HINTS ${SCOTCH_ROOT}
		PATH_SUFFIXES lib Lib LIB
		DOC "PATH TO libscotcherrexit.a")

SET (SCOTCH_LIBRARIES ${SCOTCH_LIBRARY};${SCOTCHERR_LIBRARY};${SCOTCHERREXIT_LIBRARY})

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SCOTCH DEFAULT_MSG SCOTCH_INCLUDE_DIRS SCOTCH_LIBRARIES)

IF(SCOTCH_FOUND)
   MESSAGE(STATUS "SCOTCH_INCLUDE_DIRS:${SCOTCH_INCLUDE_DIRS}")
   MESSAGE(STATUS "SCOTCH_LIBRARIES:${SCOTCH_LIBRARIES}")
ENDIF(SCOTCH_FOUND)

FIND_PATH(PTSCOTCH_INCLUDE_DIRS
		NAMES ptscotch.h ptscotchf.h 
		HINTS ${SCOTCH_ROOT}
		PATH_SUFFIXES include Include INCLUDE
		DOC "PATH TO ptscotch.h and ptscotchf.h")
FIND_LIBRARY(PTSCOTCH_LIBRARY
		NAMES ptscotch
		HINTS ${SCOTCH_ROOT}
		PATH_SUFFIXES lib Lib LIB
		DOC "PATH TO libptscotch.a")
FIND_LIBRARY(PTSCOTCHERR_LIBRARY
		NAMES ptscotcherr
		HINTS ${SCOTCH_ROOT}
		PATH_SUFFIXES lib Lib LIB
		DOC "PATH TO libptscotcherr.a")
FIND_LIBRARY(PTSCOTCHERREXIT_LIBRARY
		NAMES ptscotcherrexit
		HINTS ${SCOTCH_ROOT}
		PATH_SUFFIXES lib Lib LIB
		DOC "PATH TO libptscotcherrexit.a")

set (PTSCOTCH_LIBRARIES @PTSCOTCH_LIBRARY@;@PTSCOTCHERR_LIBRARY@;@PTSCOTCHERREXIT_LIBRARY@)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PTSCOTCH DEFAULT_MSG PTSCOTCH_INCLUDE_DIRS PTSCOTCH_LIBRARIES)
IF(PTSCOTCH_FOUND)
   MESSAGE(STATUS "PTSCOTCH_INCLUDE_DIR:${PTSCOTCH_INCLUDE_DIRS}")
   MESSAGE(STATUS "PTSCOTCH_LIBRARIES:${PTSCOTCH_LIBRARIES}")
ENDIF(PTSCOTCH_FOUND)

MARK_AS_ADVANCED(PTSCOTCHERREXIT_LIBRARY
                 PTSCOTCHERR_LIBRARY
                 PTSCOTCH_LIBRARY
                 PTSCOTCH_INCLUDE_DIRS
                 SCOTCHERREXIT_LIBRARY
                 SCOTCHERR_LIBRARY
                 SCOTCH_INCLUDE_DIRS
                 SCOTCH_LIBRARY)
