Debian Codegraph @

debian/external_deps/fetk/cmake/FindSuiteSparse.cmake

raw
1 # Ceres Solver - A fast non-linear least squares minimizer
2 # Copyright 2015 Google Inc. All rights reserved.
3 # http://ceres-solver.org/
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 #
8 # * Redistributions of source code must retain the above copyright notice,
9 # this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright notice,
11 # this list of conditions and the following disclaimer in the documentation
12 # and/or other materials provided with the distribution.
13 # * Neither the name of Google Inc. nor the names of its contributors may be
14 # used to endorse or promote products derived from this software without
15 # specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
28 #
29 # Author: [email protected] (Alex Stewart)
30 #
31
32 # FindSuiteSparse.cmake - Find SuiteSparse libraries & dependencies.
33 #
34 # This module defines the following variables:
35 #
36 # SUITESPARSE_FOUND: TRUE iff SuiteSparse and all dependencies have been found.
37 # SUITESPARSE_INCLUDE_DIRS: Include directories for all SuiteSparse components.
38 # SUITESPARSE_LIBRARIES: Libraries for all SuiteSparse component libraries and
39 # dependencies.
40 # SUITESPARSE_VERSION: Extracted from UFconfig.h (<= v3) or
41 # SuiteSparse_config.h (>= v4).
42 # SUITESPARSE_MAIN_VERSION: Equal to 4 if SUITESPARSE_VERSION = 4.2.1
43 # SUITESPARSE_SUB_VERSION: Equal to 2 if SUITESPARSE_VERSION = 4.2.1
44 # SUITESPARSE_SUBSUB_VERSION: Equal to 1 if SUITESPARSE_VERSION = 4.2.1
45 #
46 # SUITESPARSE_IS_BROKEN_SHARED_LINKING_UBUNTU_SYSTEM_VERSION: TRUE iff running
47 # on Ubuntu, SUITESPARSE_VERSION is 3.4.0 and found SuiteSparse is a system
48 # install, in which case found version of SuiteSparse cannot be used to link
49 # a shared library due to a bug (static linking is unaffected).
50 #
51 # The following variables control the behaviour of this module:
52 #
53 # SUITESPARSE_INCLUDE_DIR_HINTS: List of additional directories in which to
54 # search for SuiteSparse includes,
55 # e.g: /timbuktu/include.
56 # SUITESPARSE_LIBRARY_DIR_HINTS: List of additional directories in which to
57 # search for SuiteSparse libraries,
58 # e.g: /timbuktu/lib.
59 #
60 # The following variables define the presence / includes & libraries for the
61 # SuiteSparse components searched for, the SUITESPARSE_XX variables are the
62 # union of the variables for all components.
63 #
64 # == Symmetric Approximate Minimum Degree (AMD)
65 # AMD_FOUND
66 # AMD_INCLUDE_DIR
67 # AMD_LIBRARY
68 #
69 # == Constrained Approximate Minimum Degree (CAMD)
70 # CAMD_FOUND
71 # CAMD_INCLUDE_DIR
72 # CAMD_LIBRARY
73 #
74 # == Column Approximate Minimum Degree (COLAMD)
75 # COLAMD_FOUND
76 # COLAMD_INCLUDE_DIR
77 # COLAMD_LIBRARY
78 #
79 # Constrained Column Approximate Minimum Degree (CCOLAMD)
80 # CCOLAMD_FOUND
81 # CCOLAMD_INCLUDE_DIR
82 # CCOLAMD_LIBRARY
83 #
84 # == Sparse Supernodal Cholesky Factorization and Update/Downdate (CHOLMOD)
85 # CHOLMOD_FOUND
86 # CHOLMOD_INCLUDE_DIR
87 # CHOLMOD_LIBRARY
88 #
89 # == Multifrontal Sparse QR (SuiteSparseQR)
90 # SUITESPARSEQR_FOUND
91 # SUITESPARSEQR_INCLUDE_DIR
92 # SUITESPARSEQR_LIBRARY
93 #
94 # == Common configuration for all but CSparse (SuiteSparse version >= 4).
95 # SUITESPARSE_CONFIG_FOUND
96 # SUITESPARSE_CONFIG_INCLUDE_DIR
97 # SUITESPARSE_CONFIG_LIBRARY
98 #
99 # == Common configuration for all but CSparse (SuiteSparse version < 4).
100 # UFCONFIG_FOUND
101 # UFCONFIG_INCLUDE_DIR
102 #
103 # Optional SuiteSparse Dependencies:
104 #
105 # == Serial Graph Partitioning and Fill-reducing Matrix Ordering (METIS)
106 # METIS_FOUND
107 # METIS_LIBRARY
108
109 # Reset CALLERS_CMAKE_FIND_LIBRARY_PREFIXES to its value when
110 # FindSuiteSparse was invoked.
111 macro(SUITESPARSE_RESET_FIND_LIBRARY_PREFIX)
112 if (MSVC)
113 set(CMAKE_FIND_LIBRARY_PREFIXES "${CALLERS_CMAKE_FIND_LIBRARY_PREFIXES}")
114 endif (MSVC)
115 endmacro(SUITESPARSE_RESET_FIND_LIBRARY_PREFIX)
116
117 # Called if we failed to find SuiteSparse or any of it's required dependencies,
118 # unsets all public (designed to be used externally) variables and reports
119 # error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument.
120 macro(SUITESPARSE_REPORT_NOT_FOUND REASON_MSG)
121 unset(SUITESPARSE_FOUND)
122 unset(SUITESPARSE_INCLUDE_DIRS)
123 unset(SUITESPARSE_LIBRARIES)
124 unset(SUITESPARSE_VERSION)
125 unset(SUITESPARSE_MAIN_VERSION)
126 unset(SUITESPARSE_SUB_VERSION)
127 unset(SUITESPARSE_SUBSUB_VERSION)
128 # Do NOT unset SUITESPARSE_FOUND_REQUIRED_VARS here, as it is used by
129 # FindPackageHandleStandardArgs() to generate the automatic error message on
130 # failure which highlights which components are missing.
131
132 suitesparse_reset_find_library_prefix()
133
134 # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage()
135 # use the camelcase library name, not uppercase.
136 if (SuiteSparse_FIND_QUIETLY)
137 message(STATUS "Failed to find SuiteSparse - " ${REASON_MSG} ${ARGN})
138 elseif (SuiteSparse_FIND_REQUIRED)
139 message(FATAL_ERROR "Failed to find SuiteSparse - " ${REASON_MSG} ${ARGN})
140 else()
141 # Neither QUIETLY nor REQUIRED, use no priority which emits a message
142 # but continues configuration and allows generation.
143 message("-- Failed to find SuiteSparse - " ${REASON_MSG} ${ARGN})
144 endif (SuiteSparse_FIND_QUIETLY)
145
146 # Do not call return(), s/t we keep processing if not called with REQUIRED
147 # and report all missing components, rather than bailing after failing to find
148 # the first.
149 endmacro(SUITESPARSE_REPORT_NOT_FOUND)
150
151 # Protect against any alternative find_package scripts for this library having
152 # been called previously (in a client project) which set SUITESPARSE_FOUND, but
153 # not the other variables we require / set here which could cause the search
154 # logic here to fail.
155 unset(SUITESPARSE_FOUND)
156
157 # Handle possible presence of lib prefix for libraries on MSVC, see
158 # also SUITESPARSE_RESET_FIND_LIBRARY_PREFIX().
159 if (MSVC)
160 # Preserve the caller's original values for CMAKE_FIND_LIBRARY_PREFIXES
161 # s/t we can set it back before returning.
162 set(CALLERS_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
163 # The empty string in this list is important, it represents the case when
164 # the libraries have no prefix (shared libraries / DLLs).
165 set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "" "${CMAKE_FIND_LIBRARY_PREFIXES}")
166 endif (MSVC)
167
168 # On macOS, add the Homebrew prefix (with appropriate suffixes) to the
169 # respective HINTS directories (after any user-specified locations). This
170 # handles Homebrew installations into non-standard locations (not /usr/local).
171 # We do not use CMAKE_PREFIX_PATH for this as given the search ordering of
172 # find_xxx(), doing so would override any user-specified HINTS locations with
173 # the Homebrew version if it exists.
174 if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
175 find_program(HOMEBREW_EXECUTABLE brew)
176 mark_as_advanced(FORCE HOMEBREW_EXECUTABLE)
177 if (HOMEBREW_EXECUTABLE)
178 # Detected a Homebrew install, query for its install prefix.
179 execute_process(COMMAND ${HOMEBREW_EXECUTABLE} --prefix
180 OUTPUT_VARIABLE HOMEBREW_INSTALL_PREFIX
181 OUTPUT_STRIP_TRAILING_WHITESPACE)
182 message(STATUS "Detected Homebrew with install prefix: "
183 "${HOMEBREW_INSTALL_PREFIX}, adding to CMake search paths.")
184 list(APPEND SUITESPARSE_INCLUDE_DIR_HINTS "${HOMEBREW_INSTALL_PREFIX}/include")
185 list(APPEND SUITESPARSE_LIBRARY_DIR_HINTS "${HOMEBREW_INSTALL_PREFIX}/lib")
186 endif()
187 endif()
188
189 # Specify search directories for include files and libraries (this is the union
190 # of the search directories for all OSs). Search user-specified hint
191 # directories first if supplied, and search user-installed locations first
192 # so that we prefer user installs to system installs where both exist.
193 list(APPEND SUITESPARSE_CHECK_INCLUDE_DIRS
194 /opt/local/include
195 /opt/local/include/ufsparse # Mac OS X
196 /usr/local/homebrew/include # Mac OS X
197 /usr/local/include
198 /usr/include)
199 list(APPEND SUITESPARSE_CHECK_LIBRARY_DIRS
200 /opt/local/lib
201 /opt/local/lib/ufsparse # Mac OS X
202 /usr/local/homebrew/lib # Mac OS X
203 /usr/local/lib
204 /usr/lib)
205 # Additional suffixes to try appending to each search path.
206 list(APPEND SUITESPARSE_CHECK_PATH_SUFFIXES
207 suitesparse) # Windows/Ubuntu
208
209 # Wrappers to find_path/library that pass the SuiteSparse search hints/paths.
210 #
211 # suitesparse_find_component(<component> [FILES name1 [name2 ...]]
212 # [LIBRARIES name1 [name2 ...]]
213 # [REQUIRED])
214 macro(suitesparse_find_component COMPONENT)
215 include(CMakeParseArguments)
216 set(OPTIONS REQUIRED)
217 set(MULTI_VALUE_ARGS FILES LIBRARIES)
218 cmake_parse_arguments(SUITESPARSE_FIND_${COMPONENT}
219 "${OPTIONS}" "" "${MULTI_VALUE_ARGS}" ${ARGN})
220
221 if (SUITESPARSE_FIND_${COMPONENT}_REQUIRED)
222 list(APPEND SUITESPARSE_FOUND_REQUIRED_VARS ${COMPONENT}_FOUND)
223 endif()
224
225 set(${COMPONENT}_FOUND TRUE)
226 if (SUITESPARSE_FIND_${COMPONENT}_FILES)
227 find_path(${COMPONENT}_INCLUDE_DIR
228 NAMES ${SUITESPARSE_FIND_${COMPONENT}_FILES}
229 HINTS ${SUITESPARSE_INCLUDE_DIR_HINTS}
230 PATHS ${SUITESPARSE_CHECK_INCLUDE_DIRS}
231 PATH_SUFFIXES ${SUITESPARSE_CHECK_PATH_SUFFIXES})
232 if (${COMPONENT}_INCLUDE_DIR)
233 message(STATUS "Found ${COMPONENT} headers in: "
234 "${${COMPONENT}_INCLUDE_DIR}")
235 mark_as_advanced(${COMPONENT}_INCLUDE_DIR)
236 else()
237 # Specified headers not found.
238 set(${COMPONENT}_FOUND FALSE)
239 if (SUITESPARSE_FIND_${COMPONENT}_REQUIRED)
240 suitesparse_report_not_found(
241 "Did not find ${COMPONENT} header (required SuiteSparse component).")
242 else()
243 message(STATUS "Did not find ${COMPONENT} header (optional "
244 "SuiteSparse component).")
245 # Hide optional vars from CMake GUI even if not found.
246 mark_as_advanced(${COMPONENT}_INCLUDE_DIR)
247 endif()
248 endif()
249 endif()
250
251 if (SUITESPARSE_FIND_${COMPONENT}_LIBRARIES)
252 find_library(${COMPONENT}_LIBRARY
253 NAMES ${SUITESPARSE_FIND_${COMPONENT}_LIBRARIES}
254 HINTS ${SUITESPARSE_LIBRARY_DIR_HINTS}
255 PATHS ${SUITESPARSE_CHECK_LIBRARY_DIRS}
256 PATH_SUFFIXES ${SUITESPARSE_CHECK_PATH_SUFFIXES})
257 if (${COMPONENT}_LIBRARY)
258 message(STATUS "Found ${COMPONENT} library: ${${COMPONENT}_LIBRARY}")
259 mark_as_advanced(${COMPONENT}_LIBRARY)
260 else ()
261 # Specified libraries not found.
262 set(${COMPONENT}_FOUND FALSE)
263 if (SUITESPARSE_FIND_${COMPONENT}_REQUIRED)
264 suitesparse_report_not_found(
265 "Did not find ${COMPONENT} library (required SuiteSparse component).")
266 else()
267 message(STATUS "Did not find ${COMPONENT} library (optional SuiteSparse "
268 "dependency)")
269 # Hide optional vars from CMake GUI even if not found.
270 mark_as_advanced(${COMPONENT}_LIBRARY)
271 endif()
272 endif()
273 endif()
274 endmacro()
275
276 # Given the number of components of SuiteSparse, and to ensure that the
277 # automatic failure message generated by FindPackageHandleStandardArgs()
278 # when not all required components are found is helpful, we maintain a list
279 # of all variables that must be defined for SuiteSparse to be considered found.
280 unset(SUITESPARSE_FOUND_REQUIRED_VARS)
281
282 message(STATUS "@@@@ finding blas")
283 # BLAS.
284 find_package(BLAS)
285 if (NOT BLAS_FOUND)
286 suitesparse_report_not_found(
287 "Did not find BLAS library (required for SuiteSparse).")
288 endif (NOT BLAS_FOUND)
289 list(APPEND SUITESPARSE_FOUND_REQUIRED_VARS BLAS_FOUND)
290
291 message(STATUS "@@@@ finding lapack")
292 # LAPACK.
293 find_package(LAPACK)
294 if (NOT LAPACK_FOUND)
295 suitesparse_report_not_found(
296 "Did not find LAPACK library (required for SuiteSparse).")
297 endif (NOT LAPACK_FOUND)
298 list(APPEND SUITESPARSE_FOUND_REQUIRED_VARS LAPACK_FOUND)
299
300 message(STATUS "@@@@ finding amd")
301 suitesparse_find_component(AMD REQUIRED FILES amd.h LIBRARIES amd)
302 message(STATUS "@@@@ finding camd")
303 suitesparse_find_component(CAMD REQUIRED FILES camd.h LIBRARIES camd)
304 message(STATUS "@@@@ finding colamd")
305 suitesparse_find_component(COLAMD REQUIRED FILES colamd.h LIBRARIES colamd)
306 message(STATUS "@@@@ finding ccolamd")
307 suitesparse_find_component(CCOLAMD REQUIRED FILES ccolamd.h LIBRARIES ccolamd)
308 message(STATUS "@@@@ finding cholmod")
309 suitesparse_find_component(CHOLMOD REQUIRED FILES cholmod.h LIBRARIES cholmod)
310 message(STATUS "@@@@ finding parseqr")
311 suitesparse_find_component(
312 SUITESPARSEQR REQUIRED FILES SuiteSparseQR.hpp LIBRARIES spqr)
313 if (SUITESPARSEQR_FOUND)
314 # SuiteSparseQR may be compiled with Intel Threading Building Blocks,
315 # we assume that if TBB is installed, SuiteSparseQR was compiled with
316 # support for it, this will do no harm if it wasn't.
317 find_package(TBB QUIET)
318 if (TBB_FOUND)
319 message(STATUS "Found Intel Thread Building Blocks (TBB) library "
320 "(${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR} / ${TBB_INTERFACE_VERSION}) "
321 "include location: ${TBB_INCLUDE_DIRS}. Assuming SuiteSparseQR was "
322 "compiled with TBB.")
323 # Add the TBB libraries to the SuiteSparseQR libraries (the only
324 # libraries to optionally depend on TBB).
325 list(APPEND SUITESPARSEQR_LIBRARY ${TBB_LIBRARIES})
326 else()
327 message(STATUS "Did not find Intel TBB library, assuming SuiteSparseQR was "
328 "not compiled with TBB.")
329 endif()
330 endif(SUITESPARSEQR_FOUND)
331
332 message(STATUS "@@@@ finding config")
333 # UFconfig / SuiteSparse_config.
334 #
335 # If SuiteSparse version is >= 4 then SuiteSparse_config is required.
336 # For SuiteSparse 3, UFconfig.h is required.
337 suitesparse_find_component(
338 SUITESPARSE_CONFIG FILES SuiteSparse_config.h LIBRARIES suitesparseconfig)
339
340 if (SUITESPARSE_CONFIG_FOUND)
341 # SuiteSparse_config (SuiteSparse version >= 4) requires librt library for
342 # timing by default when compiled on Linux or Unix, but not on OSX (which
343 # does not have librt).
344 if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR UNIX AND NOT APPLE)
345 suitesparse_find_component(LIBRT LIBRARIES rt)
346 if (LIBRT_FOUND)
347 message(STATUS "Adding librt: ${LIBRT_LIBRARY} to "
348 "SuiteSparse_config libraries (required on Linux & Unix [not OSX] if "
349 "SuiteSparse is compiled with timing).")
350 list(APPEND SUITESPARSE_CONFIG_LIBRARY ${LIBRT_LIBRARY})
351 else()
352 message(STATUS "Could not find librt, but found SuiteSparse_config, "
353 "assuming that SuiteSparse was compiled without timing.")
354 endif ()
355 endif (CMAKE_SYSTEM_NAME MATCHES "Linux" OR UNIX AND NOT APPLE)
356 else()
357 # Failed to find SuiteSparse_config (>= v4 installs), instead look for
358 # UFconfig header which should be present in < v4 installs.
359 suitesparse_find_component(UFCONFIG FILES UFconfig.h)
360 endif ()
361
362 if (NOT SUITESPARSE_CONFIG_FOUND AND
363 NOT UFCONFIG_FOUND)
364 suitesparse_report_not_found(
365 "Failed to find either: SuiteSparse_config header & library (should be "
366 "present in all SuiteSparse >= v4 installs), or UFconfig header (should "
367 "be present in all SuiteSparse < v4 installs).")
368 endif()
369
370 # Extract the SuiteSparse version from the appropriate header (UFconfig.h for
371 # <= v3, SuiteSparse_config.h for >= v4).
372 list(APPEND SUITESPARSE_FOUND_REQUIRED_VARS SUITESPARSE_VERSION)
373
374 if (UFCONFIG_FOUND)
375 # SuiteSparse version <= 3.
376 set(SUITESPARSE_VERSION_FILE ${UFCONFIG_INCLUDE_DIR}/UFconfig.h)
377 if (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
378 suitesparse_report_not_found(
379 "Could not find file: ${SUITESPARSE_VERSION_FILE} containing version "
380 "information for <= v3 SuiteSparse installs, but UFconfig was found "
381 "(only present in <= v3 installs).")
382 else (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
383 file(READ ${SUITESPARSE_VERSION_FILE} UFCONFIG_CONTENTS)
384
385 string(REGEX MATCH "#define SUITESPARSE_MAIN_VERSION [0-9]+"
386 SUITESPARSE_MAIN_VERSION "${UFCONFIG_CONTENTS}")
387 string(REGEX REPLACE "#define SUITESPARSE_MAIN_VERSION ([0-9]+)" "\\1"
388 SUITESPARSE_MAIN_VERSION "${SUITESPARSE_MAIN_VERSION}")
389
390 string(REGEX MATCH "#define SUITESPARSE_SUB_VERSION [0-9]+"
391 SUITESPARSE_SUB_VERSION "${UFCONFIG_CONTENTS}")
392 string(REGEX REPLACE "#define SUITESPARSE_SUB_VERSION ([0-9]+)" "\\1"
393 SUITESPARSE_SUB_VERSION "${SUITESPARSE_SUB_VERSION}")
394
395 string(REGEX MATCH "#define SUITESPARSE_SUBSUB_VERSION [0-9]+"
396 SUITESPARSE_SUBSUB_VERSION "${UFCONFIG_CONTENTS}")
397 string(REGEX REPLACE "#define SUITESPARSE_SUBSUB_VERSION ([0-9]+)" "\\1"
398 SUITESPARSE_SUBSUB_VERSION "${SUITESPARSE_SUBSUB_VERSION}")
399
400 # This is on a single line s/t CMake does not interpret it as a list of
401 # elements and insert ';' separators which would result in 4.;2.;1 nonsense.
402 set(SUITESPARSE_VERSION
403 "${SUITESPARSE_MAIN_VERSION}.${SUITESPARSE_SUB_VERSION}.${SUITESPARSE_SUBSUB_VERSION}")
404 endif (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
405 endif (UFCONFIG_FOUND)
406
407 if (SUITESPARSE_CONFIG_FOUND)
408 # SuiteSparse version >= 4.
409 set(SUITESPARSE_VERSION_FILE
410 ${SUITESPARSE_CONFIG_INCLUDE_DIR}/SuiteSparse_config.h)
411 if (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
412 suitesparse_report_not_found(
413 "Could not find file: ${SUITESPARSE_VERSION_FILE} containing version "
414 "information for >= v4 SuiteSparse installs, but SuiteSparse_config was "
415 "found (only present in >= v4 installs).")
416 else (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
417 file(READ ${SUITESPARSE_VERSION_FILE} SUITESPARSE_CONFIG_CONTENTS)
418
419 string(REGEX MATCH "#define SUITESPARSE_MAIN_VERSION [0-9]+"
420 SUITESPARSE_MAIN_VERSION "${SUITESPARSE_CONFIG_CONTENTS}")
421 string(REGEX REPLACE "#define SUITESPARSE_MAIN_VERSION ([0-9]+)" "\\1"
422 SUITESPARSE_MAIN_VERSION "${SUITESPARSE_MAIN_VERSION}")
423
424 string(REGEX MATCH "#define SUITESPARSE_SUB_VERSION [0-9]+"
425 SUITESPARSE_SUB_VERSION "${SUITESPARSE_CONFIG_CONTENTS}")
426 string(REGEX REPLACE "#define SUITESPARSE_SUB_VERSION ([0-9]+)" "\\1"
427 SUITESPARSE_SUB_VERSION "${SUITESPARSE_SUB_VERSION}")
428
429 string(REGEX MATCH "#define SUITESPARSE_SUBSUB_VERSION [0-9]+"
430 SUITESPARSE_SUBSUB_VERSION "${SUITESPARSE_CONFIG_CONTENTS}")
431 string(REGEX REPLACE "#define SUITESPARSE_SUBSUB_VERSION ([0-9]+)" "\\1"
432 SUITESPARSE_SUBSUB_VERSION "${SUITESPARSE_SUBSUB_VERSION}")
433
434 # This is on a single line s/t CMake does not interpret it as a list of
435 # elements and insert ';' separators which would result in 4.;2.;1 nonsense.
436 set(SUITESPARSE_VERSION
437 "${SUITESPARSE_MAIN_VERSION}.${SUITESPARSE_SUB_VERSION}.${SUITESPARSE_SUBSUB_VERSION}")
438 endif (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
439 endif (SUITESPARSE_CONFIG_FOUND)
440
441 message(STATUS "@@@@ finding metis")
442 # METIS (Optional dependency).
443 suitesparse_find_component(METIS LIBRARIES metis)
444
445 # Only mark SuiteSparse as found if all required components and dependencies
446 # have been found.
447 set(SUITESPARSE_FOUND TRUE)
448 foreach(REQUIRED_VAR ${SUITESPARSE_FOUND_REQUIRED_VARS})
449 if (NOT ${REQUIRED_VAR})
450 set(SUITESPARSE_FOUND FALSE)
451 endif (NOT ${REQUIRED_VAR})
452 endforeach(REQUIRED_VAR ${SUITESPARSE_FOUND_REQUIRED_VARS})
453
454 if (SUITESPARSE_FOUND)
455 list(APPEND SUITESPARSE_INCLUDE_DIRS
456 ${AMD_INCLUDE_DIR}
457 ${CAMD_INCLUDE_DIR}
458 ${COLAMD_INCLUDE_DIR}
459 ${CCOLAMD_INCLUDE_DIR}
460 ${CHOLMOD_INCLUDE_DIR}
461 ${SUITESPARSEQR_INCLUDE_DIR})
462 # Handle config separately, as otherwise at least one of them will be set
463 # to NOTFOUND which would cause any check on SUITESPARSE_INCLUDE_DIRS to fail.
464 if (SUITESPARSE_CONFIG_FOUND)
465 list(APPEND SUITESPARSE_INCLUDE_DIRS
466 ${SUITESPARSE_CONFIG_INCLUDE_DIR})
467 endif (SUITESPARSE_CONFIG_FOUND)
468 if (UFCONFIG_FOUND)
469 list(APPEND SUITESPARSE_INCLUDE_DIRS
470 ${UFCONFIG_INCLUDE_DIR})
471 endif (UFCONFIG_FOUND)
472 # As SuiteSparse includes are often all in the same directory, remove any
473 # repetitions.
474 list(REMOVE_DUPLICATES SUITESPARSE_INCLUDE_DIRS)
475
476 # Important: The ordering of these libraries is *NOT* arbitrary, as these
477 # could potentially be static libraries their link ordering is important.
478 list(APPEND SUITESPARSE_LIBRARIES
479 ${SUITESPARSEQR_LIBRARY}
480 ${CHOLMOD_LIBRARY}
481 ${CCOLAMD_LIBRARY}
482 ${CAMD_LIBRARY}
483 ${COLAMD_LIBRARY}
484 ${AMD_LIBRARY}
485 ${LAPACK_LIBRARIES}
486 ${BLAS_LIBRARIES})
487 if (SUITESPARSE_CONFIG_FOUND)
488 list(APPEND SUITESPARSE_LIBRARIES
489 ${SUITESPARSE_CONFIG_LIBRARY})
490 endif (SUITESPARSE_CONFIG_FOUND)
491 if (METIS_FOUND)
492 list(APPEND SUITESPARSE_LIBRARIES
493 ${METIS_LIBRARY})
494 endif (METIS_FOUND)
495 endif()
496
497 # Determine if we are running on Ubuntu with the package install of SuiteSparse
498 # which is broken and does not support linking a shared library.
499 set(SUITESPARSE_IS_BROKEN_SHARED_LINKING_UBUNTU_SYSTEM_VERSION FALSE)
500 if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND
501 SUITESPARSE_VERSION VERSION_EQUAL 3.4.0)
502 find_program(LSB_RELEASE_EXECUTABLE lsb_release)
503 if (LSB_RELEASE_EXECUTABLE)
504 # Any even moderately recent Ubuntu release (likely to be affected by
505 # this bug) should have lsb_release, if it isn't present we are likely
506 # on a different Linux distribution (should be fine).
507 execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -si
508 OUTPUT_VARIABLE LSB_DISTRIBUTOR_ID
509 OUTPUT_STRIP_TRAILING_WHITESPACE)
510
511 if (LSB_DISTRIBUTOR_ID MATCHES "Ubuntu" AND
512 SUITESPARSE_LIBRARIES MATCHES "/usr/lib/libamd")
513 # We are on Ubuntu, and the SuiteSparse version matches the broken
514 # system install version and is a system install.
515 set(SUITESPARSE_IS_BROKEN_SHARED_LINKING_UBUNTU_SYSTEM_VERSION TRUE)
516 message(STATUS "Found system install of SuiteSparse "
517 "${SUITESPARSE_VERSION} running on Ubuntu, which has a known bug "
518 "preventing linking of shared libraries (static linking unaffected).")
519 endif (LSB_DISTRIBUTOR_ID MATCHES "Ubuntu" AND
520 SUITESPARSE_LIBRARIES MATCHES "/usr/lib/libamd")
521 endif (LSB_RELEASE_EXECUTABLE)
522 endif (CMAKE_SYSTEM_NAME MATCHES "Linux" AND
523 SUITESPARSE_VERSION VERSION_EQUAL 3.4.0)
524
525 suitesparse_reset_find_library_prefix()
526
527 # Handle REQUIRED and QUIET arguments to FIND_PACKAGE
528 include(FindPackageHandleStandardArgs)
529 if (SUITESPARSE_FOUND)
530 find_package_handle_standard_args(SuiteSparse
531 REQUIRED_VARS ${SUITESPARSE_FOUND_REQUIRED_VARS}
532 VERSION_VAR SUITESPARSE_VERSION
533 FAIL_MESSAGE "Failed to find some/all required components of SuiteSparse.")
534 else (SUITESPARSE_FOUND)
535 # Do not pass VERSION_VAR to FindPackageHandleStandardArgs() if we failed to
536 # find SuiteSparse to avoid a confusing autogenerated failure message
537 # that states 'not found (missing: FOO) (found version: x.y.z)'.
538 find_package_handle_standard_args(SuiteSparse
539 REQUIRED_VARS ${SUITESPARSE_FOUND_REQUIRED_VARS}
540 FAIL_MESSAGE "Failed to find some/all required components of SuiteSparse.")
541 endif (SUITESPARSE_FOUND)