Debian Codegraph @

cmake_modules/FindSuiteSparse.cmake

raw
1 # Ceres Solver - A fast non-linear least squares minimizer
2 # Copyright 2022 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 #[=======================================================================[.rst:
33 FindSuiteSparse
34 ===============
35
36 Module for locating SuiteSparse libraries and its dependencies.
37
38 This module defines the following variables:
39
40 ``SuiteSparse_FOUND``
41 ``TRUE`` iff SuiteSparse and all dependencies have been found.
42
43 ``SuiteSparse_VERSION``
44 Extracted from ``SuiteSparse_config.h`` (>= v4).
45
46 ``SuiteSparse_VERSION_MAJOR``
47 Equal to 4 if ``SuiteSparse_VERSION`` = 4.2.1
48
49 ``SuiteSparse_VERSION_MINOR``
50 Equal to 2 if ``SuiteSparse_VERSION`` = 4.2.1
51
52 ``SuiteSparse_VERSION_PATCH``
53 Equal to 1 if ``SuiteSparse_VERSION`` = 4.2.1
54
55 The following variables control the behaviour of this module:
56
57 ``SuiteSparse_NO_CMAKE``
58 Do not attempt to use the native SuiteSparse CMake package configuration.
59
60
61 Targets
62 -------
63
64 The following targets define the SuiteSparse components searched for.
65
66 ``SuiteSparse::AMD``
67 Symmetric Approximate Minimum Degree (AMD)
68
69 ``SuiteSparse::CAMD``
70 Constrained Approximate Minimum Degree (CAMD)
71
72 ``SuiteSparse::COLAMD``
73 Column Approximate Minimum Degree (COLAMD)
74
75 ``SuiteSparse::CCOLAMD``
76 Constrained Column Approximate Minimum Degree (CCOLAMD)
77
78 ``SuiteSparse::CHOLMOD``
79 Sparse Supernodal Cholesky Factorization and Update/Downdate (CHOLMOD)
80
81 ``SuiteSparse::Partition``
82 CHOLMOD with METIS support
83
84 ``SuiteSparse::SPQR``
85 Multifrontal Sparse QR (SuiteSparseQR)
86
87 ``SuiteSparse::Config``
88 Common configuration for all but CSparse (SuiteSparse version >= 4).
89
90 Optional SuiteSparse dependencies:
91
92 ``METIS::METIS``
93 Serial Graph Partitioning and Fill-reducing Matrix Ordering (METIS)
94 ]=======================================================================]
95
96 if (NOT SuiteSparse_NO_CMAKE)
97 find_package (SuiteSparse NO_MODULE QUIET)
98 endif (NOT SuiteSparse_NO_CMAKE)
99
100 if (SuiteSparse_FOUND)
101 return ()
102 endif (SuiteSparse_FOUND)
103
104 # Push CMP0057 to enable support for IN_LIST, when cmake_minimum_required is
105 # set to <3.3.
106 cmake_policy (PUSH)
107 cmake_policy (SET CMP0057 NEW)
108
109 if (NOT SuiteSparse_FIND_COMPONENTS)
110 set (SuiteSparse_FIND_COMPONENTS
111 AMD
112 CAMD
113 CCOLAMD
114 CHOLMOD
115 COLAMD
116 SPQR
117 )
118
119 foreach (component IN LISTS SuiteSparse_FIND_COMPONENTS)
120 set (SuiteSparse_FIND_REQUIRED_${component} TRUE)
121 endforeach (component IN LISTS SuiteSparse_FIND_COMPONENTS)
122 endif (NOT SuiteSparse_FIND_COMPONENTS)
123
124 # Assume SuiteSparse was found and set it to false only if third-party
125 # dependencies could not be located. SuiteSparse components are handled by
126 # FindPackageHandleStandardArgs HANDLE_COMPONENTS option.
127 set (SuiteSparse_FOUND TRUE)
128
129 include (CheckLibraryExists)
130 include (CheckSymbolExists)
131 include (CMakePushCheckState)
132
133 # Config is a base component and thus always required
134 set (SuiteSparse_IMPLICIT_COMPONENTS Config)
135
136 # CHOLMOD depends on AMD, CAMD, CCOLAMD, and COLAMD.
137 if (CHOLMOD IN_LIST SuiteSparse_FIND_COMPONENTS)
138 list (APPEND SuiteSparse_IMPLICIT_COMPONENTS AMD CAMD CCOLAMD COLAMD)
139 endif (CHOLMOD IN_LIST SuiteSparse_FIND_COMPONENTS)
140
141 # SPQR depends on CHOLMOD.
142 if (SPQR IN_LIST SuiteSparse_FIND_COMPONENTS)
143 list (APPEND SuiteSparse_IMPLICIT_COMPONENTS CHOLMOD)
144 endif (SPQR IN_LIST SuiteSparse_FIND_COMPONENTS)
145
146 # Implicit components are always required
147 foreach (component IN LISTS SuiteSparse_IMPLICIT_COMPONENTS)
148 set (SuiteSparse_FIND_REQUIRED_${component} TRUE)
149 endforeach (component IN LISTS SuiteSparse_IMPLICIT_COMPONENTS)
150
151 list (APPEND SuiteSparse_FIND_COMPONENTS ${SuiteSparse_IMPLICIT_COMPONENTS})
152
153 # Do not list components multiple times.
154 list (REMOVE_DUPLICATES SuiteSparse_FIND_COMPONENTS)
155
156 # Reset CALLERS_CMAKE_FIND_LIBRARY_PREFIXES to its value when
157 # FindSuiteSparse was invoked.
158 macro(SuiteSparse_RESET_FIND_LIBRARY_PREFIX)
159 if (MSVC)
160 set(CMAKE_FIND_LIBRARY_PREFIXES "${CALLERS_CMAKE_FIND_LIBRARY_PREFIXES}")
161 endif (MSVC)
162 endmacro(SuiteSparse_RESET_FIND_LIBRARY_PREFIX)
163
164 # Called if we failed to find SuiteSparse or any of it's required dependencies,
165 # unsets all public (designed to be used externally) variables and reports
166 # error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument.
167 macro(SuiteSparse_REPORT_NOT_FOUND REASON_MSG)
168 # Will be set to FALSE by find_package_handle_standard_args
169 unset (SuiteSparse_FOUND)
170
171 # Do NOT unset SuiteSparse_REQUIRED_VARS here, as it is used by
172 # FindPackageHandleStandardArgs() to generate the automatic error message on
173 # failure which highlights which components are missing.
174
175 suitesparse_reset_find_library_prefix()
176
177 # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage()
178 # use the camelcase library name, not uppercase.
179 if (SuiteSparse_FIND_QUIETLY)
180 message(STATUS "Failed to find SuiteSparse - " ${REASON_MSG} ${ARGN})
181 elseif (SuiteSparse_FIND_REQUIRED)
182 message(FATAL_ERROR "Failed to find SuiteSparse - " ${REASON_MSG} ${ARGN})
183 else()
184 # Neither QUIETLY nor REQUIRED, use no priority which emits a message
185 # but continues configuration and allows generation.
186 message("-- Failed to find SuiteSparse - " ${REASON_MSG} ${ARGN})
187 endif (SuiteSparse_FIND_QUIETLY)
188
189 # Do not call return(), s/t we keep processing if not called with REQUIRED
190 # and report all missing components, rather than bailing after failing to find
191 # the first.
192 endmacro(SuiteSparse_REPORT_NOT_FOUND)
193
194 # Handle possible presence of lib prefix for libraries on MSVC, see
195 # also SuiteSparse_RESET_FIND_LIBRARY_PREFIX().
196 if (MSVC)
197 # Preserve the caller's original values for CMAKE_FIND_LIBRARY_PREFIXES
198 # s/t we can set it back before returning.
199 set(CALLERS_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
200 # The empty string in this list is important, it represents the case when
201 # the libraries have no prefix (shared libraries / DLLs).
202 set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "" "${CMAKE_FIND_LIBRARY_PREFIXES}")
203 endif (MSVC)
204
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 macro(suitesparse_find_component COMPONENT)
214 include(CMakeParseArguments)
215 set(MULTI_VALUE_ARGS FILES LIBRARIES)
216 cmake_parse_arguments(SuiteSparse_FIND_COMPONENT_${COMPONENT}
217 "" "" "${MULTI_VALUE_ARGS}" ${ARGN})
218
219 set(SuiteSparse_${COMPONENT}_FOUND TRUE)
220 if (SuiteSparse_FIND_COMPONENT_${COMPONENT}_FILES)
221 find_path(SuiteSparse_${COMPONENT}_INCLUDE_DIR
222 NAMES ${SuiteSparse_FIND_COMPONENT_${COMPONENT}_FILES}
223 PATH_SUFFIXES ${SuiteSparse_CHECK_PATH_SUFFIXES})
224 if (SuiteSparse_${COMPONENT}_INCLUDE_DIR)
225 message(STATUS "Found ${COMPONENT} headers in: "
226 "${SuiteSparse_${COMPONENT}_INCLUDE_DIR}")
227 mark_as_advanced(SuiteSparse_${COMPONENT}_INCLUDE_DIR)
228 else()
229 # Specified headers not found.
230 set(SuiteSparse_${COMPONENT}_FOUND FALSE)
231 if (SuiteSparse_FIND_REQUIRED_${COMPONENT})
232 suitesparse_report_not_found(
233 "Did not find ${COMPONENT} header (required SuiteSparse component).")
234 else()
235 message(STATUS "Did not find ${COMPONENT} header (optional "
236 "SuiteSparse component).")
237 # Hide optional vars from CMake GUI even if not found.
238 mark_as_advanced(SuiteSparse_${COMPONENT}_INCLUDE_DIR)
239 endif()
240 endif()
241 endif()
242
243 if (SuiteSparse_FIND_COMPONENT_${COMPONENT}_LIBRARIES)
244 find_library(SuiteSparse_${COMPONENT}_LIBRARY
245 NAMES ${SuiteSparse_FIND_COMPONENT_${COMPONENT}_LIBRARIES}
246 PATH_SUFFIXES ${SuiteSparse_CHECK_PATH_SUFFIXES})
247 if (SuiteSparse_${COMPONENT}_LIBRARY)
248 message(STATUS "Found ${COMPONENT} library: ${SuiteSparse_${COMPONENT}_LIBRARY}")
249 mark_as_advanced(SuiteSparse_${COMPONENT}_LIBRARY)
250 else ()
251 # Specified libraries not found.
252 set(SuiteSparse_${COMPONENT}_FOUND FALSE)
253 if (SuiteSparse_FIND_REQUIRED_${COMPONENT})
254 suitesparse_report_not_found(
255 "Did not find ${COMPONENT} library (required SuiteSparse component).")
256 else()
257 message(STATUS "Did not find ${COMPONENT} library (optional SuiteSparse "
258 "dependency)")
259 # Hide optional vars from CMake GUI even if not found.
260 mark_as_advanced(SuiteSparse_${COMPONENT}_LIBRARY)
261 endif()
262 endif()
263 endif()
264
265 # A component can be optional (given to OPTIONAL_COMPONENTS). However, if the
266 # component is implicit (must be always present, such as the Config component)
267 # assume it be required as well.
268 if (SuiteSparse_FIND_REQUIRED_${COMPONENT})
269 list (APPEND SuiteSparse_REQUIRED_VARS SuiteSparse_${COMPONENT}_INCLUDE_DIR)
270 list (APPEND SuiteSparse_REQUIRED_VARS SuiteSparse_${COMPONENT}_LIBRARY)
271 endif (SuiteSparse_FIND_REQUIRED_${COMPONENT})
272
273 # Define the target only if the include directory and the library were found
274 if (SuiteSparse_${COMPONENT}_INCLUDE_DIR AND SuiteSparse_${COMPONENT}_LIBRARY)
275 if (NOT TARGET SuiteSparse::${COMPONENT})
276 add_library(SuiteSparse::${COMPONENT} IMPORTED UNKNOWN)
277 endif (NOT TARGET SuiteSparse::${COMPONENT})
278
279 set_property(TARGET SuiteSparse::${COMPONENT} PROPERTY
280 INTERFACE_INCLUDE_DIRECTORIES ${SuiteSparse_${COMPONENT}_INCLUDE_DIR})
281 set_property(TARGET SuiteSparse::${COMPONENT} PROPERTY
282 IMPORTED_LOCATION ${SuiteSparse_${COMPONENT}_LIBRARY})
283 endif (SuiteSparse_${COMPONENT}_INCLUDE_DIR AND SuiteSparse_${COMPONENT}_LIBRARY)
284 endmacro()
285
286 # Given the number of components of SuiteSparse, and to ensure that the
287 # automatic failure message generated by FindPackageHandleStandardArgs()
288 # when not all required components are found is helpful, we maintain a list
289 # of all variables that must be defined for SuiteSparse to be considered found.
290 unset(SuiteSparse_REQUIRED_VARS)
291
292 # BLAS.
293 find_package(BLAS QUIET)
294 if (NOT BLAS_FOUND)
295 suitesparse_report_not_found(
296 "Did not find BLAS library (required for SuiteSparse).")
297 endif (NOT BLAS_FOUND)
298
299 # LAPACK.
300 find_package(LAPACK QUIET)
301 if (NOT LAPACK_FOUND)
302 suitesparse_report_not_found(
303 "Did not find LAPACK library (required for SuiteSparse).")
304 endif (NOT LAPACK_FOUND)
305
306 foreach (component IN LISTS SuiteSparse_FIND_COMPONENTS)
307 if (component STREQUAL Partition)
308 # Partition is a meta component that neither provides additional headers nor
309 # a separate library. It is strictly part of CHOLMOD.
310 continue ()
311 endif (component STREQUAL Partition)
312 string (TOLOWER ${component} component_library)
313
314 if (component STREQUAL "Config")
315 set (component_header SuiteSparse_config.h)
316 set (component_library suitesparseconfig)
317 elseif (component STREQUAL "SPQR")
318 set (component_header SuiteSparseQR.hpp)
319 else (component STREQUAL "SPQR")
320 set (component_header ${component_library}.h)
321 endif (component STREQUAL "Config")
322
323 suitesparse_find_component(${component}
324 FILES ${component_header}
325 LIBRARIES ${component_library})
326 endforeach (component IN LISTS SuiteSparse_FIND_COMPONENTS)
327
328 if (TARGET SuiteSparse::SPQR)
329 # SuiteSparseQR may be compiled with Intel Threading Building Blocks,
330 # we assume that if TBB is installed, SuiteSparseQR was compiled with
331 # support for it, this will do no harm if it wasn't.
332 find_package(TBB QUIET)
333 if (TBB_FOUND)
334 message(STATUS "Found Intel Thread Building Blocks (TBB) library "
335 "(${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR} / ${TBB_INTERFACE_VERSION}) "
336 "include location: ${TBB_INCLUDE_DIRS}. Assuming SuiteSparseQR was "
337 "compiled with TBB.")
338 # Add the TBB libraries to the SuiteSparseQR libraries (the only
339 # libraries to optionally depend on TBB).
340 if (TARGET TBB::tbb)
341 # Native TBB package configuration provides an imported target. Use it if
342 # available.
343 set_property (TARGET SuiteSparse::SPQR APPEND PROPERTY
344 INTERFACE_LINK_LIBRARIES TBB::tbb)
345 else (TARGET TBB::tbb)
346 set_property (TARGET SuiteSparse::SPQR APPEND PROPERTY
347 INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS})
348 set_property (TARGET SuiteSparse::SPQR APPEND PROPERTY
349 INTERFACE_LINK_LIBRARIES ${TBB_LIBRARIES})
350 endif (TARGET TBB::tbb)
351 else (TBB_FOUND)
352 message(STATUS "Did not find Intel TBB library, assuming SuiteSparseQR was "
353 "not compiled with TBB.")
354 endif (TBB_FOUND)
355 endif (TARGET SuiteSparse::SPQR)
356
357 check_library_exists(rt shm_open "" HAVE_LIBRT)
358
359 if (TARGET SuiteSparse::Config)
360 # SuiteSparse_config (SuiteSparse version >= 4) requires librt library for
361 # timing by default when compiled on Linux or Unix, but not on OSX (which
362 # does not have librt).
363 if (HAVE_LIBRT)
364 message(STATUS "Adding librt to "
365 "SuiteSparse_config libraries (required on Linux & Unix [not OSX] if "
366 "SuiteSparse is compiled with timing).")
367 set_property (TARGET SuiteSparse::Config APPEND PROPERTY
368 INTERFACE_LINK_LIBRARIES $<LINK_ONLY:rt>)
369 else (HAVE_LIBRT)
370 message(STATUS "Could not find librt, but found SuiteSparse_config, "
371 "assuming that SuiteSparse was compiled without timing.")
372 endif (HAVE_LIBRT)
373
374 # Add BLAS and LAPACK as dependencies of SuiteSparse::Config for convenience
375 # given that all components depend on it.
376 if (BLAS_FOUND)
377 if (TARGET BLAS::BLAS)
378 set_property (TARGET SuiteSparse::Config APPEND PROPERTY
379 INTERFACE_LINK_LIBRARIES $<LINK_ONLY:BLAS::BLAS>)
380 else (TARGET BLAS::BLAS)
381 set_property (TARGET SuiteSparse::Config APPEND PROPERTY
382 INTERFACE_LINK_LIBRARIES ${BLAS_LIBRARIES})
383 endif (TARGET BLAS::BLAS)
384 endif (BLAS_FOUND)
385
386 if (LAPACK_FOUND)
387 if (TARGET LAPACK::LAPACK)
388 set_property (TARGET SuiteSparse::Config APPEND PROPERTY
389 INTERFACE_LINK_LIBRARIES $<LINK_ONLY:LAPACK::LAPACK>)
390 else (TARGET LAPACK::LAPACK)
391 set_property (TARGET SuiteSparse::Config APPEND PROPERTY
392 INTERFACE_LINK_LIBRARIES ${LAPACK_LIBRARIES})
393 endif (TARGET LAPACK::LAPACK)
394 endif (LAPACK_FOUND)
395
396 # SuiteSparse version >= 4.
397 set(SuiteSparse_VERSION_FILE
398 ${SuiteSparse_Config_INCLUDE_DIR}/SuiteSparse_config.h)
399 if (NOT EXISTS ${SuiteSparse_VERSION_FILE})
400 suitesparse_report_not_found(
401 "Could not find file: ${SuiteSparse_VERSION_FILE} containing version "
402 "information for >= v4 SuiteSparse installs, but SuiteSparse_config was "
403 "found (only present in >= v4 installs).")
404 else (NOT EXISTS ${SuiteSparse_VERSION_FILE})
405 file(READ ${SuiteSparse_VERSION_FILE} Config_CONTENTS)
406
407 string(REGEX MATCH "#define SUITESPARSE_MAIN_VERSION[ \t]+([0-9]+)"
408 SuiteSparse_VERSION_LINE "${Config_CONTENTS}")
409 set (SuiteSparse_VERSION_MAJOR ${CMAKE_MATCH_1})
410
411 string(REGEX MATCH "#define SUITESPARSE_SUB_VERSION[ \t]+([0-9]+)"
412 SuiteSparse_VERSION_LINE "${Config_CONTENTS}")
413 set (SuiteSparse_VERSION_MINOR ${CMAKE_MATCH_1})
414
415 string(REGEX MATCH "#define SUITESPARSE_SUBSUB_VERSION[ \t]+([0-9]+)"
416 SuiteSparse_VERSION_LINE "${Config_CONTENTS}")
417 set (SuiteSparse_VERSION_PATCH ${CMAKE_MATCH_1})
418
419 unset (SuiteSparse_VERSION_LINE)
420
421 # This is on a single line s/t CMake does not interpret it as a list of
422 # elements and insert ';' separators which would result in 4.;2.;1 nonsense.
423 set(SuiteSparse_VERSION
424 "${SuiteSparse_VERSION_MAJOR}.${SuiteSparse_VERSION_MINOR}.${SuiteSparse_VERSION_PATCH}")
425
426 if (SuiteSparse_VERSION MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
427 set(SuiteSparse_VERSION_COMPONENTS 3)
428 else (SuiteSparse_VERSION MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
429 message (WARNING "Could not parse SuiteSparse_config.h: SuiteSparse "
430 "version will not be available")
431
432 unset (SuiteSparse_VERSION)
433 unset (SuiteSparse_VERSION_MAJOR)
434 unset (SuiteSparse_VERSION_MINOR)
435 unset (SuiteSparse_VERSION_PATCH)
436 endif (SuiteSparse_VERSION MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
437 endif (NOT EXISTS ${SuiteSparse_VERSION_FILE})
438 endif (TARGET SuiteSparse::Config)
439
440 # CHOLMOD requires AMD CAMD CCOLAMD COLAMD
441 if (TARGET SuiteSparse::CHOLMOD)
442 foreach (component IN ITEMS AMD CAMD CCOLAMD COLAMD)
443 if (TARGET SuiteSparse::${component})
444 set_property (TARGET SuiteSparse::CHOLMOD APPEND PROPERTY
445 INTERFACE_LINK_LIBRARIES SuiteSparse::${component})
446 else (TARGET SuiteSparse::${component})
447 # Consider CHOLMOD not found if COLAMD cannot be found
448 set (SuiteSparse_CHOLMOD_FOUND FALSE)
449 endif (TARGET SuiteSparse::${component})
450 endforeach (component IN ITEMS AMD CAMD CCOLAMD COLAMD)
451 endif (TARGET SuiteSparse::CHOLMOD)
452
453 # SPQR requires CHOLMOD
454 if (TARGET SuiteSparse::SPQR)
455 if (TARGET SuiteSparse::CHOLMOD)
456 set_property (TARGET SuiteSparse::SPQR APPEND PROPERTY
457 INTERFACE_LINK_LIBRARIES SuiteSparse::CHOLMOD)
458 else (TARGET SuiteSparse::CHOLMOD)
459 # Consider SPQR not found if CHOLMOD cannot be found
460 set (SuiteSparse_SQPR_FOUND FALSE)
461 endif (TARGET SuiteSparse::CHOLMOD)
462 endif (TARGET SuiteSparse::SPQR)
463
464 # Add SuiteSparse::Config as dependency to all components
465 if (TARGET SuiteSparse::Config)
466 foreach (component IN LISTS SuiteSparse_FIND_COMPONENTS)
467 if (component STREQUAL Config)
468 continue ()
469 endif (component STREQUAL Config)
470
471 if (TARGET SuiteSparse::${component})
472 set_property (TARGET SuiteSparse::${component} APPEND PROPERTY
473 INTERFACE_LINK_LIBRARIES SuiteSparse::Config)
474 endif (TARGET SuiteSparse::${component})
475 endforeach (component IN LISTS SuiteSparse_FIND_COMPONENTS)
476 endif (TARGET SuiteSparse::Config)
477
478 # Check whether CHOLMOD was compiled with METIS support. The check can be
479 # performed only after the main components have been set up.
480 if (TARGET SuiteSparse::CHOLMOD)
481 # NOTE If SuiteSparse was compiled as a static library we'll need to link
482 # against METIS already during the check. Otherwise, the check can fail due to
483 # undefined references even though SuiteSparse was compiled with METIS.
484 find_package (METIS)
485
486 if (TARGET METIS::METIS)
487 cmake_push_check_state (RESET)
488 set (CMAKE_REQUIRED_LIBRARIES SuiteSparse::CHOLMOD METIS::METIS)
489 check_symbol_exists (cholmod_metis cholmod.h SuiteSparse_CHOLMOD_USES_METIS)
490 cmake_pop_check_state ()
491
492 if (SuiteSparse_CHOLMOD_USES_METIS)
493 set_property (TARGET SuiteSparse::CHOLMOD APPEND PROPERTY
494 INTERFACE_LINK_LIBRARIES $<LINK_ONLY:METIS::METIS>)
495
496 # Provide the SuiteSparse::Partition component whose availability indicates
497 # that CHOLMOD was compiled with the Partition module.
498 if (NOT TARGET SuiteSparse::Partition)
499 add_library (SuiteSparse::Partition IMPORTED INTERFACE)
500 endif (NOT TARGET SuiteSparse::Partition)
501
502 set_property (TARGET SuiteSparse::Partition APPEND PROPERTY
503 INTERFACE_LINK_LIBRARIES SuiteSparse::CHOLMOD)
504 endif (SuiteSparse_CHOLMOD_USES_METIS)
505 endif (TARGET METIS::METIS)
506 endif (TARGET SuiteSparse::CHOLMOD)
507
508 # We do not use suitesparse_find_component to find Partition and therefore must
509 # handle the availability in an extra step.
510 if (TARGET SuiteSparse::Partition)
511 set (SuiteSparse_Partition_FOUND TRUE)
512 else (TARGET SuiteSparse::Partition)
513 set (SuiteSparse_Partition_FOUND FALSE)
514 endif (TARGET SuiteSparse::Partition)
515
516 suitesparse_reset_find_library_prefix()
517
518 # Handle REQUIRED and QUIET arguments to FIND_PACKAGE
519 include(FindPackageHandleStandardArgs)
520 if (SuiteSparse_FOUND)
521 find_package_handle_standard_args(SuiteSparse
522 REQUIRED_VARS ${SuiteSparse_REQUIRED_VARS}
523 VERSION_VAR SuiteSparse_VERSION
524 FAIL_MESSAGE "Failed to find some/all required components of SuiteSparse."
525 HANDLE_COMPONENTS)
526 else (SuiteSparse_FOUND)
527 # Do not pass VERSION_VAR to FindPackageHandleStandardArgs() if we failed to
528 # find SuiteSparse to avoid a confusing autogenerated failure message
529 # that states 'not found (missing: FOO) (found version: x.y.z)'.
530 find_package_handle_standard_args(SuiteSparse
531 REQUIRED_VARS ${SuiteSparse_REQUIRED_VARS}
532 FAIL_MESSAGE "Failed to find some/all required components of SuiteSparse."
533 HANDLE_COMPONENTS)
534 endif (SuiteSparse_FOUND)
535
536 # Pop CMP0057.
537 cmake_policy (POP)