Debian Codegraph @

cmake/FindCHOLMOD.cmake

raw
1 # Copyright (c), ETH Zurich and UNC Chapel Hill.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 #
14 # * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of
15 # its contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29
30
31 # Find package module for CHOLMOD library.
32 #
33 # The following variables are set by this module:
34 #
35 # CHOLMOD_FOUND: TRUE if CHOLMOD is found.
36 # CHOLMOD::CHOLMOD: Imported target to link against.
37 #
38 # The following variables control the behavior of this module:
39 #
40 # CHOLMOD_INCLUDE_DIR_HINTS: List of additional directories in which to
41 # search for CHOLMOD includes.
42 # CHOLMOD_LIBRARY_DIR_HINTS: List of additional directories in which to
43 # search for CHOLMOD libraries.
44
45 set(CHOLMOD_INCLUDE_DIR_HINTS "" CACHE PATH "CHOLMOD include directory")
46 set(CHOLMOD_LIBRARY_DIR_HINTS "" CACHE PATH "CHOLMOD library directory")
47
48 unset(CHOLMOD_FOUND)
49 unset(CHOLMOD_INCLUDE_DIRS)
50 unset(CHOLMOD_LIBRARIES)
51
52 find_package(CHOLMOD CONFIG QUIET)
53 if(TARGET CHOLMOD::CHOLMOD)
54 set(CHOLMOD_FOUND TRUE)
55 message(STATUS "Found CHOLMOD")
56 message(STATUS " Target : CHOLMOD::CHOLMOD")
57 else()
58 list(APPEND CHOLMOD_INCLUDE_SEARCH_PATHS
59 ${CHOLMOD_INCLUDE_DIR_HINTS}
60 /usr/include
61 /usr/local/include
62 /sw/include
63 /opt/include
64 /opt/local/include)
65
66 # Some distros don't package suitesparse under a /suitesparse subdirectory (e.g. NixOS).
67 # Search for both layouts separately so that the suitesparse/ subdirectory
68 # layout is reliably preferred across all search paths. A single find_path
69 # call with both names would iterate search paths first and names second,
70 # which could pick up a bare cholmod.h from an earlier path over
71 # suitesparse/cholmod.h from a later one.
72 find_path(CHOLMOD_INCLUDE_DIRS
73 NAMES suitesparse/cholmod.h
74 PATHS ${CHOLMOD_INCLUDE_SEARCH_PATHS})
75 if(NOT CHOLMOD_INCLUDE_DIRS)
76 unset(CHOLMOD_INCLUDE_DIRS CACHE)
77 find_path(CHOLMOD_INCLUDE_DIRS
78 NAMES cholmod.h
79 PATHS ${CHOLMOD_INCLUDE_SEARCH_PATHS})
80 endif()
81
82 find_library(CHOLMOD_LIBRARIES
83 NAMES
84 cholmod
85 PATHS
86 ${CHOLMOD_LIBRARY_DIR_HINTS}
87 /usr/lib64
88 /usr/lib
89 /usr/local/lib64
90 /usr/local/lib
91 /sw/lib
92 /opt/lib
93 /opt/local/lib)
94
95 if(CHOLMOD_INCLUDE_DIRS AND CHOLMOD_LIBRARIES)
96 set(CHOLMOD_FOUND TRUE)
97 message(STATUS "Found CHOLMOD")
98 message(STATUS " Includes : ${CHOLMOD_INCLUDE_DIRS}")
99 message(STATUS " Libraries : ${CHOLMOD_LIBRARIES}")
100 else()
101 set(CHOLMOD_FOUND FALSE)
102 endif()
103
104 if(EXISTS "${CHOLMOD_INCLUDE_DIRS}/suitesparse/cholmod.h")
105 set(CHOLMOD_INTERFACE_INCLUDE_DIRS "${CHOLMOD_INCLUDE_DIRS}/suitesparse")
106 else()
107 set(CHOLMOD_INTERFACE_INCLUDE_DIRS "${CHOLMOD_INCLUDE_DIRS}")
108 endif()
109
110 add_library(CHOLMOD::CHOLMOD INTERFACE IMPORTED)
111 target_include_directories(
112 CHOLMOD::CHOLMOD INTERFACE ${CHOLMOD_INTERFACE_INCLUDE_DIRS})
113 target_link_libraries(
114 CHOLMOD::CHOLMOD INTERFACE ${CHOLMOD_LIBRARIES})
115 endif()
116
117 if(NOT CHOLMOD_FOUND AND CHOLMOD_FIND_REQUIRED)
118 message(FATAL_ERROR "Could not find CHOLMOD")
119 endif()