-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
FindSuiteSparse.cmake
241 lines (218 loc) · 7.71 KB
/
FindSuiteSparse.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# This CMakeFile is adapted from that in dune-common:
# .. cmake_module::
#
# Find the SuiteSparse libraries like UMFPACK or SPQR.
#
# Example which tries to find Suite Sparse's UMFPack component:
#
# :code:`find_package(SuiteSparse OPTIONAL_COMPONENTS UMFPACK)`
#
# `OPTIONAL_COMPONENTS`
# A list of components. Components are:
# AMD, BTF, CAMD, CCOLAMD, CHOLMOD, COLAMD, CXSPARSE,
# KLU, LDL, RBIO, SPQR, UMFPACK
#
# :ref:`SuiteSparse_ROOT`
# Path list to search for SuiteSparse
#
# Sets the following variables:
#
# :code:`SuiteSparse_FOUND`
# True if SuiteSparse was found.
#
# :code:`SuiteSparse_INCLUDE_DIRS`
# Path to the SuiteSparse include dirs.
#
# :code:`SuiteSparse_LIBRARIES`
# Name of the SuiteSparse libraries.
#
# :code:`SuiteSparse_<COMPONENT>_FOUND`
# Whether <COMPONENT> was found as part of SuiteSparse.
#
# .. cmake_variable:: SuiteSparse_ROOT
#
# You may set this variable to have :ref:`FindSuiteSparse` look
# for SuiteSparse in the given path before inspecting
# system paths.
#
find_package(BLAS QUIET)
# look for desired componenents
set(SUITESPARSE_COMPONENTS ${SuiteSparse_FIND_COMPONENTS})
# resolve inter-component dependencies
list(FIND SUITESPARSE_COMPONENTS "UMFPACK" WILL_USE_UMFPACK)
if(NOT WILL_USE_UMFPACK EQUAL -1)
list(APPEND SUITESPARSE_COMPONENTS AMD CHOLMOD)
endif()
list(FIND SUITESPARSE_COMPONENTS "CHOLMOD" WILL_USE_CHOLMOD)
if(NOT WILL_USE_CHOLMOD EQUAL -1)
list(APPEND SUITESPARSE_COMPONENTS AMD CAMD COLAMD CCOLAMD)
endif()
if(SUITESPARSE_COMPONENTS)
list(REMOVE_DUPLICATES SUITESPARSE_COMPONENTS)
endif()
# find SuiteSparse config:
# look for library at positions given by the user
find_library(SUITESPARSE_CONFIG_LIB
NAMES "suitesparseconfig"
PATHS ${SuiteSparse_ROOT}
PATH_SUFFIXES "lib" "lib32" "lib64" "Lib"
NO_DEFAULT_PATH
)
# now also include the default paths
find_library(SUITESPARSE_CONFIG_LIB
NAMES "suitesparseconfig"
PATH_SUFFIXES "lib" "lib32" "lib64" "Lib"
)
#look for header files at positions given by the user
find_path(SUITESPARSE_INCLUDE_DIR
NAMES "SuiteSparse_config.h"
PATHS ${SuiteSparse_ROOT}
PATH_SUFFIXES "SuiteSparse_config" "SuiteSparse_config/include" "suitesparse" "include" "src" "SuiteSparse_config/Include"
NO_DEFAULT_PATH
)
#now also look for default paths
find_path(SUITESPARSE_INCLUDE_DIR
NAMES "SuiteSparse_config.h"
PATH_SUFFIXES "SuiteSparse_config" "SuiteSparse_config/include" "suitesparse" "include" "src" "SuiteSparse_config/Include"
)
foreach(_component ${SUITESPARSE_COMPONENTS})
string(TOLOWER ${_component} _componentLower)
#look for library at positions given by the user
find_library(${_component}_LIBRARY
NAMES "${_componentLower}"
PATHS ${SuiteSparse_ROOT}
PATH_SUFFIXES "lib" "lib32" "lib64" "${_component}" "${_component}/Lib"
NO_DEFAULT_PATH
)
#now also include the default paths
find_library(${_component}_LIBRARY
NAMES "${_componentLower}"
PATH_SUFFIXES "lib" "lib32" "lib64" "${_component}" "${_component}/Lib"
)
#look for header files at positions given by the user
find_path(${_component}_INCLUDE_DIR
NAMES "${_componentLower}.h"
PATHS ${SuiteSparse_ROOT}
PATH_SUFFIXES "${_componentLower}" "include/${_componentLower}" "suitesparse" "include" "src" "${_component}" "${_component}/Include"
NO_DEFAULT_PATH
)
#now also look for default paths
find_path(${_component}_INCLUDE_DIR
NAMES "${_componentLower}.h"
PATH_SUFFIXES "${_componentLower}" "include/${_componentLower}" "suitesparse" "include" "${_component}" "${_component}/Include"
)
endforeach()
# SPQR has different header file name SuiteSparseQR.hpp
#look for header files at positions given by the user
find_path(SPQR_INCLUDE_DIR
NAMES "SuiteSparseQR.hpp"
PATHS ${SuiteSparse_ROOT}
PATH_SUFFIXES "spqr" "include/spqr" "suitesparse" "include" "src" "SPQR" "SPQR/Include"
NO_DEFAULT_PATH
)
#now also look for default paths
find_path(SPQR_INCLUDE_DIR
NAMES "SuiteSparseQR.hpp"
PATH_SUFFIXES "spqr" "include/spqr" "suitesparse" "include" "SPQR" "SPQR/Include"
)
# resolve inter-modular dependencies
# CHOLMOD requires AMD, COLAMD; CAMD and CCOLAMD are optional
if(CHOLMOD_LIBRARY)
if(NOT (AMD_LIBRARY AND COLAMD_LIBRARY))
message(WARNING "CHOLMOD requires AMD and COLAMD which were not found, skipping the test.")
set(SuiteSparse_CHOLMOD_FOUND "CHOLMOD requires AMD and COLAMD-NOTFOUND")
endif()
list(APPEND CHOLMOD_LIBRARY ${AMD_LIBRARY} ${COLAMD_LIBRARY})
if(CAMD_LIBRARY)
list(APPEND CHOLMOD_LIBRARY ${CAMD_LIBRARY})
endif()
if(CCOLAMD_LIBRARY)
list(APPEND CHOLMOD_LIBRARY ${CCOLAMD_LIBRARY})
endif()
list(REVERSE CHOLMOD_LIBRARY)
# remove duplicates
list(REMOVE_DUPLICATES CHOLMOD_LIBRARY)
list(REVERSE CHOLMOD_LIBRARY)
endif()
# UMFPack requires AMD, can depend on CHOLMOD
if(UMFPACK_LIBRARY)
# check wether cholmod was found
if(CHOLMOD_LIBRARY)
list(APPEND UMFPACK_LIBRARY ${CHOLMOD_LIBRARY})
else()
list(APPEND UMFPACK_LIBRARY ${AMD_LIBRARY})
endif()
list(REVERSE UMFPACK_LIBRARY)
# remove duplicates
list(REMOVE_DUPLICATES UMFPACK_LIBRARY)
list(REVERSE UMFPACK_LIBRARY)
endif()
# check wether everything was found
foreach(_component ${SUITESPARSE_COMPONENTS})
# variable used for component handling
set(SuiteSparse_${_component}_FOUND (${_component}_LIBRARY AND ${_component}_INCLUDE_DIR))
set(HAVE_SUITESPARSE_${_component} SuiteSparse_${_component}_FOUND)
if(SuiteSparse_${_component}_FOUND)
list(APPEND SUITESPARSE_INCLUDE_DIR "${${_component}_INCLUDE_DIR}")
list(APPEND SUITESPARSE_LIBRARY "${${_component}_LIBRARY}")
endif()
mark_as_advanced(
HAVE_SUITESPARSE_${_component}
SuiteSparse_${_component}_FOUND
${_component}_INCLUDE_DIR
${_component}_LIBRARY)
endforeach()
list(APPEND SUITESPARSE_LIBRARY ${SUITESPARSE_CONFIG_LIB})
# make them unique
if(SUITESPARSE_INCLUDE_DIR)
list(REMOVE_DUPLICATES SUITESPARSE_INCLUDE_DIR)
endif()
if(SUITESPARSE_LIBRARY)
list(REVERSE SUITESPARSE_LIBRARY)
list(REMOVE_DUPLICATES SUITESPARSE_LIBRARY)
list(REVERSE SUITESPARSE_LIBRARY)
endif()
# behave like a CMake module is supposed to behave
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
"SuiteSparse"
FOUND_VAR SuiteSparse_FOUND
REQUIRED_VARS
BLAS_FOUND
SUITESPARSE_INCLUDE_DIR
SUITESPARSE_LIBRARY
HANDLE_COMPONENTS
)
mark_as_advanced(
SUITESPARSE_INCLUDE_DIR
SUITESPARSE_LIBRARY
SUITESPARSE_CONFIG_LIB
WILL_USE_CHOLMOD
WILL_USE_UMFPACK)
# if both headers and library are found, store results
if(SuiteSparse_FOUND)
set(SuiteSparse_LIBRARIES ${SUITESPARSE_LIBRARY})
set(SuiteSparse_INCLUDE_DIRS ${SUITESPARSE_INCLUDE_DIR})
# log result
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining location of SuiteSparse succeded:\n"
"Include directory: ${SuiteSparse_INCLUDE_DIRS}\n"
"Library directory: ${SuiteSparse_LIBRARIES}\n\n")
set(SuiteSparse_COMPILER_FLAGS)
foreach(dir ${SuiteSparse_INCLUDE_DIRS})
set(SuiteSparse_COMPILER_FLAGS "${SuiteSparse_COMPILER_FLAGS} -I${dir}/")
endforeach()
set(SuiteSparse_DUNE_COMPILE_FLAGS ${SuiteSparse_COMPILER_FLAGS}
CACHE STRING "Compile Flags used by DUNE when compiling with SuiteSparse programs")
set(SuiteSparse_DUNE_LIBRARIES ${BLAS_LIBRARIES} ${SuiteSparse_LIBRARIES}
CACHE STRING "Libraries used by DUNE when linking SuiteSparse programs")
else()
# log errornous result
file(APPEND ${CMAKE_BINARY_DIR}${CMAKES_FILES_DIRECTORY}/CMakeError.log
"Determing location of SuiteSparse failed:\n"
"Include directory: ${SuiteSparse_INCLUDE_DIRS}\n"
"Library directory: ${SuiteSparse_LIBRARIES}\n\n")
endif()
#set HAVE_SUITESPARSE for config.h
set(HAVE_SUITESPARSE ${SuiteSparse_FOUND})
set(HAVE_UMFPACK ${SuiteSparse_UMFPACK_FOUND})