Skip to content

Commit 643759c

Browse files
authored
Use find_library to search for cholmod (#286)
Use find_library to search for cholmod. Newer versions of suitesparse provide a CHOLMODConfig.cmake, so we can try searching for it first before adding these new find modules to the CMake module path and searching with find_library / find_path. The CHOLMOD_ROOT environment variable can be used as a hint both for config-based searches and find-module based searches.
1 parent 9e5daa0 commit 643759c

File tree

3 files changed

+155
-1
lines changed

3 files changed

+155
-1
lines changed

library/src/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,14 @@ if(NOT USE_CUDA)
143143
list(APPEND static_depends PACKAGE rocsparse)
144144
endif()
145145

146-
target_link_libraries(hipsolver PRIVATE roc::rocsparse suitesparseconfig cholmod)
146+
find_package(CHOLMOD QUIET)
147+
if(NOT TARGET SuiteSparse::CHOLMOD)
148+
# try again with the custom find modules for older versions of suitesparse
149+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/suitesparse)
150+
find_package(CHOLMOD REQUIRED)
151+
endif()
152+
153+
target_link_libraries( hipsolver PRIVATE roc::rocsparse SuiteSparse::CHOLMOD)
147154
set_source_files_properties(${hipsolver_source}
148155
PROPERTIES
149156
COMPILE_DEFINITIONS HAVE_ROCSPARSE
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# ########################################################################
2+
# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell cop-
8+
# ies of the Software, and to permit persons to whom the Software is furnished
9+
# to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in all
12+
# copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM-
15+
# PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE-
19+
# CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
#
21+
# ########################################################################
22+
23+
#[=======================================================================[.rst:
24+
FindCHOLMOD
25+
----------
26+
27+
Find the SuiteSparse CHOLMOD library
28+
29+
Imported targets
30+
^^^^^^^^^^^^^^^^
31+
32+
This module defines the :prop_tgt:`IMPORTED` target if CHOLMOD is found:
33+
34+
``SuiteSparse::CHOLMOD``
35+
36+
Result Variables
37+
^^^^^^^^^^^^^^^^
38+
39+
This module defines the following variables:
40+
41+
``CHOLMOD_INCLUDE_DIR``
42+
``CHOLMOD_LIBRARY``
43+
``CHOLMOD_LIBRARIES``
44+
``CHOLMOD_FOUND``
45+
46+
#]=======================================================================]
47+
48+
find_path(CHOLMOD_INCLUDE_DIR suitesparse/cholmod.h)
49+
find_library(CHOLMOD_LIBRARY cholmod)
50+
51+
include(FindPackageHandleStandardArgs)
52+
find_package_handle_standard_args(CHOLMOD CHOLMOD_INCLUDE_DIR CHOLMOD_LIBRARY)
53+
54+
find_package(SuiteSparse_config QUIET)
55+
56+
if(CHOLMOD_FOUND)
57+
if(NOT DEFINED CHOLMOD_LIBRARIES)
58+
if(TARGET SuiteSparse::SuiteSparse_config)
59+
set(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARY} SuiteSparse::SuiteSparse_config)
60+
else()
61+
set(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARY})
62+
endif()
63+
endif()
64+
65+
if(NOT TARGET SuiteSparse::CHOLMOD)
66+
add_library(SuiteSparse::CHOLMOD UNKNOWN IMPORTED)
67+
68+
set_target_properties(SuiteSparse::CHOLMOD PROPERTIES
69+
IMPORTED_LOCATION "${CHOLMOD_LIBRARY}"
70+
INTERFACE_INCLUDE_DIRECTORIES "${CHOLMOD_INCLUDE_DIR}"
71+
)
72+
if(TARGET SuiteSparse::SuiteSparse_config)
73+
set_target_properties(SuiteSparse::CHOLMOD PROPERTIES
74+
INTERFACE_LINK_LIBRARIES SuiteSparse::SuiteSparse_config
75+
)
76+
endif()
77+
endif()
78+
endif()
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# ########################################################################
2+
# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell cop-
8+
# ies of the Software, and to permit persons to whom the Software is furnished
9+
# to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in all
12+
# copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM-
15+
# PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE-
19+
# CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
#
21+
# ########################################################################
22+
23+
#[=======================================================================[.rst:
24+
FindSuiteSparse_config
25+
----------
26+
27+
Find the SuiteSparse SuiteSparse_config library
28+
29+
Imported targets
30+
^^^^^^^^^^^^^^^^
31+
32+
This module defines the :prop_tgt:`IMPORTED` target if SuiteSparse_config is found:
33+
34+
``SuiteSparse::SuiteSparseConfig``
35+
36+
Result Variables
37+
^^^^^^^^^^^^^^^^
38+
39+
This module defines the following variables:
40+
41+
``SUITESPARSE_CONFIG_INCLUDE_DIR``
42+
``SUITESPARSE_CONFIG_LIBRARY``
43+
``SUITESPARSE_CONFIG_LIBRARIES``
44+
``SUITESPARSE_CONFIG_FOUND``
45+
46+
#]=======================================================================]
47+
48+
find_path(SUITESPARSE_CONFIG_INCLUDE_DIR suitesparse/SuiteSparse_config.h)
49+
find_library(SUITESPARSE_CONFIG_LIBRARY suitesparseconfig)
50+
51+
include(FindPackageHandleStandardArgs)
52+
find_package_handle_standard_args(SuiteSparse_config SUITESPARSE_CONFIG_INCLUDE_DIR SUITESPARSE_CONFIG_LIBRARY)
53+
54+
if(SUITESPARSE_CONFIG_FOUND)
55+
if(NOT DEFINED SUITESPARSE_CONFIG_LIBRARIES)
56+
set(SUITESPARSE_CONFIG_LIBRARIES ${SUITESPARSE_CONFIG_LIBRARY})
57+
endif()
58+
59+
if(NOT TARGET SuiteSparse::SuiteSparseConfig)
60+
add_library(SuiteSparse::SuiteSparseConfig UNKNOWN IMPORTED)
61+
62+
set_target_properties(SuiteSparse::SuiteSparseConfig PROPERTIES
63+
IMPORTED_LOCATION "${SUITESPARSE_CONFIG_LIBRARY}"
64+
)
65+
set_target_properties(SuiteSparse::SuiteSparseConfig PROPERTIES
66+
INTERFACE_INCLUDE_DIRECTORIES "${SUITESPARSE_CONFIG_INCLUDE_DIR}"
67+
)
68+
endif()
69+
endif()

0 commit comments

Comments
 (0)