Prefer SuiteSparse config-mode packages in Find modules

libeigen/eigen!2327
This commit is contained in:
Pavel Guzenfeld
2026-03-22 15:44:01 +00:00
committed by Rasmus Munk Larsen
parent f5774b014e
commit 835e5615a9
4 changed files with 86 additions and 7 deletions

View File

@@ -1,10 +1,32 @@
# CHOLMOD lib usually requires linking to a blas and lapack library. # CHOLMOD lib usually requires linking to a blas and lapack library.
# It is up to the user of this module to find a BLAS and link to it. # It is up to the user of this module to find a BLAS and link to it.
#
# This module first tries to find CHOLMOD via its CMake config-mode package
# (shipped with SuiteSparse >= 7.0). If that fails, it falls back to a
# manual header/library search for compatibility with older installations.
if (CHOLMOD_INCLUDES AND CHOLMOD_LIBRARIES) if (CHOLMOD_INCLUDES AND CHOLMOD_LIBRARIES)
set(CHOLMOD_FIND_QUIETLY TRUE) set(CHOLMOD_FIND_QUIETLY TRUE)
endif () endif ()
# --- Try config-mode first (SuiteSparse >= 7.0) ---
if(NOT CHOLMOD_INCLUDES OR NOT CHOLMOD_LIBRARIES)
find_package(CHOLMOD CONFIG QUIET)
if(CHOLMOD_FOUND AND TARGET SuiteSparse::CHOLMOD)
# Extract include dirs and libraries from the imported target so that the
# legacy variables expected by Eigen's build system are populated.
get_target_property(_cholmod_inc SuiteSparse::CHOLMOD INTERFACE_INCLUDE_DIRECTORIES)
if(_cholmod_inc)
set(CHOLMOD_INCLUDES "${_cholmod_inc}" CACHE PATH "CHOLMOD include directory")
endif()
set(CHOLMOD_LIBRARIES SuiteSparse::CHOLMOD CACHE STRING "CHOLMOD libraries")
# Mark as found and return early -- no need for the manual search below.
mark_as_advanced(CHOLMOD_INCLUDES CHOLMOD_LIBRARIES)
return()
endif()
endif()
# --- Fallback: manual search (SuiteSparse < 7.0 or no config package) ---
find_path(CHOLMOD_INCLUDES find_path(CHOLMOD_INCLUDES
NAMES NAMES
cholmod.h cholmod.h
@@ -79,7 +101,7 @@ if(CHOLMOD_LIBRARIES)
if (SUITESPARSE_LIBRARY) if (SUITESPARSE_LIBRARY)
set(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARIES} ${SUITESPARSE_LIBRARY}) set(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARIES} ${SUITESPARSE_LIBRARY})
endif () endif ()
endif() endif()
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)

View File

@@ -1,10 +1,29 @@
# KLU lib usually requires linking to a blas library. # KLU lib usually requires linking to a blas library.
# It is up to the user of this module to find a BLAS and link to it. # It is up to the user of this module to find a BLAS and link to it.
#
# This module first tries to find KLU via its CMake config-mode package
# (shipped with SuiteSparse >= 7.0). If that fails, it falls back to a
# manual header/library search for compatibility with older installations.
if (KLU_INCLUDES AND KLU_LIBRARIES) if (KLU_INCLUDES AND KLU_LIBRARIES)
set(KLU_FIND_QUIETLY TRUE) set(KLU_FIND_QUIETLY TRUE)
endif () endif ()
# --- Try config-mode first (SuiteSparse >= 7.0) ---
if(NOT KLU_INCLUDES OR NOT KLU_LIBRARIES)
find_package(KLU CONFIG QUIET)
if(KLU_FOUND AND TARGET SuiteSparse::KLU)
get_target_property(_klu_inc SuiteSparse::KLU INTERFACE_INCLUDE_DIRECTORIES)
if(_klu_inc)
set(KLU_INCLUDES "${_klu_inc}" CACHE PATH "KLU include directory")
endif()
set(KLU_LIBRARIES SuiteSparse::KLU CACHE STRING "KLU libraries")
mark_as_advanced(KLU_INCLUDES KLU_LIBRARIES)
return()
endif()
endif()
# --- Fallback: manual search (SuiteSparse < 7.0 or no config package) ---
find_path(KLU_INCLUDES find_path(KLU_INCLUDES
NAMES NAMES
klu.h klu.h
@@ -28,7 +47,7 @@ if(KLU_LIBRARIES)
if(COLAMD_LIBRARY) if(COLAMD_LIBRARY)
set(KLU_LIBRARIES ${KLU_LIBRARIES} ${COLAMD_LIBRARY}) set(KLU_LIBRARIES ${KLU_LIBRARIES} ${COLAMD_LIBRARY})
endif () endif ()
find_library(AMD_LIBRARY amd PATHS ${KLU_LIBDIR} $ENV{KLUDIR} ${LIB_INSTALL_DIR}) find_library(AMD_LIBRARY amd PATHS ${KLU_LIBDIR} $ENV{KLUDIR} ${LIB_INSTALL_DIR})
if(AMD_LIBRARY) if(AMD_LIBRARY)
set(KLU_LIBRARIES ${KLU_LIBRARIES} ${AMD_LIBRARY}) set(KLU_LIBRARIES ${KLU_LIBRARIES} ${AMD_LIBRARY})

View File

@@ -1,13 +1,32 @@
# SPQR lib usually requires linking to a blas and lapack library. # SPQR lib usually requires linking to a blas and lapack library.
# It is up to the user of this module to find a BLAS and link to it. # It is up to the user of this module to find a BLAS and link to it.
#
# SPQR lib requires Cholmod, colamd and amd as well. # SPQR lib requires Cholmod, colamd and amd as well.
# FindCholmod.cmake can be used to find those packages before finding spqr # FindCholmod.cmake can be used to find those packages before finding spqr
#
# This module first tries to find SPQR via its CMake config-mode package
# (shipped with SuiteSparse >= 7.0). If that fails, it falls back to a
# manual header/library search for compatibility with older installations.
if (SPQR_INCLUDES AND SPQR_LIBRARIES) if (SPQR_INCLUDES AND SPQR_LIBRARIES)
set(SPQR_FIND_QUIETLY TRUE) set(SPQR_FIND_QUIETLY TRUE)
endif () endif ()
# --- Try config-mode first (SuiteSparse >= 7.0) ---
if(NOT SPQR_INCLUDES OR NOT SPQR_LIBRARIES)
find_package(SPQR CONFIG QUIET)
if(SPQR_FOUND AND TARGET SuiteSparse::SPQR)
get_target_property(_spqr_inc SuiteSparse::SPQR INTERFACE_INCLUDE_DIRECTORIES)
if(_spqr_inc)
set(SPQR_INCLUDES "${_spqr_inc}" CACHE PATH "SPQR include directory")
endif()
set(SPQR_LIBRARIES SuiteSparse::SPQR CACHE STRING "SPQR libraries")
mark_as_advanced(SPQR_INCLUDES SPQR_LIBRARIES)
return()
endif()
endif()
# --- Fallback: manual search (SuiteSparse < 7.0 or no config package) ---
find_path(SPQR_INCLUDES find_path(SPQR_INCLUDES
NAMES NAMES
SuiteSparseQR.hpp SuiteSparseQR.hpp
@@ -32,10 +51,10 @@ if(SPQR_LIBRARIES)
if(CHOLMOD_LIBRARY) if(CHOLMOD_LIBRARY)
set(SPQR_LIBRARIES ${SPQR_LIBRARIES} ${CHOLMOD_LIBRARY}) set(SPQR_LIBRARIES ${SPQR_LIBRARIES} ${CHOLMOD_LIBRARY})
endif() endif()
endif() endif()
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SPQR DEFAULT_MSG SPQR_INCLUDES SPQR_LIBRARIES) find_package_handle_standard_args(SPQR DEFAULT_MSG SPQR_INCLUDES SPQR_LIBRARIES)
mark_as_advanced(SPQR_INCLUDES SPQR_LIBRARIES) mark_as_advanced(SPQR_INCLUDES SPQR_LIBRARIES)

View File

@@ -1,10 +1,29 @@
# Umfpack lib usually requires linking to a blas library. # Umfpack lib usually requires linking to a blas library.
# It is up to the user of this module to find a BLAS and link to it. # It is up to the user of this module to find a BLAS and link to it.
#
# This module first tries to find UMFPACK via its CMake config-mode package
# (shipped with SuiteSparse >= 7.0). If that fails, it falls back to a
# manual header/library search for compatibility with older installations.
if (UMFPACK_INCLUDES AND UMFPACK_LIBRARIES) if (UMFPACK_INCLUDES AND UMFPACK_LIBRARIES)
set(UMFPACK_FIND_QUIETLY TRUE) set(UMFPACK_FIND_QUIETLY TRUE)
endif () endif ()
# --- Try config-mode first (SuiteSparse >= 7.0) ---
if(NOT UMFPACK_INCLUDES OR NOT UMFPACK_LIBRARIES)
find_package(UMFPACK CONFIG QUIET)
if(UMFPACK_FOUND AND TARGET SuiteSparse::UMFPACK)
get_target_property(_umfpack_inc SuiteSparse::UMFPACK INTERFACE_INCLUDE_DIRECTORIES)
if(_umfpack_inc)
set(UMFPACK_INCLUDES "${_umfpack_inc}" CACHE PATH "UMFPACK include directory")
endif()
set(UMFPACK_LIBRARIES SuiteSparse::UMFPACK CACHE STRING "UMFPACK libraries")
mark_as_advanced(UMFPACK_INCLUDES UMFPACK_LIBRARIES)
return()
endif()
endif()
# --- Fallback: manual search (SuiteSparse < 7.0 or no config package) ---
find_path(UMFPACK_INCLUDES find_path(UMFPACK_INCLUDES
NAMES NAMES
umfpack.h umfpack.h
@@ -28,7 +47,7 @@ if(UMFPACK_LIBRARIES)
if(COLAMD_LIBRARY) if(COLAMD_LIBRARY)
set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES} ${COLAMD_LIBRARY}) set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES} ${COLAMD_LIBRARY})
endif () endif ()
find_library(AMD_LIBRARY amd PATHS ${UMFPACK_LIBDIR} $ENV{UMFPACKDIR} ${LIB_INSTALL_DIR}) find_library(AMD_LIBRARY amd PATHS ${UMFPACK_LIBDIR} $ENV{UMFPACKDIR} ${LIB_INSTALL_DIR})
if(AMD_LIBRARY) if(AMD_LIBRARY)
set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES} ${AMD_LIBRARY}) set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES} ${AMD_LIBRARY})