FindSuiteSparse.cmake 20 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()

76
if(SUITESPARSE_VERBOSE)
Sylvain Thery's avatar
Sylvain Thery committed
77 78 79 80 81 82
	message(STATUS "Start to FindSuiteSparse.cmake :")
endif()


## 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!
83
	set(SUITESPARSE_SEARCH_LIB_POSTFIX "64" CACHE STRING "suffix for 32/64 dir placement")
Sylvain Thery's avatar
Sylvain Thery committed
84
else()  # Size in bytes!
85
	set(SUITESPARSE_SEARCH_LIB_POSTFIX "" CACHE STRING "suffix for 32/64 dir placement")
Sylvain Thery's avatar
Sylvain Thery committed
86
endif()
87 88 89 90
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
91 92 93 94 95 96 97
	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
98
macro(SUITESPARSE_FIND_COMPONENTS )
Sylvain Thery's avatar
Sylvain Thery committed
99

100
	## On windows : we absolutly need SUITESPARSE_config.h every time for all projects
Sylvain Thery's avatar
Sylvain Thery committed
101
	if(WIN32)
102
		list(FIND SUITESPARSE_FIND_COMPONENTS "suitesparseconfig" SS_config_index)
Sylvain Thery's avatar
Sylvain Thery committed
103
		if(${SS_config_index} MATCHES "-1")
104 105 106
			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
107 108 109 110 111
			endif()
		endif()
	endif()

	## special check for suitesparse component (allow to find on windows but not on linux because doesn't exist)
112
	list(FIND SUITESPARSE_FIND_COMPONENTS "suitesparse" ss_index)
Sylvain Thery's avatar
Sylvain Thery committed
113 114 115 116 117 118
	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()
119 120
			list(REMOVE_AT SUITESPARSE_FIND_COMPONENTS ${ss_index})
			if(SUITESPARSE_VERBOSE)
Sylvain Thery's avatar
Sylvain Thery committed
121 122 123 124 125 126 127 128
				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)
129
	foreach(suitesparseComp ${SUITESPARSE_FIND_COMPONENTS})
Sylvain Thery's avatar
Sylvain Thery committed
130 131 132 133 134 135 136 137 138 139 140 141

		## 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)
142
		find_path(SUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR	
Sylvain Thery's avatar
Sylvain Thery committed
143 144 145 146 147 148 149 150 151
			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}
152 153 154 155 156
						${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
157 158 159 160 161
						${${suitesparseCompUC}_DIR}/include
						${${suitesparseCompUC}_DIR}/${suitesparseComp}/include
						${${suitesparseCompUC}_DIR}
		)
		## check if found
162 163 164
		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
165 166
			endif()
		else()
167
			list(APPEND SUITESPARSE_INCLUDE_DIRS	${SUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR})
Sylvain Thery's avatar
Sylvain Thery committed
168 169 170
		endif()

		## try to find filepath lib name (looking for very important lib file)
171
		find_library(SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE 
Sylvain Thery's avatar
Sylvain Thery committed
172 173
			NAMES 			lib${suitesparseComp} 	lib${suitesparseCompLC} lib${suitesparseCompUC}
							${suitesparseComp} 		${suitesparseCompLC} 	${suitesparseCompUC}
174 175 176 177 178
			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
179 180 181
							${${suitesparseCompUC}_DIR}
			PATH_SUFFIXES	Release
		)
182
		find_library(SUITESPARSE_${suitesparseCompUC}_LIBRARY_DEBUG 
Sylvain Thery's avatar
Sylvain Thery committed
183 184
			NAMES 			${suitesparseComp}d		${suitesparseCompLC}d 		${suitesparseCompUC}d
							lib${suitesparseComp}d 	lib${suitesparseCompLC}d 	lib${suitesparseCompUC}d
185 186 187 188 189
			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
190 191 192 193 194
							${${suitesparseCompUC}_DIR}
			PATH_SUFFIXES	Debug
		)
		
		## check and auto complete release with debug if release missing and vice versa
195 196 197
		if(SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE)
			if(NOT SUITESPARSE_${suitesparseCompUC}_LIBRARY_DEBUG)
				set(SUITESPARSE_${suitesparseCompUC}_LIBRARY_DEBUG ${SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE} CACHE PATH "Path to a library." FORCE)
Sylvain Thery's avatar
Sylvain Thery committed
198 199
			endif()
		endif()
200 201 202
		if(SUITESPARSE_${suitesparseCompUC}_LIBRARY_DEBUG)
			if(NOT SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE)
				set(SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE ${SUITESPARSE_${suitesparseCompUC}_LIBRARY_DEBUG} CACHE PATH "Path to a library." FORCE)
Sylvain Thery's avatar
Sylvain Thery committed
203 204 205
			endif()
		endif()
		
206 207 208
		## check and append the and SUITESPARSE_LIBRARIES list, and warn if not found (release and debug) otherwise
		if(NOT SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE AND NOT SUITESPARSE_${suitesparseCompUC}_LIBRARY_DEBUG)
			if (SUITESPARSE_VERBOSE)
Sylvain Thery's avatar
Sylvain Thery committed
209 210
			message(WARNING "   Failed to find ${suitesparseComp} :
			Check you write correctly the component name (case sensitive),
211 212
			or set the SUITESPARSE_${suitesparseCompUC}_DIR to look inside,
			or set directly SUITESPARSE_${suitesparseCompUC}_LIBRARY_DEBUG and SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE
Sylvain Thery's avatar
Sylvain Thery committed
213 214 215
			")
			endif ()
		else()
216
			list(APPEND SUITESPARSE_LIBRARIES	optimized "${SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE}" debug "${SUITESPARSE_${suitesparseCompUC}_LIBRARY_DEBUG}")
Sylvain Thery's avatar
Sylvain Thery committed
217 218 219
		endif()
		
		## here we allow to find at least the include OR the lib dir and just warn if one of both missing
220 221
		if(NOT SUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR AND NOT SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE)
			set(SUITESPARSE_${suitesparseCompUC}_FOUND OFF)
Sylvain Thery's avatar
Sylvain Thery committed
222
		else()
223
			set(SUITESPARSE_${suitesparseCompUC}_FOUND ON)
Sylvain Thery's avatar
Sylvain Thery committed
224 225 226
		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
227 228
		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
229
		else()
230 231 232 233 234
			mark_as_advanced(SUITESPARSE_${suitesparseCompUC}_INCLUDE_DIR)
			mark_as_advanced(SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE)
			mark_as_advanced(SUITESPARSE_${suitesparseCompUC}_LIBRARY_DEBUG)
			if(DEFINED SUITESPARSE_${suitesparseCompUC}_DIR)
				mark_as_advanced(SUITESPARSE_${suitesparseCompUC}_DIR)
Sylvain Thery's avatar
Sylvain Thery committed
235 236 237
			endif()
		endif()

238 239 240 241 242
		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_DEBUG = ${SUITESPARSE_${suitesparseCompUC}_LIBRARY_DEBUG}")
			message(STATUS "      * SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE = ${SUITESPARSE_${suitesparseCompUC}_LIBRARY_RELEASE}")
Sylvain Thery's avatar
Sylvain Thery committed
243 244
		endif()
		
245
		list(APPEND SUITESPARSE_FOUND_LIST SUITESPARSE_${suitesparseCompUC}_FOUND)
Sylvain Thery's avatar
Sylvain Thery committed
246 247 248
		
		## special definition needed for metis
		if(${suitesparseComp} MATCHES "metis")
249 250 251 252
			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
253 254 255 256 257 258
			endif()
		endif()
		
	endforeach()
	
	
259 260 261 262
	## 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
263 264 265
		MESSAGE(STATUS "final check: ${componentToCheck}")
		endif()
		if(NOT ${componentToCheck})
266
			set(SUITESPARSE_FOUND OFF)
Sylvain Thery's avatar
Sylvain Thery committed
267 268 269 270 271 272
			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
273 274
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
275 276
endif()

277
SUITESPARSE_FIND_COMPONENTS()
Sylvain Thery's avatar
Sylvain Thery committed
278 279

## check if we have to find also blas and lapack lib for SuiteSparse
280
if(SUITESPARSE_USE_LAPACK_BLAS)
Sylvain Thery's avatar
Sylvain Thery committed
281 282 283

	## set additional search dirs
	set(ADDITIONAL_SEARCH_DIRS 
284 285 286 287 288 289 290 291 292 293
		${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
294 295 296
	)

	## try to find blas lib
297
	find_library(SUITESPARSE_BLAS_LIBRARY 
Sylvain Thery's avatar
Sylvain Thery committed
298
		NAMES 			blas cblas libblas
299 300 301 302 303
		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
304 305 306
						${ADDITIONAL_SEARCH_DIRS}
		PATH_SUFFIXES	Release Debug
	)
307 308
	if(NOT SUITESPARSE_BLAS_LIBRARY)
		if (SUITESPARSE_VERBOSE)
Sylvain Thery's avatar
Sylvain Thery committed
309
			# Send all msgs as "STATUS": We'll send an error at the bottom, only if "REQUIRED" is set.
310
			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
311
		endif()
312
			set(SUITESPARSE_BLAS_DIR "$ENV{SUITESPARSE_BLAS_DIR}" CACHE PATH "blas root directory")
Sylvain Thery's avatar
Sylvain Thery committed
313
	else()
314 315
		if(DEFINED SUITESPARSE_BLAS_DIR)
			mark_as_advanced(SUITESPARSE_BLAS_DIR)
Sylvain Thery's avatar
Sylvain Thery committed
316
		endif()
317
		list(APPEND SUITESPARSE_LAPACK_BLAS_LIBRARIES ${SUITESPARSE_BLAS_LIBRARY})
Sylvain Thery's avatar
Sylvain Thery committed
318 319 320
	endif()
	
	## try to find lapack lib
321
	find_library(SUITESPARSE_LAPACK_LIBRARY 
Sylvain Thery's avatar
Sylvain Thery committed
322
		NAMES 			lapack liblapack
323 324 325 326 327
		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
328 329 330
						${ADDITIONAL_SEARCH_DIRS}
		PATH_SUFFIXES	Release Debug
	)
331 332
	if(NOT SUITESPARSE_LAPACK_LIBRARY)
		if (SUITESPARSE_VERBOSE)
Sylvain Thery's avatar
Sylvain Thery committed
333
			# Send all msgs as "STATUS": We'll send an error at the bottom, only if "REQUIRED" is set.
334
			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
335
		endif()
336
		set(SUITESPARSE_LAPACK_DIR "$ENV{SUITESPARSE_LAPACK_DIR}" CACHE PATH "lapack root directory")
Sylvain Thery's avatar
Sylvain Thery committed
337
	else()
338 339
		if(DEFINED SUITESPARSE_LAPACK_DIR)
			mark_as_advanced(SUITESPARSE_LAPACK_DIR)
Sylvain Thery's avatar
Sylvain Thery committed
340
		endif()
341
		list(APPEND SUITESPARSE_LAPACK_BLAS_LIBRARIES ${SUITESPARSE_LAPACK_LIBRARY})
Sylvain Thery's avatar
Sylvain Thery committed
342 343
	endif()
		
344 345 346 347 348 349 350
	## 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
351 352 353 354 355 356 357
				message(STATUS "         ${lib}")
			endforeach()
		endif()
	endif()
	
	## Now looking for *.dll => note that this is not a safe way to get it...
	if(WIN32)
358 359 360
		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
361
		else()
362 363
			set(SUITESPARSE_SEARCH_BIN_POSTFIX_1 "x86")
			set(SUITESPARSE_SEARCH_BIN_POSTFIX_2 "Win32")
Sylvain Thery's avatar
Sylvain Thery committed
364 365
		endif()
		
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
		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
381 382 383 384 385 386
			${ADDITIONAL_SEARCH_DIRS}
			"$ENV{Path}"
		)
		set(dllPatternFileList "libblas" "liblapack" "libgcc_s_" "libgfortran" "libquadmath")
		foreach(dllPattern ${dllPatternFileList})
			string(TOUPPER ${dllPattern} dllPatternUC)
387 388 389
			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
390
				if(${resultCount} GREATER "0" )
391
					list(APPEND SUITESPARSE_LAPACK_BLAS_DLL ${SUITESPARSE_DLL_${dllPatternUC}})
Sylvain Thery's avatar
Sylvain Thery committed
392 393 394 395 396
					break()
				endif()
			endforeach()
		endforeach()
		
397 398 399
		if(SUITESPARSE_VERBOSE)
			message(STATUS "      * SUITESPARSE_LAPACK_BLAS_DLL : ")
			foreach(dll ${SUITESPARSE_LAPACK_BLAS_DLL})
Sylvain Thery's avatar
Sylvain Thery committed
400 401 402 403 404 405 406 407
				message(STATUS "         ${dll}")
			endforeach()
		endif()
		
	endif()
	
endif()

408 409
if(SUITESPARSE_INCLUDE_DIRS)
	list(REMOVE_DUPLICATES SUITESPARSE_INCLUDE_DIRS)
Sylvain Thery's avatar
Sylvain Thery committed
410
endif()
411 412
if(SUITESPARSE_LIBRARIES)
	list(REMOVE_DUPLICATES SUITESPARSE_LIBRARIES)
Sylvain Thery's avatar
Sylvain Thery committed
413 414
endif()

415 416
if(SUITESPARSE_LAPACK_BLAS_LIBRARIES)
	list(REMOVE_DUPLICATES SUITESPARSE_LAPACK_BLAS_LIBRARIES)
Sylvain Thery's avatar
Sylvain Thery committed
417 418
endif()

419 420
if(SUITESPARSE_LAPACK_BLAS_DLL)
	list(REMOVE_DUPLICATES SUITESPARSE_LAPACK_BLAS_DLL)
Sylvain Thery's avatar
Sylvain Thery committed
421 422
endif()

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

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