FindSuiteSparse.cmake 19.2 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1 2 3 4 5 6 7 8 9
## CMake file to locate SuiteSparse and its useful composite projects
## The first developpement of this file was made fro Windows users who
## use the http://code.google.com/p/suitesparse-metis-for-windows/
## downloaded here :
## svn checkout http://suitesparse-metis-for-windows.googlecode.com/svn/trunk/ suitesparse-metis-for-windows
## Anyway, it chould be work also on linux (tested on fedora 17 when you installed suitesparse from yum)
##
##
## Inputs variables this file can process (variable must be given before find_package(SUITESPARES ...) command) :
10 11
##   * SUITESPARSE_VERBOSE			Default to OFF
##   * SUITESPARSE_USE_LAPACK_BLAS	Default to OFF. If ON append to SUITESPARSE_LIBRARIES the blas and lapack library
Sylvain Thery's avatar
Sylvain Thery committed
12 13 14 15
##   Note: SuiteSparse lib usually requires linking to a blas and lapack library.
##
##
## Help variables this file handle internaly :
16
##   * SUITESPARSE_SEARCH_LIB_POSTFIX		Is set in cache (as advanced) to look into the right lib/lib64 dir for libraries (user can change)
Sylvain Thery's avatar
Sylvain Thery committed
17 18 19
##
##
## Variables this file provide : 
20 21 22 23 24
##   * SUITESPARSE_FOUND         			True if SuiteSparse given COMPONENTS include and libraries were found
##   * SUITESPARSE_INCLUDE_DIRS  			Paths containing SuiteSparse needed headers (depend on which COMPONENTS you gave)
##   * SUITESPARSE_LIBRARIES     			Absolute paths of SuiteSparse libs found (depend on which COMPONENTS you gave)
##   If SUITESPARSE_USE_LAPACK_BLAS is set to ON : 
##   	* SUITESPARSE_LAPACK_BLAS_LIBRARIES 	Which contain the libblas and liblapack libraries
Sylvain Thery's avatar
Sylvain Thery committed
25
##   	On windows:
26
##   		* SUITESPARSE_LAPACK_BLAS_DLL		Which contain all requiered binaries for use libblas and liblapack
Sylvain Thery's avatar
Sylvain Thery committed
27 28 29
##
##
## Detailed variables this file provide :
30 31 32 33
##   * SUITESPARSE_<UPPPER_CASE_COMPONENT>_FOUND		True if the given component to look for is found (INCLUDE DIR and LIBRARY)
##   * SUITESPARSE_<UPPPER_CASE_COMPONENT>_INCLUDE_DIR	The path directory where we can found all compenent header files
##   * SUITESPARSE_<UPPPER_CASE_COMPONENT>_LIBRARY		The file path to the component library
##   Note: If a component is not found, a SUITESPARSE_<UPPPER_CASE_COMPONENT>_DIR cache variable is set to allow user set the search directory.
Sylvain Thery's avatar
Sylvain Thery committed
34 35 36 37 38 39 40 41 42 43 44 45
##
##
## Possible componnents to find are (maybe some others can be available):
##   * AMD
##   * CAMD
##   * COLAMD
##   * CCOLAMD
##   * CHOLMOD	: this lib need all previous one. According to how it was build (a single static lib or a full dynamic one), you should looking for its dependencies.
##   * metis (opt): may not be found (depend if suitesparse was build with metis or not) => required by CHOLMOD (optional)
##
##
## How to use this file : 
46 47
##   (opt) set(SUITESPARSE_VERBOSE ON)
##   (opt) set(SUITESPARSE_USE_LAPACK_BLAS ON)
Sylvain Thery's avatar
Sylvain Thery committed
48 49 50 51 52
##   ( 1 ) find_package(SuiteSparse) ## metis is not search by default because it's not a part of suitesparse (suitesparse can be built without metis)
##   ( 2 ) find_package(SuiteSparse COMPONENTS metis CHOLMOD) 		## be careful, components are case sensitive
##   ( 3 ) find_package(SuiteSparse COMPONENTS metis suitesparse)	## valid on windows (linux have no suitesparse library)
##   ( 4 ) find_package(SuiteSparse COMPONENTS suitesparse)
## 
53 54 55
##    if(SUITESPARSE_FOUND)
##       include_directories(${SUITESPARSE_INCLUDE_DIRS})
##		 target_link_library(<myProject> ${SUITESPARSE_LIBRARIES})
Sylvain Thery's avatar
Sylvain Thery committed
56 57 58 59 60 61 62
##	  endif()
##
## Created by jesnault (jerome.esnault@inria.fr) 2014-01-15
## Updated by jesnault (jerome.esnault@inria.fr) 2014-01-21


## check if global root SuiteSparse folder is set or not and cache it in order to let user fill it
63 64
if(NOT SUITESPARSE_DIR)
    set(SUITESPARSE_DIR "$ENV{SUITESPARSE_DIR}" CACHE PATH "SuiteSparse root directory")
Sylvain Thery's avatar
Sylvain Thery committed
65
endif()
66 67
if(SUITESPARSE_DIR)
	file(TO_CMAKE_PATH ${SUITESPARSE_DIR} SUITESPARSE_DIR)
Sylvain Thery's avatar
Sylvain Thery committed
68 69 70
endif()

## set default verbosity
71 72 73
## Process the CMake automatically-generated var: SUITESPARSE_FIND_QUIETLY: supersedes *_VERBOSE.
if(NOT SUITESPARSE_VERBOSE OR SUITESPARSE_FIND_QUIETLY)
	set(SUITESPARSE_VERBOSE OFF)
Sylvain Thery's avatar
Sylvain Thery committed
74 75
endif()

Sylvain Thery's avatar
Sylvain Thery committed
76
MESSAGE (STATUS "Looking for SuiteSparse ..")
Sylvain Thery's avatar
Sylvain Thery committed
77 78 79

## set the LIB POSTFIX to find in a right directory according to what kind of compiler we use (32/64bits)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)  # Size in bytes!
80
	set(SUITESPARSE_SEARCH_LIB_POSTFIX "64" CACHE STRING "suffix for 32/64 dir placement")
Sylvain Thery's avatar
Sylvain Thery committed
81
else()  # Size in bytes!
82
	set(SUITESPARSE_SEARCH_LIB_POSTFIX "" CACHE STRING "suffix for 32/64 dir placement")
Sylvain Thery's avatar
Sylvain Thery committed
83
endif()
84 85 86 87
if(SUITESPARSE_SEARCH_LIB_POSTFIX)
	mark_as_advanced(SUITESPARSE_SEARCH_LIB_POSTFIX)
	if(SUITESPARSE_VERBOSE)
		message(STATUS "   find_library will search inside lib${SUITESPARSE_SEARCH_LIB_POSTFIX} directory (can be changed with SUITESPARSE_SEARCH_LIB_POSTFIX)")
Sylvain Thery's avatar
Sylvain Thery committed
88 89 90 91 92 93 94
	endif()
endif()


## This utility macro is used to find all suitesparse projects by giving its name
## Since the name structure is the same for lib name and include dir name,
## we can use a generic way to find all of these with simple cmake lines of code
95
macro(SUITESPARSE_FIND_COMPONENTS )
Sylvain Thery's avatar
Sylvain Thery committed
96

97
	## On windows : we absolutly need SUITESPARSE_config.h every time for all projects
Sylvain Thery's avatar
Sylvain Thery committed
98
	if(WIN32)
99
		list(FIND SUITESPARSE_FIND_COMPONENTS "suitesparseconfig" SS_config_index)
Sylvain Thery's avatar
Sylvain Thery committed
100
		if(${SS_config_index} MATCHES "-1")
101 102 103
			list(APPEND SUITESPARSE_FIND_COMPONENTS suitesparseconfig)
			if(SUITESPARSE_VERBOSE)
				message(STATUS "   On windows, we absolutly need SUITESPARSE_config.h every time for all projects : add suitesparseconfig component to look for")
Sylvain Thery's avatar
Sylvain Thery committed
104 105 106 107 108
			endif()
		endif()
	endif()

	## special check for suitesparse component (allow to find on windows but not on linux because doesn't exist)
109
	list(FIND SUITESPARSE_FIND_COMPONENTS "suitesparse" ss_index)
Sylvain Thery's avatar
Sylvain Thery committed
110 111 112 113 114 115
	if(${ss_index} MATCHES "-1")
		## do nothing, the user didn't provide the suisparse componnent
	else()
		if(WIN32)
			## do nothing, the user provide the suisparse componnent we will try to find
		else()
116 117
			list(REMOVE_AT SUITESPARSE_FIND_COMPONENTS ${ss_index})
			if(SUITESPARSE_VERBOSE)
Sylvain Thery's avatar
Sylvain Thery committed
118 119 120 121 122 123 124 125
				message(STATUS "   On this plateform : suitesparse lib doesn't exist (only on windows), so skip this component")
			endif()
		endif()
	endif()
		
	## Look for each component the same way :
	##  * For include dir the reference file is the <component>.h
	##	* for library fileName the reference is the <component> itself (cmake will prepend/append necessary prefix/suffix according to the plateform)
126
	foreach(suitesparseComp ${SUITESPARSE_FIND_COMPONENTS})
Sylvain Thery's avatar
Sylvain Thery committed
127 128 129 130 131 132 133 134 135 136 137 138

		## used to construct specific cmake variables (in upper case) according to the component, but also used for find_*()
		string(TOUPPER ${suitesparseComp} suitesparseCompUC)
		string(TOLOWER ${suitesparseComp} suitesparseCompLC)

		## Special case: CXSparse library is named "libcxsparse.*" but headers are "cs.h":
		SET(suitesparseComp_ALT "${suitesparseComp}") # Alternative names
		if("${suitesparseComp}" STREQUAL "CXSPARSE")
			SET(suitesparseComp_ALT "cs") # Alternative name of CXSparse
		endif()

		## try to find include dir (looking for very important header file)
139
		find_path(SUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR	
Sylvain Thery's avatar
Sylvain Thery committed
140 141 142 143 144 145 146 147 148
			NAMES 			${suitesparseComp}.h ${suitesparseCompLC}.h ${suitesparseCompUC}.h ${suitesparseComp_ALT}.h
						${suitesparseComp}.hpp ${suitesparseCompLC}.hpp ${suitesparseCompUC}.hpp
			PATHS			/opt/local/include
						/usr/include
						/usr/local/include
						/usr/include/suitesparse
						/usr/local/include/suitesparse
						/usr/include/${suitesparseComp}
						/usr/local/include/${suitesparseComp}
149 150 151 152 153
						${SUITESPARSE_DIR}/include
						${SUITESPARSE_DIR}/include/suitesparse
						${SUITESPARSE_DIR}/suitesparse/include
						${SUITESPARSE_DIR}/include/${suitesparseComp}
						${SUITESPARSE_DIR}/${suitesparseComp}/include
Sylvain Thery's avatar
Sylvain Thery committed
154 155 156 157 158
						${${suitesparseCompUC}_DIR}/include
						${${suitesparseCompUC}_DIR}/${suitesparseComp}/include
						${${suitesparseCompUC}_DIR}
		)
		## check if found
159 160 161
		if(NOT SUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR)
			if (SUITESPARSE_VERBOSE)
				message(WARNING "   Failed to find ${suitesparseComp} :\nSUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR not found.\nCheck you write correctly the component name (case sensitive),\nor set the SUITESPARSE_${suitesparseCompUC}_DIR to look inside")
Sylvain Thery's avatar
Sylvain Thery committed
162 163
			endif()
		else()
164
			list(APPEND SUITESPARSE_INCLUDE_DIRS	${SUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR})
Sylvain Thery's avatar
Sylvain Thery committed
165 166 167
		endif()

		## try to find filepath lib name (looking for very important lib file)
168
		find_library(SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE 
Sylvain Thery's avatar
Sylvain Thery committed
169 170
			NAMES 			lib${suitesparseComp} 	lib${suitesparseCompLC} lib${suitesparseCompUC}
							${suitesparseComp} 		${suitesparseCompLC} 	${suitesparseCompUC}
171 172 173 174 175
			PATHS 			/opt/local/lib${SUITESPARSE_SEARCH_LIB_POSTFIX} 		
							/usr/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
							/usr/local/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
							${SUITESPARSE_DIR}/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
							${${suitesparseCompUC}_DIR}/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
Sylvain Thery's avatar
Sylvain Thery committed
176 177 178 179
							${${suitesparseCompUC}_DIR}
			PATH_SUFFIXES	Release
		)
		
180
		## check and append the and SUITESPARSE_LIBRARIES list, and warn if not found (release and debug) otherwise
Sylvain Thery's avatar
Sylvain Thery committed
181
		if(NOT SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE )
182
			if (SUITESPARSE_VERBOSE)
Sylvain Thery's avatar
Sylvain Thery committed
183 184
			message(WARNING "   Failed to find ${suitesparseComp} :
			Check you write correctly the component name (case sensitive),
185
			or set the SUITESPARSE_${suitesparseCompUC}_DIR to look inside,
Sylvain Thery's avatar
Sylvain Thery committed
186
			or set directly SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE
Sylvain Thery's avatar
Sylvain Thery committed
187 188 189
			")
			endif ()
		else()
Sylvain Thery's avatar
Sylvain Thery committed
190
			list(APPEND SUITESPARSE_LIBRARIES	"${SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE}" )
Sylvain Thery's avatar
Sylvain Thery committed
191 192 193
		endif()
		
		## here we allow to find at least the include OR the lib dir and just warn if one of both missing
194 195
		if(NOT SUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR AND NOT SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE)
			set(SUITESPARSE_${suitesparseCompUC}_FOUND OFF)
Sylvain Thery's avatar
Sylvain Thery committed
196
		else()
197
			set(SUITESPARSE_${suitesparseCompUC}_FOUND ON)
Sylvain Thery's avatar
Sylvain Thery committed
198 199 200
		endif()
		
		## if one of both (include dir or filepath lib), then we provide a new cmake cache variable for the search. Otherwise we don't need anymore to expose all intermediates variables
201 202
		if(NOT SUITESPARSE_${suitesparseCompUC}_FOUND)
			set(SUITESPARSE_${suitesparseCompUC}_DIR "$ENV{SUITESPARSE_${suitesparseCompUC}_DIR}" CACHE PATH "${suitesparseComp} root directory")
Sylvain Thery's avatar
Sylvain Thery committed
203
		else()
204 205 206 207
			mark_as_advanced(SUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR)
			mark_as_advanced(SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE)
			if(DEFINED SUITESPARSE_${suitesparseCompUC}_DIR)
				mark_as_advanced(SUITESPARSE_${suitesparseCompUC}_DIR)
Sylvain Thery's avatar
Sylvain Thery committed
208 209 210
			endif()
		endif()

211 212 213 214
		if(SUITESPARSE_VERBOSE)
			message(STATUS "   SUITESPARSE_${suitesparseCompUC}_FOUND = ${SUITESPARSE_${suitesparseCompUC}_FOUND} : ")
			message(STATUS "      * SUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR = ${SUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR}")
			message(STATUS "      * SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE = ${SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE}")
Sylvain Thery's avatar
Sylvain Thery committed
215 216
		endif()
		
217
		list(APPEND SUITESPARSE_FOUND_LIST SUITESPARSE_${suitesparseCompUC}_FOUND)
Sylvain Thery's avatar
Sylvain Thery committed
218 219 220
		
		## special definition needed for metis
		if(${suitesparseComp} MATCHES "metis")
221 222 223 224
			set(SUITESPARSE_${suitesparseCompUC}_DEFINITIONS "-DNPARTITION")
			add_definitions(${SUITESPARSE_${suitesparseCompUC}_DEFINITIONS})
			if(SUITESPARSE_VERBOSE)
				message(STATUS "      * SUITESPARSE_${suitesparseCompUC}_DEFINITIONS = ${SUITESPARSE_${suitesparseCompUC}_DEFINITIONS}")
Sylvain Thery's avatar
Sylvain Thery committed
225 226 227 228 229 230
			endif()
		endif()
		
	endforeach()
	
	
231 232 233 234
	## set the final SUITESPARSE_FOUND based on all previous components found (status)
	foreach(componentToCheck ${SUITESPARSE_FOUND_LIST})
		set(SUITESPARSE_FOUND ON)
		if(SUITESPARSE_VERBOSE)
Sylvain Thery's avatar
Sylvain Thery committed
235 236 237
		MESSAGE(STATUS "final check: ${componentToCheck}")
		endif()
		if(NOT ${componentToCheck})
238
			set(SUITESPARSE_FOUND OFF)
Sylvain Thery's avatar
Sylvain Thery committed
239 240 241 242 243 244
			break() ## one component not found is enought to failed
		endif()
	endforeach()
endmacro()

## Default behavior if user don't use the COMPONENTS flag in find_package(SuiteSparse ...) command
245 246
if(NOT SUITESPARSE_FIND_COMPONENTS)
	list(APPEND SUITESPARSE_FIND_COMPONENTS AMD CAMD CCOLAMD COLAMD CHOLMOD SPQR LDL BTF KLU CXSPARSE UMFPACK)  ## suitesparse and metis are not searched by default (special case)
Sylvain Thery's avatar
Sylvain Thery committed
247 248
endif()

249
SUITESPARSE_FIND_COMPONENTS()
Sylvain Thery's avatar
Sylvain Thery committed
250 251

## check if we have to find also blas and lapack lib for SuiteSparse
252
if(SUITESPARSE_USE_LAPACK_BLAS)
Sylvain Thery's avatar
Sylvain Thery committed
253 254 255

	## set additional search dirs
	set(ADDITIONAL_SEARCH_DIRS 
256 257 258 259 260 261 262 263 264 265
		${SUITESPARSE_DIR}/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
		${SUITESPARSE_DIR}/lapack_windows/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
		${SUITESPARSE_DIR}/lapack_windows/x${SUITESPARSE_SEARCH_LIB_POSTFIX}
		${SUITESPARSE_DIR}/blas_windows/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
		${SUITESPARSE_DIR}/blas_windows/x${SUITESPARSE_SEARCH_LIB_POSTFIX}
		${SUITESPARSE_DIR}/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}/lapack_windows
		${SUITESPARSE_DIR}/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}/blas_windows
		${SUITESPARSE_DIR}/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}/lapack_blas_windows
		${SUITESPARSE_DIR}/lapack_blas_windows
		${SUITESPARSE_DIR}/lapack_blas_windows/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
Sylvain Thery's avatar
Sylvain Thery committed
266 267 268
	)

	## try to find blas lib
269
	find_library(SUITESPARSE_BLAS_LIBRARY 
Sylvain Thery's avatar
Sylvain Thery committed
270
		NAMES 			blas cblas libblas
271 272 273 274 275
		PATHS 			/opt/local/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}		
						/usr/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
						/usr/local/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
						${SUITESPARSE_BLAS_DIR}/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
						${SUITESPARSE_BLAS_DIR}
Sylvain Thery's avatar
Sylvain Thery committed
276 277 278
						${ADDITIONAL_SEARCH_DIRS}
		PATH_SUFFIXES	Release Debug
	)
279 280
	if(NOT SUITESPARSE_BLAS_LIBRARY)
		if (SUITESPARSE_VERBOSE)
Sylvain Thery's avatar
Sylvain Thery committed
281
			# Send all msgs as "STATUS": We'll send an error at the bottom, only if "REQUIRED" is set.
282
			message(STATUS "   Failed to find SUITESPARSE_BLAS_LIBRARY.Set it manually or set the SUITESPARSE_BLAS_DIR to looking for it inside.")
Sylvain Thery's avatar
Sylvain Thery committed
283
		endif()
284
			set(SUITESPARSE_BLAS_DIR "$ENV{SUITESPARSE_BLAS_DIR}" CACHE PATH "blas root directory")
Sylvain Thery's avatar
Sylvain Thery committed
285
	else()
286 287
		if(DEFINED SUITESPARSE_BLAS_DIR)
			mark_as_advanced(SUITESPARSE_BLAS_DIR)
Sylvain Thery's avatar
Sylvain Thery committed
288
		endif()
289
		list(APPEND SUITESPARSE_LAPACK_BLAS_LIBRARIES ${SUITESPARSE_BLAS_LIBRARY})
Sylvain Thery's avatar
Sylvain Thery committed
290 291 292
	endif()
	
	## try to find lapack lib
293
	find_library(SUITESPARSE_LAPACK_LIBRARY 
Sylvain Thery's avatar
Sylvain Thery committed
294
		NAMES 			lapack liblapack
295 296 297 298 299
		PATHS 			/opt/local/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}		
						/usr/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
						/usr/local/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
						${SUITESPARSE_LAPACK_DIR}/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
						${SUITESPARSE_LAPACK_DIR}
Sylvain Thery's avatar
Sylvain Thery committed
300 301 302
						${ADDITIONAL_SEARCH_DIRS}
		PATH_SUFFIXES	Release Debug
	)
303 304
	if(NOT SUITESPARSE_LAPACK_LIBRARY)
		if (SUITESPARSE_VERBOSE)
Sylvain Thery's avatar
Sylvain Thery committed
305
			# Send all msgs as "STATUS": We'll send an error at the bottom, only if "REQUIRED" is set.
306
			message(STATUS "   Failed to find SUITESPARSE_LAPACK_LIBRARY.Set it manually or set the SUITESPARSE_LAPACK_DIR to looking for it inside.")
Sylvain Thery's avatar
Sylvain Thery committed
307
		endif()
308
		set(SUITESPARSE_LAPACK_DIR "$ENV{SUITESPARSE_LAPACK_DIR}" CACHE PATH "lapack root directory")
Sylvain Thery's avatar
Sylvain Thery committed
309
	else()
310 311
		if(DEFINED SUITESPARSE_LAPACK_DIR)
			mark_as_advanced(SUITESPARSE_LAPACK_DIR)
Sylvain Thery's avatar
Sylvain Thery committed
312
		endif()
313
		list(APPEND SUITESPARSE_LAPACK_BLAS_LIBRARIES ${SUITESPARSE_LAPACK_LIBRARY})
Sylvain Thery's avatar
Sylvain Thery committed
314 315
	endif()
		
Sylvain Thery's avatar
Sylvain Thery committed
316 317 318 319 320 321 322 323 324 325 326 327 328
	find_library(F2C_LIBRARY 
		NAMES 			f2c libf2c
		PATHS 			/opt/local/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}		
						/usr/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
						/usr/local/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
						${SUITESPARSE_DIR}
		PATH_SUFFIXES	Release Debug
	)	
	
	if (F2C_LIBRARY)
		list(APPEND SUITESPARSE_LAPACK_BLAS_LIBRARIES ${F2C_LIBRARY})
	endif()
	
329 330 331 332 333 334 335
	## well, now append to the SUITESPARSE_LIBRARIES and print infos if VERBOSE
	if(SUITESPARSE_LAPACK_BLAS_LIBRARIES)
		list(APPEND SUITESPARSE_LIBRARIES	${SUITESPARSE_LAPACK_BLAS_LIBRARIES})
		if(SUITESPARSE_VERBOSE)
			message(STATUS "   SUITESPARSE_USE_LAPACK_BLAS = ${SUITESPARSE_USE_LAPACK_BLAS} : ")
			message(STATUS "      * SUITESPARSE_LAPACK_BLAS_LIBRARIES : ")
			foreach(lib ${SUITESPARSE_LAPACK_BLAS_LIBRARIES})
Sylvain Thery's avatar
Sylvain Thery committed
336 337 338 339 340 341 342
				message(STATUS "         ${lib}")
			endforeach()
		endif()
	endif()
	
	## Now looking for *.dll => note that this is not a safe way to get it...
	if(WIN32)
343 344 345
		if(${SUITESPARSE_SEARCH_LIB_POSTFIX} MATCHES "64")
			set(SUITESPARSE_SEARCH_BIN_POSTFIX_1 "x64")
			set(SUITESPARSE_SEARCH_BIN_POSTFIX_2 "Win64")
Sylvain Thery's avatar
Sylvain Thery committed
346
		else()
347 348
			set(SUITESPARSE_SEARCH_BIN_POSTFIX_1 "x86")
			set(SUITESPARSE_SEARCH_BIN_POSTFIX_2 "Win32")
Sylvain Thery's avatar
Sylvain Thery committed
349 350
		endif()
		
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
		set(SUITESPARSE_DLL_SEARCH_DIRS
			${SUITESPARSE_LAPACK_DIR}/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
			${SUITESPARSE_LAPACK_DIR}
			${SUITESPARSE_LAPACK_DIR}/bin
			${SUITESPARSE_LAPACK_DIR}/bin/${SUITESPARSE_SEARCH_BIN_POSTFIX_1}
			${SUITESPARSE_LAPACK_DIR}/bin/${SUITESPARSE_SEARCH_BIN_POSTFIX_2}
			${SUITESPARSE_LAPACK_DIR}/bin/Release/${SUITESPARSE_SEARCH_BIN_POSTFIX_1}
			${SUITESPARSE_LAPACK_DIR}/bin/Debug/${SUITESPARSE_SEARCH_BIN_POSTFIX_2}
			${SUITESPARSE_LAPACK_DIR}/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
			${SUITESPARSE_BLAS_DIR}
			${SUITESPARSE_BLAS_DIR}/bin
			${SUITESPARSE_BLAS_DIR}/bin/${SUITESPARSE_SEARCH_BIN_POSTFIX_1}
			${SUITESPARSE_BLAS_DIR}/bin/${SUITESPARSE_SEARCH_BIN_POSTFIX_2}
			${SUITESPARSE_BLAS_DIR}/bin/Release/${SUITESPARSE_SEARCH_BIN_POSTFIX_1}
			${SUITESPARSE_BLAS_DIR}/bin/Debug/${SUITESPARSE_SEARCH_BIN_POSTFIX_2}
Sylvain Thery's avatar
Sylvain Thery committed
366 367 368 369 370 371
			${ADDITIONAL_SEARCH_DIRS}
			"$ENV{Path}"
		)
		set(dllPatternFileList "libblas" "liblapack" "libgcc_s_" "libgfortran" "libquadmath")
		foreach(dllPattern ${dllPatternFileList})
			string(TOUPPER ${dllPattern} dllPatternUC)
372 373 374
			foreach(searchDir ${SUITESPARSE_DLL_SEARCH_DIRS})
				file(GLOB SUITESPARSE_DLL_${dllPatternUC} "${searchDir}/${dllPattern}*.dll") ## append the *.dll
				list(LENGTH SUITESPARSE_DLL_${dllPatternUC} resultCount)
Sylvain Thery's avatar
Sylvain Thery committed
375
				if(${resultCount} GREATER "0" )
376
					list(APPEND SUITESPARSE_LAPACK_BLAS_DLL ${SUITESPARSE_DLL_${dllPatternUC}})
Sylvain Thery's avatar
Sylvain Thery committed
377 378 379 380 381
					break()
				endif()
			endforeach()
		endforeach()
		
382 383 384
		if(SUITESPARSE_VERBOSE)
			message(STATUS "      * SUITESPARSE_LAPACK_BLAS_DLL : ")
			foreach(dll ${SUITESPARSE_LAPACK_BLAS_DLL})
Sylvain Thery's avatar
Sylvain Thery committed
385 386 387 388 389 390 391 392
				message(STATUS "         ${dll}")
			endforeach()
		endif()
		
	endif()
	
endif()

393 394 395 396 397 398 399 400 401 402 403 404
find_library(SSPARSE_CONFIG_LIB 
		NAMES 			libsuitesparseconfig suitesparseconfig
		PATHS 			/opt/local/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
						/usr/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
						/usr/local/lib${SUITESPARSE_SEARCH_LIB_POSTFIX}
						${SUITESPARSE_DIR}
		PATH_SUFFIXES	Release Debug)	

if (SSPARSE_CONFIG_LIB)
	list(APPEND SUITESPARSE_LIBRARIES ${SSPARSE_CONFIG_LIB})
endif()

405 406
if(SUITESPARSE_INCLUDE_DIRS)
	list(REMOVE_DUPLICATES SUITESPARSE_INCLUDE_DIRS)
Sylvain Thery's avatar
Sylvain Thery committed
407
endif()
408 409
if(SUITESPARSE_LIBRARIES)
	list(REMOVE_DUPLICATES SUITESPARSE_LIBRARIES)
Sylvain Thery's avatar
Sylvain Thery committed
410 411
endif()

412 413
if(SUITESPARSE_LAPACK_BLAS_LIBRARIES)
	list(REMOVE_DUPLICATES SUITESPARSE_LAPACK_BLAS_LIBRARIES)
Sylvain Thery's avatar
Sylvain Thery committed
414 415
endif()

416 417
if(SUITESPARSE_LAPACK_BLAS_DLL)
	list(REMOVE_DUPLICATES SUITESPARSE_LAPACK_BLAS_DLL)
Sylvain Thery's avatar
Sylvain Thery committed
418 419
endif()

420 421
if(SUITESPARSE_VERBOSE)
	message(STATUS "Finish to FindSuiteSparse.cmake => SUITESPARSE_FOUND=${SUITESPARSE_FOUND}")
Sylvain Thery's avatar
Sylvain Thery committed
422 423 424
endif()

## Show error if not found and _REQUIRED
425
IF(NOT SUITESPARSE_FOUND)
Sylvain Thery's avatar
Sylvain Thery committed
426
  # make FIND_PACKAGE friendly
427 428
  IF(NOT SUITESPARSE_FIND_QUIETLY)
    IF(SUITESPARSE_FIND_REQUIRED)
Sylvain Thery's avatar
Sylvain Thery committed
429 430 431 432 433 434
      MESSAGE(FATAL_ERROR
        "SuiteSparse required but some headers or libs not found.")
    ELSE()
      MESSAGE(STATUS "ERROR: SuiteSparse was not found.")
    ENDIF()
  ENDIF()
Sylvain Thery's avatar
Sylvain Thery committed
435 436
ELSE()
	message (STATUS ".. SuiteSparse Found")
Sylvain Thery's avatar
Sylvain Thery committed
437
ENDIF()