## Generated by CMAKE from UseSuiteSparseForInstall.cmake.in file !!
##
## UseSuiteSparse.cmake is included by the SuiteSparseConfig.cmake from the install dir.
## It allow to find SuiteSparse for another project.
## When find_package(SuiteSparse) is used in another project,
## SuiteSparseConfig.cmake is found from the SuiteSparse_DIR (the install dir).
##
## This file do some things for you (and according metis is build or not): 
##   * he set the link_directories (with SuiteSparse_LIB_DIRS) where we can find all libraries
##   * he set the include_directories (with SuiteSparse_INCLUDE_DIRS) where we can find all headers files
##
## This file provide :
##	 * The name of the SuiteSparse targets as IMPORTED (so you can use directly the name of the target for target_link_libraries(...))
##   * SuiteSparse_LIBRARIES : an "all in one" help cmake variable, which contain all libraries for use SuiteSparse  for target_link_libraries(...)
##   On windows:
##   * SuiteSparse_LAPACK_BLAS_LIBRARIES: which contain the libblas and liblapack libraries
##   * SuiteSparse_LAPACK_BLAS_DLL		: which contain all requiered binaries for use libblas and liblapack
##
## OPT (win): Given the cmake flag : set(SuiteSparse_USE_LAPACK_BLAS ON)
## before using the Find_package(SuiteSparse) instruction,
## will set (for windows only) the link for liblapack and libblas
##
## Created by jesnault (jerome.esnault@inria.fr) 2014-01-21
## Updated by jesnault (jerome.esnault@inria.fr) 2014-01-21

## get the root path (install dir)
get_filename_component(SuiteSparse_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)


## libs
set(SuiteSparse_LIBRARIES 	"")
set(SuiteSparse_LIB_DIR 	"${SuiteSparse_DIR}/lib64")

if(WIN32 AND SuiteSparse_USE_LAPACK_BLAS)
	set(SuiteSparse_LAPACK_BLAS_LIB_DIR 		"${SuiteSparse_DIR}/")
	file(GLOB SuiteSparse_LAPACK_BLAS_LIBRARIES "${SuiteSparse_LAPACK_BLAS_LIB_DIR}/*.lib")
	file(GLOB SuiteSparse_LAPACK_BLAS_DLL 		"${SuiteSparse_LAPACK_BLAS_LIB_DIR}/*.dll")
	
	if(SuiteSparse_LAPACK_BLAS_LIBRARIES AND SuiteSparse_LAPACK_BLAS_DLL)
		add_library(blas SHARED IMPORTED)
		set_property(TARGET blas PROPERTY IMPORTED_LOCATION "${SuiteSparse_LAPACK_BLAS_LIB_DIR}/libblas.dll")
		set_property(TARGET blas PROPERTY IMPORTED_IMPLIB 	"${SuiteSparse_LAPACK_BLAS_LIB_DIR}/libblas.lib")
		
		add_library(lapack SHARED IMPORTED)
		set_property(TARGET lapack PROPERTY IMPORTED_LOCATION 	"${SuiteSparse_LAPACK_BLAS_LIB_DIR}/liblapack.dll")
		set_property(TARGET lapack PROPERTY IMPORTED_IMPLIB 	"${SuiteSparse_LAPACK_BLAS_LIB_DIR}/liblapack.lib")
	
		list(APPEND SuiteSparse_LIBRARIES blas lapack)
	endif()
else()
	set(SuiteSparse_LAPACK_BLAS_LIB_DIR "")
endif()

set(SuiteSparse_LIB_DIRS 	"${SuiteSparse_LIB_DIR}" "${SuiteSparse_LAPACK_BLAS_LIB_DIR}")
link_directories(${SuiteSparse_LIB_DIRS})

set(SuiteSparse_CMAKE_CONFIG "${SuiteSparse_DIR}/cmake/SuiteSparse-config64.cmake")
if(EXISTS "${SuiteSparse_CMAKE_CONFIG}")

	## From SuiteSparse project => the install EXPORT cmd => cmake provide all imported target
	include(${SuiteSparse_CMAKE_CONFIG})
	
	## libs (get from the export cmake file) => in order to fill the SuiteSparse_LIBRARIES
	file(READ "${SuiteSparse_CMAKE_CONFIG}" SuiteSparseConfigContent)
	STRING(REGEX REPLACE "\r?\n" ";" SuiteSparseConfigContent "${SuiteSparseConfigContent}")
	foreach(line ${SuiteSparseConfigContent})
		string(REGEX MATCH "ADD_LIBRARY\\(.* SHARED IMPORTED" sharedMatchedUC ${line})
		string(REGEX MATCH "add_library\\(.* SHARED IMPORTED" sharedMatched ${line})
		if( sharedMatchedUC )
			string(REGEX REPLACE "ADD_LIBRARY\\((.*) SHARED IMPORTED" "\\1" libName ${sharedMatchedUC})
			list(APPEND SuiteSparse_LIBRARIES ${libName}) # the final cmake variable other project can use
		elseif( sharedMatched )
			string(REGEX REPLACE "add_library\\((.*) SHARED IMPORTED" "\\1" libName ${sharedMatched})
			list(APPEND SuiteSparse_LIBRARIES ${libName}) # the final cmake variable other project can use
		endif()
		
		string(REGEX MATCH "ADD_LIBRARY\\(.* STATIC IMPORTED" staticMatchedUC ${line})
		string(REGEX MATCH "add_library\\(.* STATIC IMPORTED" staticMatched ${line})
		if( staticMatchedUC )
			string(REGEX REPLACE "ADD_LIBRARY\\((.*) STATIC IMPORTED" "\\1" libName ${staticMatchedUC})
			list(APPEND SuiteSparse_LIBRARIES ${libName}) # the final cmake variable other project can use
		elseif( staticMatched )
			string(REGEX REPLACE "add_library\\((.*) STATIC IMPORTED" "\\1" libName ${staticMatched})
			list(APPEND SuiteSparse_LIBRARIES ${libName}) # the final cmake variable other project can use
		endif()
	endforeach()
	
else()
	message(WARNING "${SuiteSparse_CMAKE_CONFIG} not found...\n Can't fill SuiteSparse_LIBRARIES...\n set SuiteSparse_DIR cmake variable to the dir we can find this file.")
endif()


## include (get from the install of the public headers)
if("OFF" STREQUAL "ON") # BUILD_METIS?
	set(SuiteSparse_METIS_INCLUDE_DIR "${SuiteSparse_DIR}/include")
	ADD_DEFINITIONS(-DNPARTITION)
else()
	set(SuiteSparse_METIS_INCLUDE_DIR "")
endif()

set(SuiteSparse_INCLUDE_DIR  "${SuiteSparse_DIR}/include/suitesparse")
set(SuiteSparse_INCLUDE_DIRS "${SuiteSparse_INCLUDE_DIR}" "${SuiteSparse_METIS_INCLUDE_DIR}")
include_directories(${SuiteSparse_INCLUDE_DIRS})

