FindSuiteSparse.cmake 5.07 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# - Try to find SUITESPARSE
# Once done this will define
#  
#  SUITESPARSE_FOUND            - system has SUITESPARSE
#  SUITESPARSE_INCLUDE_DIRS     - the SUITESPARSE include directory
#  SUITESPARSE_LIBRARIES        - Link these to use SUITESPARSE
#  SUITESPARSE_SPQR_LIBRARY     - name of spqr library (necessary due to error in debian package)
#  SUITESPARSE_SPQR_LIBRARY_DIR - name of spqr library (necessary due to error in debian package)
#  SUITESPARSE_LIBRARY_DIR      - Library main directory containing suitesparse libs
#  SUITESPARSE_LIBRARY_DIRS     - all Library directories containing suitesparse libs
#  SUITESPARSE_SPQR_VALID       - automatic identification whether or not spqr package is installed correctly

IF (SUITESPARSE_INCLUDE_DIRS)
  # Already in cache, be silent
  SET(SUITESPARSE_FIND_QUIETLY TRUE)
ENDIF (SUITESPARSE_INCLUDE_DIRS)

if( WIN32 )
   # Find cholmod part of the suitesparse library collection

   FIND_PATH( CHOLMOD_INCLUDE_DIR cholmod.h
              PATHS "C:\\libs\\win32\\SuiteSparse\\Include"  )

   # Add cholmod include directory to collection include directories
   IF ( CHOLMOD_INCLUDE_DIR )
	list ( APPEND SUITESPARSE_INCLUDE_DIRS ${CHOLMOD_INCLUDE_DIR} )
   ENDIF( CHOLMOD_INCLUDE_DIR )


   # find path suitesparse library
   FIND_PATH( SUITESPARSE_LIBRARY_DIRS 
	         amd.lib
               PATHS "C:\\libs\\win32\\SuiteSparse\\libs" )

   # if we found the library, add it to the defined libraries
   IF ( SUITESPARSE_LIBRARY_DIRS )
	list ( APPEND SUITESPARSE_LIBRARIES optimized;amd;optimized;camd;optimized;ccolamd;optimized;cholmod;optimized;colamd;optimized;metis;optimized;spqr;optimized;umfpack;debug;amdd;debug;camdd;debug;ccolamdd;debug;cholmodd;debug;spqrd;debug;umfpackd;debug;colamdd;debug;metisd;optimized;blas;optimized;libf2c;optimized;lapack;debug;blasd;debug;libf2cd;debug;lapackd )
   ENDIF( SUITESPARSE_LIBRARY_DIRS )  

else( WIN32 )
Pierre Kraemer's avatar
Pierre Kraemer committed
41
   IF(APPLE)
Pierre Kraemer's avatar
Pierre Kraemer committed
42
	   FIND_PATH( CHOLMOD_INCLUDE_DIR cholmod.h
Pierre Kraemer's avatar
Pierre Kraemer committed
43
44
        	      PATHS /opt/local/include/ufsparse
			    /usr/local/include )
Pierre Kraemer's avatar
Pierre Kraemer committed
45
46

           FIND_PATH( SUITESPARSE_LIBRARY_DIR
Pierre Kraemer's avatar
Pierre Kraemer committed
47
48
49
                      NAMES libcholmod.a
                      PATHS /opt/local/lib
			    /usr/local/lib )
Pierre Kraemer's avatar
Pierre Kraemer committed
50
51
52
53
54
55
56
57
58
59
60
   ELSE(APPLE)
	   FIND_PATH( CHOLMOD_INCLUDE_DIR cholmod.h
        	      PATHS /usr/local/include 
        	            /usr/include 
        	            /usr/include/suitesparse/ 
        	            ${CMAKE_SOURCE_DIR}/MacOS/Libs/cholmod
              	      PATH_SUFFIXES cholmod/ CHOLMOD/ )
   	
           FIND_PATH( SUITESPARSE_LIBRARY_DIR
                      NAMES libcholmod.so 
                      PATHS /usr/lib 
thery's avatar
thery committed
61
62
                            /usr/lib64
                            /usr/lib/x86_64-linux-gnu
Pierre Kraemer's avatar
Pierre Kraemer committed
63
64
65
66
67
68
69
70
71
72
73
                            /usr/local/lib )
   ENDIF(APPLE)

   # Add cholmod include directory to collection include directories
   IF ( CHOLMOD_INCLUDE_DIR )
	list ( APPEND SUITESPARSE_INCLUDE_DIRS ${CHOLMOD_INCLUDE_DIR} )
   ENDIF( CHOLMOD_INCLUDE_DIR )

   # if we found the library, add it to the defined libraries
   IF ( SUITESPARSE_LIBRARY_DIR )

Pierre Kraemer's avatar
Pierre Kraemer committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
       list ( APPEND SUITESPARSE_LIBRARIES amd)
       list ( APPEND SUITESPARSE_LIBRARIES btf)
       list ( APPEND SUITESPARSE_LIBRARIES camd)
       list ( APPEND SUITESPARSE_LIBRARIES ccolamd)
       list ( APPEND SUITESPARSE_LIBRARIES cholmod)
       list ( APPEND SUITESPARSE_LIBRARIES colamd)
 #     list ( APPEND SUITESPARSE_LIBRARIES csparse)
       list ( APPEND SUITESPARSE_LIBRARIES cxsparse)
       list ( APPEND SUITESPARSE_LIBRARIES klu)
 #     list ( APPEND SUITESPARSE_LIBRARIES spqr)
       list ( APPEND SUITESPARSE_LIBRARIES umfpack)

       IF (APPLE)
           list ( APPEND SUITESPARSE_LIBRARIES suitesparseconfig)
       ENDIF (APPLE)

Pierre Kraemer's avatar
Pierre Kraemer committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
       # Metis and spqr are optional
       FIND_LIBRARY( SUITESPARSE_METIS_LIBRARY
                     NAMES metis
                     PATHS ${SUITESPARSE_LIBRARY_DIR} )
       IF (SUITESPARSE_METIS_LIBRARY)			
	  list ( APPEND SUITESPARSE_LIBRARIES metis)
       ENDIF(SUITESPARSE_METIS_LIBRARY)

       if(EXISTS  "${CHOLMOD_INCLUDE_DIR}/SuiteSparseQR.hpp")
	  SET(SUITESPARSE_SPQR_VALID TRUE CACHE BOOL "SuiteSparseSPQR valid")
       else()
	  SET(SUITESPARSE_SPQR_VALID false CACHE BOOL "SuiteSparseSPQR valid")
       endif()

       if(SUITESPARSE_SPQR_VALID)
	  FIND_LIBRARY( SUITESPARSE_SPQR_LIBRARY
		      NAMES spqr
		      PATHS ${SUITESPARSE_LIBRARY_DIR} )
	  IF (SUITESPARSE_SPQR_LIBRARY)			
	    list ( APPEND SUITESPARSE_LIBRARIES spqr)
	  ENDIF (SUITESPARSE_SPQR_LIBRARY)
       endif()
       
    ENDIF( SUITESPARSE_LIBRARY_DIR )  
   
endif( WIN32 )


IF (SUITESPARSE_INCLUDE_DIRS AND SUITESPARSE_LIBRARIES)
   IF(WIN32)
    list (APPEND SUITESPARSE_INCLUDE_DIRS ${CHOLMOD_INCLUDE_DIR}/../../UFconfig )
   ENDIF(WIN32)
   SET(SUITESPARSE_FOUND TRUE)
Pierre Kraemer's avatar
Pierre Kraemer committed
123
   MESSAGE(STATUS "Found SuiteSparse")
Pierre Kraemer's avatar
Pierre Kraemer committed
124
125
ELSE (SUITESPARSE_INCLUDE_DIRS AND SUITESPARSE_LIBRARIES)
   SET( SUITESPARSE_FOUND FALSE )
Pierre Kraemer's avatar
Pierre Kraemer committed
126
   MESSAGE(FATAL_ERROR "Unable to find SuiteSparse")
Pierre Kraemer's avatar
Pierre Kraemer committed
127
ENDIF (SUITESPARSE_INCLUDE_DIRS AND SUITESPARSE_LIBRARIES)