blob: e4de8b02910c10cdedb9950ffc6ae7f5cb9d9c02 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001# 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: alexs.mac@gmail.com (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.
111macro(SUITESPARSE_RESET_FIND_LIBRARY_PREFIX)
112 if (MSVC)
113 set(CMAKE_FIND_LIBRARY_PREFIXES "${CALLERS_CMAKE_FIND_LIBRARY_PREFIXES}")
114 endif (MSVC)
115endmacro(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.
120macro(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.
149endmacro(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.
155unset(SUITESPARSE_FOUND)
156
157# Handle possible presence of lib prefix for libraries on MSVC, see
158# also SUITESPARSE_RESET_FIND_LIBRARY_PREFIX().
159if (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}")
166endif (MSVC)
167
168# Specify search directories for include files and libraries (this is the union
169# of the search directories for all OSs). Search user-specified hint
170# directories first if supplied, and search user-installed locations first
171# so that we prefer user installs to system installs where both exist.
172list(APPEND SUITESPARSE_CHECK_INCLUDE_DIRS
173 /opt/local/include
174 /opt/local/include/ufsparse # Mac OS X
175 /usr/local/homebrew/include # Mac OS X
176 /usr/local/include
177 /usr/include)
178list(APPEND SUITESPARSE_CHECK_LIBRARY_DIRS
179 /opt/local/lib
180 /opt/local/lib/ufsparse # Mac OS X
181 /usr/local/homebrew/lib # Mac OS X
182 /usr/local/lib
183 /usr/lib)
184# Additional suffixes to try appending to each search path.
185list(APPEND SUITESPARSE_CHECK_PATH_SUFFIXES
186 suitesparse) # Windows/Ubuntu
187
188# Wrappers to find_path/library that pass the SuiteSparse search hints/paths.
189#
190# suitesparse_find_component(<component> [FILES name1 [name2 ...]]
191# [LIBRARIES name1 [name2 ...]]
192# [REQUIRED])
193macro(suitesparse_find_component COMPONENT)
194 include(CMakeParseArguments)
195 set(OPTIONS REQUIRED)
196 set(MULTI_VALUE_ARGS FILES LIBRARIES)
197 cmake_parse_arguments(SUITESPARSE_FIND_${COMPONENT}
198 "${OPTIONS}" "" "${MULTI_VALUE_ARGS}" ${ARGN})
199
200 if (SUITESPARSE_FIND_${COMPONENT}_REQUIRED)
201 list(APPEND SUITESPARSE_FOUND_REQUIRED_VARS ${COMPONENT}_FOUND)
202 endif()
203
204 set(${COMPONENT}_FOUND TRUE)
205 if (SUITESPARSE_FIND_${COMPONENT}_FILES)
206 find_path(${COMPONENT}_INCLUDE_DIR
207 NAMES ${SUITESPARSE_FIND_${COMPONENT}_FILES}
208 HINTS ${SUITESPARSE_INCLUDE_DIR_HINTS}
209 PATHS ${SUITESPARSE_CHECK_INCLUDE_DIRS}
210 PATH_SUFFIXES ${SUITESPARSE_CHECK_PATH_SUFFIXES})
211 if (${COMPONENT}_INCLUDE_DIR)
212 message(STATUS "Found ${COMPONENT} headers in: "
213 "${${COMPONENT}_INCLUDE_DIR}")
214 mark_as_advanced(${COMPONENT}_INCLUDE_DIR)
215 else()
216 # Specified headers not found.
217 set(${COMPONENT}_FOUND FALSE)
218 if (SUITESPARSE_FIND_${COMPONENT}_REQUIRED)
219 suitesparse_report_not_found(
220 "Did not find ${COMPONENT} header (required SuiteSparse component).")
221 else()
222 message(STATUS "Did not find ${COMPONENT} header (optional "
223 "SuiteSparse component).")
224 # Hide optional vars from CMake GUI even if not found.
225 mark_as_advanced(${COMPONENT}_INCLUDE_DIR)
226 endif()
227 endif()
228 endif()
229
230 if (SUITESPARSE_FIND_${COMPONENT}_LIBRARIES)
231 find_library(${COMPONENT}_LIBRARY
232 NAMES ${SUITESPARSE_FIND_${COMPONENT}_LIBRARIES}
233 HINTS ${SUITESPARSE_LIBRARY_DIR_HINTS}
234 PATHS ${SUITESPARSE_CHECK_LIBRARY_DIRS}
235 PATH_SUFFIXES ${SUITESPARSE_CHECK_PATH_SUFFIXES})
236 if (${COMPONENT}_LIBRARY)
237 message(STATUS "Found ${COMPONENT} library: ${${COMPONENT}_LIBRARY}")
238 mark_as_advanced(${COMPONENT}_LIBRARY)
239 else ()
240 # Specified libraries not found.
241 set(${COMPONENT}_FOUND FALSE)
242 if (SUITESPARSE_FIND_${COMPONENT}_REQUIRED)
243 suitesparse_report_not_found(
244 "Did not find ${COMPONENT} library (required SuiteSparse component).")
245 else()
246 message(STATUS "Did not find ${COMPONENT} library (optional SuiteSparse "
247 "dependency)")
248 # Hide optional vars from CMake GUI even if not found.
249 mark_as_advanced(${COMPONENT}_LIBRARY)
250 endif()
251 endif()
252 endif()
253endmacro()
254
255# Given the number of components of SuiteSparse, and to ensure that the
256# automatic failure message generated by FindPackageHandleStandardArgs()
257# when not all required components are found is helpful, we maintain a list
258# of all variables that must be defined for SuiteSparse to be considered found.
259unset(SUITESPARSE_FOUND_REQUIRED_VARS)
260
261# BLAS.
262find_package(BLAS QUIET)
263if (NOT BLAS_FOUND)
264 suitesparse_report_not_found(
265 "Did not find BLAS library (required for SuiteSparse).")
266endif (NOT BLAS_FOUND)
267list(APPEND SUITESPARSE_FOUND_REQUIRED_VARS BLAS_FOUND)
268
269# LAPACK.
270find_package(LAPACK QUIET)
271if (NOT LAPACK_FOUND)
272 suitesparse_report_not_found(
273 "Did not find LAPACK library (required for SuiteSparse).")
274endif (NOT LAPACK_FOUND)
275list(APPEND SUITESPARSE_FOUND_REQUIRED_VARS LAPACK_FOUND)
276
277suitesparse_find_component(AMD REQUIRED FILES amd.h LIBRARIES amd)
278suitesparse_find_component(CAMD REQUIRED FILES camd.h LIBRARIES camd)
279suitesparse_find_component(COLAMD REQUIRED FILES colamd.h LIBRARIES colamd)
280suitesparse_find_component(CCOLAMD REQUIRED FILES ccolamd.h LIBRARIES ccolamd)
281suitesparse_find_component(CHOLMOD REQUIRED FILES cholmod.h LIBRARIES cholmod)
282suitesparse_find_component(
283 SUITESPARSEQR REQUIRED FILES SuiteSparseQR.hpp LIBRARIES spqr)
284if (SUITESPARSEQR_FOUND)
285 # SuiteSparseQR may be compiled with Intel Threading Building Blocks,
286 # we assume that if TBB is installed, SuiteSparseQR was compiled with
287 # support for it, this will do no harm if it wasn't.
288 find_package(TBB QUIET)
289 if (TBB_FOUND)
290 message(STATUS "Found Intel Thread Building Blocks (TBB) library "
291 "(${TBB_VERSION}) assuming SuiteSparseQR was compiled "
292 "with TBB.")
293 # Add the TBB libraries to the SuiteSparseQR libraries (the only
294 # libraries to optionally depend on TBB).
295 list(APPEND SUITESPARSEQR_LIBRARY ${TBB_LIBRARIES})
296 else()
297 message(STATUS "Did not find Intel TBB library, assuming SuiteSparseQR was "
298 "not compiled with TBB.")
299 endif()
300endif(SUITESPARSEQR_FOUND)
301
302# UFconfig / SuiteSparse_config.
303#
304# If SuiteSparse version is >= 4 then SuiteSparse_config is required.
305# For SuiteSparse 3, UFconfig.h is required.
306suitesparse_find_component(
307 SUITESPARSE_CONFIG FILES SuiteSparse_config.h LIBRARIES suitesparseconfig)
308
309if (SUITESPARSE_CONFIG_FOUND)
310 # SuiteSparse_config (SuiteSparse version >= 4) requires librt library for
311 # timing by default when compiled on Linux or Unix, but not on OSX (which
312 # does not have librt).
313 if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR UNIX AND NOT APPLE)
314 suitesparse_find_component(LIBRT LIBRARIES rt)
315 if (LIBRT_FOUND)
316 message(STATUS "Adding librt: ${LIBRT_LIBRARY} to "
317 "SuiteSparse_config libraries (required on Linux & Unix [not OSX] if "
318 "SuiteSparse is compiled with timing).")
319 list(APPEND SUITESPARSE_CONFIG_LIBRARY ${LIBRT_LIBRARY})
320 else()
321 message(STATUS "Could not find librt, but found SuiteSparse_config, "
322 "assuming that SuiteSparse was compiled without timing.")
323 endif ()
324 endif (CMAKE_SYSTEM_NAME MATCHES "Linux" OR UNIX AND NOT APPLE)
325else()
326 # Failed to find SuiteSparse_config (>= v4 installs), instead look for
327 # UFconfig header which should be present in < v4 installs.
328 suitesparse_find_component(UFCONFIG FILES UFconfig.h)
329endif ()
330
331if (NOT SUITESPARSE_CONFIG_FOUND AND
332 NOT UFCONFIG_FOUND)
333 suitesparse_report_not_found(
334 "Failed to find either: SuiteSparse_config header & library (should be "
335 "present in all SuiteSparse >= v4 installs), or UFconfig header (should "
336 "be present in all SuiteSparse < v4 installs).")
337endif()
338
339# Extract the SuiteSparse version from the appropriate header (UFconfig.h for
340# <= v3, SuiteSparse_config.h for >= v4).
341list(APPEND SUITESPARSE_FOUND_REQUIRED_VARS SUITESPARSE_VERSION)
342
343if (UFCONFIG_FOUND)
344 # SuiteSparse version <= 3.
345 set(SUITESPARSE_VERSION_FILE ${UFCONFIG_INCLUDE_DIR}/UFconfig.h)
346 if (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
347 suitesparse_report_not_found(
348 "Could not find file: ${SUITESPARSE_VERSION_FILE} containing version "
349 "information for <= v3 SuiteSparse installs, but UFconfig was found "
350 "(only present in <= v3 installs).")
351 else (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
352 file(READ ${SUITESPARSE_VERSION_FILE} UFCONFIG_CONTENTS)
353
354 string(REGEX MATCH "#define SUITESPARSE_MAIN_VERSION [0-9]+"
355 SUITESPARSE_MAIN_VERSION "${UFCONFIG_CONTENTS}")
356 string(REGEX REPLACE "#define SUITESPARSE_MAIN_VERSION ([0-9]+)" "\\1"
357 SUITESPARSE_MAIN_VERSION "${SUITESPARSE_MAIN_VERSION}")
358
359 string(REGEX MATCH "#define SUITESPARSE_SUB_VERSION [0-9]+"
360 SUITESPARSE_SUB_VERSION "${UFCONFIG_CONTENTS}")
361 string(REGEX REPLACE "#define SUITESPARSE_SUB_VERSION ([0-9]+)" "\\1"
362 SUITESPARSE_SUB_VERSION "${SUITESPARSE_SUB_VERSION}")
363
364 string(REGEX MATCH "#define SUITESPARSE_SUBSUB_VERSION [0-9]+"
365 SUITESPARSE_SUBSUB_VERSION "${UFCONFIG_CONTENTS}")
366 string(REGEX REPLACE "#define SUITESPARSE_SUBSUB_VERSION ([0-9]+)" "\\1"
367 SUITESPARSE_SUBSUB_VERSION "${SUITESPARSE_SUBSUB_VERSION}")
368
369 # This is on a single line s/t CMake does not interpret it as a list of
370 # elements and insert ';' separators which would result in 4.;2.;1 nonsense.
371 set(SUITESPARSE_VERSION
372 "${SUITESPARSE_MAIN_VERSION}.${SUITESPARSE_SUB_VERSION}.${SUITESPARSE_SUBSUB_VERSION}")
373 endif (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
374endif (UFCONFIG_FOUND)
375
376if (SUITESPARSE_CONFIG_FOUND)
377 # SuiteSparse version >= 4.
378 set(SUITESPARSE_VERSION_FILE
379 ${SUITESPARSE_CONFIG_INCLUDE_DIR}/SuiteSparse_config.h)
380 if (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
381 suitesparse_report_not_found(
382 "Could not find file: ${SUITESPARSE_VERSION_FILE} containing version "
383 "information for >= v4 SuiteSparse installs, but SuiteSparse_config was "
384 "found (only present in >= v4 installs).")
385 else (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
386 file(READ ${SUITESPARSE_VERSION_FILE} SUITESPARSE_CONFIG_CONTENTS)
387
388 string(REGEX MATCH "#define SUITESPARSE_MAIN_VERSION [0-9]+"
389 SUITESPARSE_MAIN_VERSION "${SUITESPARSE_CONFIG_CONTENTS}")
390 string(REGEX REPLACE "#define SUITESPARSE_MAIN_VERSION ([0-9]+)" "\\1"
391 SUITESPARSE_MAIN_VERSION "${SUITESPARSE_MAIN_VERSION}")
392
393 string(REGEX MATCH "#define SUITESPARSE_SUB_VERSION [0-9]+"
394 SUITESPARSE_SUB_VERSION "${SUITESPARSE_CONFIG_CONTENTS}")
395 string(REGEX REPLACE "#define SUITESPARSE_SUB_VERSION ([0-9]+)" "\\1"
396 SUITESPARSE_SUB_VERSION "${SUITESPARSE_SUB_VERSION}")
397
398 string(REGEX MATCH "#define SUITESPARSE_SUBSUB_VERSION [0-9]+"
399 SUITESPARSE_SUBSUB_VERSION "${SUITESPARSE_CONFIG_CONTENTS}")
400 string(REGEX REPLACE "#define SUITESPARSE_SUBSUB_VERSION ([0-9]+)" "\\1"
401 SUITESPARSE_SUBSUB_VERSION "${SUITESPARSE_SUBSUB_VERSION}")
402
403 # This is on a single line s/t CMake does not interpret it as a list of
404 # elements and insert ';' separators which would result in 4.;2.;1 nonsense.
405 set(SUITESPARSE_VERSION
406 "${SUITESPARSE_MAIN_VERSION}.${SUITESPARSE_SUB_VERSION}.${SUITESPARSE_SUBSUB_VERSION}")
407 endif (NOT EXISTS ${SUITESPARSE_VERSION_FILE})
408endif (SUITESPARSE_CONFIG_FOUND)
409
410# METIS (Optional dependency).
411suitesparse_find_component(METIS LIBRARIES metis)
412
413# Only mark SuiteSparse as found if all required components and dependencies
414# have been found.
415set(SUITESPARSE_FOUND TRUE)
416foreach(REQUIRED_VAR ${SUITESPARSE_FOUND_REQUIRED_VARS})
417 if (NOT ${REQUIRED_VAR})
418 set(SUITESPARSE_FOUND FALSE)
419 endif (NOT ${REQUIRED_VAR})
420endforeach(REQUIRED_VAR ${SUITESPARSE_FOUND_REQUIRED_VARS})
421
422if (SUITESPARSE_FOUND)
423 list(APPEND SUITESPARSE_INCLUDE_DIRS
424 ${AMD_INCLUDE_DIR}
425 ${CAMD_INCLUDE_DIR}
426 ${COLAMD_INCLUDE_DIR}
427 ${CCOLAMD_INCLUDE_DIR}
428 ${CHOLMOD_INCLUDE_DIR}
429 ${SUITESPARSEQR_INCLUDE_DIR})
430 # Handle config separately, as otherwise at least one of them will be set
431 # to NOTFOUND which would cause any check on SUITESPARSE_INCLUDE_DIRS to fail.
432 if (SUITESPARSE_CONFIG_FOUND)
433 list(APPEND SUITESPARSE_INCLUDE_DIRS
434 ${SUITESPARSE_CONFIG_INCLUDE_DIR})
435 endif (SUITESPARSE_CONFIG_FOUND)
436 if (UFCONFIG_FOUND)
437 list(APPEND SUITESPARSE_INCLUDE_DIRS
438 ${UFCONFIG_INCLUDE_DIR})
439 endif (UFCONFIG_FOUND)
440 # As SuiteSparse includes are often all in the same directory, remove any
441 # repetitions.
442 list(REMOVE_DUPLICATES SUITESPARSE_INCLUDE_DIRS)
443
444 # Important: The ordering of these libraries is *NOT* arbitrary, as these
445 # could potentially be static libraries their link ordering is important.
446 list(APPEND SUITESPARSE_LIBRARIES
447 ${SUITESPARSEQR_LIBRARY}
448 ${CHOLMOD_LIBRARY}
449 ${CCOLAMD_LIBRARY}
450 ${CAMD_LIBRARY}
451 ${COLAMD_LIBRARY}
452 ${AMD_LIBRARY}
453 ${LAPACK_LIBRARIES}
454 ${BLAS_LIBRARIES})
455 if (SUITESPARSE_CONFIG_FOUND)
456 list(APPEND SUITESPARSE_LIBRARIES
457 ${SUITESPARSE_CONFIG_LIBRARY})
458 endif (SUITESPARSE_CONFIG_FOUND)
459 if (METIS_FOUND)
460 list(APPEND SUITESPARSE_LIBRARIES
461 ${METIS_LIBRARY})
462 endif (METIS_FOUND)
463endif()
464
465# Determine if we are running on Ubuntu with the package install of SuiteSparse
466# which is broken and does not support linking a shared library.
467set(SUITESPARSE_IS_BROKEN_SHARED_LINKING_UBUNTU_SYSTEM_VERSION FALSE)
468if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND
469 SUITESPARSE_VERSION VERSION_EQUAL 3.4.0)
470 find_program(LSB_RELEASE_EXECUTABLE lsb_release)
471 if (LSB_RELEASE_EXECUTABLE)
472 # Any even moderately recent Ubuntu release (likely to be affected by
473 # this bug) should have lsb_release, if it isn't present we are likely
474 # on a different Linux distribution (should be fine).
475 execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -si
476 OUTPUT_VARIABLE LSB_DISTRIBUTOR_ID
477 OUTPUT_STRIP_TRAILING_WHITESPACE)
478
479 if (LSB_DISTRIBUTOR_ID MATCHES "Ubuntu" AND
480 SUITESPARSE_LIBRARIES MATCHES "/usr/lib/libamd")
481 # We are on Ubuntu, and the SuiteSparse version matches the broken
482 # system install version and is a system install.
483 set(SUITESPARSE_IS_BROKEN_SHARED_LINKING_UBUNTU_SYSTEM_VERSION TRUE)
484 message(STATUS "Found system install of SuiteSparse "
485 "${SUITESPARSE_VERSION} running on Ubuntu, which has a known bug "
486 "preventing linking of shared libraries (static linking unaffected).")
487 endif (LSB_DISTRIBUTOR_ID MATCHES "Ubuntu" AND
488 SUITESPARSE_LIBRARIES MATCHES "/usr/lib/libamd")
489 endif (LSB_RELEASE_EXECUTABLE)
490endif (CMAKE_SYSTEM_NAME MATCHES "Linux" AND
491 SUITESPARSE_VERSION VERSION_EQUAL 3.4.0)
492
493suitesparse_reset_find_library_prefix()
494
495# Handle REQUIRED and QUIET arguments to FIND_PACKAGE
496include(FindPackageHandleStandardArgs)
497if (SUITESPARSE_FOUND)
498 find_package_handle_standard_args(SuiteSparse
499 REQUIRED_VARS ${SUITESPARSE_FOUND_REQUIRED_VARS}
500 VERSION_VAR SUITESPARSE_VERSION
501 FAIL_MESSAGE "Failed to find some/all required components of SuiteSparse.")
502else (SUITESPARSE_FOUND)
503 # Do not pass VERSION_VAR to FindPackageHandleStandardArgs() if we failed to
504 # find SuiteSparse to avoid a confusing autogenerated failure message
505 # that states 'not found (missing: FOO) (found version: x.y.z)'.
506 find_package_handle_standard_args(SuiteSparse
507 REQUIRED_VARS ${SUITESPARSE_FOUND_REQUIRED_VARS}
508 FAIL_MESSAGE "Failed to find some/all required components of SuiteSparse.")
509endif (SUITESPARSE_FOUND)