FindSUITESPARSE.cmake 8.69 KB
Newer Older
1
2
3
# - Try to find SUITESPARSE
# Once done this will define
#  
4
5
6
7
8
9
10
#  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
David Bommes's avatar
changed    
David Bommes committed
11
#  SUITESPARSE_SPQR_VALID       - automatic identification whether or not spqr package is installed correctly
12

13
if (SUITESPARSE_INCLUDE_DIRS)
14
15
  # Already in cache, be silent
  SET(SUITESPARSE_FIND_QUIETLY TRUE)
16
endif (SUITESPARSE_INCLUDE_DIRS)
17
18

if( WIN32 )
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  # Find cholmod part of the suitesparse library collection

  # Check if the base path is set
  if ( NOT CMAKE_WINDOWS_LIBS_DIR )
    # This is the base directory for windows library search used in the finders we shipp.
    set(CMAKE_WINDOWS_LIBS_DIR "c:/libs" CACHE STRING "Default Library search dir on windows." )
  endif()

  if ( CMAKE_GENERATOR MATCHES "^Visual Studio 11.*Win64" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2012/x64/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 11.*" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2012/x32/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 12.*Win64" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2013/x64/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 12.*" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2013/x32/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 14.*Win64" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2015/x64/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 14.*" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2015/x32/")
  endif()


  FIND_PATH( CHOLMOD_INCLUDE_DIR cholmod.h
    PATHS "C:\\libs\\win32\\SuiteSparse\\Include"
    "${VS_SEARCH_PATH}"
    PATH_SUFFIXES suitesparse-4.2.1/include/suitesparse
    suitesparse-metis-for-windows-1.2.2-install/include/suitesparse
    )

  # Add cholmod include directory to collection include directories
50
  if ( CHOLMOD_INCLUDE_DIR )
51
    list ( APPEND SUITESPARSE_INCLUDE_DIRS ${CHOLMOD_INCLUDE_DIR} )
52
  endif( CHOLMOD_INCLUDE_DIR )
53
54


55
56
57
58
59
60
61
62
63
  # find path suitesparse library
  FIND_PATH( SUITESPARSE_LIBRARY_DIRS
    NAMES amd.lib libamd.lib
    PATHS "C:\\libs\\win32\\SuiteSparse\\libs"
    "${VS_SEARCH_PATH}"
    PATH_SUFFIXES suitesparse-4.2.1/lib64
    suitesparse-metis-for-windows-1.2.2-install/lib64			   )

  # if we found the library, add it to the defined libraries
64
  if ( SUITESPARSE_LIBRARY_DIRS )
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    if ( EXISTS "${SUITESPARSE_LIBRARY_DIRS}/libamd.lib" )
      list ( APPEND SUITESPARSE_LIBRARY_DIRS "${SUITESPARSE_LIBRARY_DIRS}/lapack_blas_windows") # because liblapack.lib lies here
      list ( APPEND SUITESPARSE_LIBRARIES optimized;libamd;optimized;libcamd;optimized;libccolamd;optimized;libcholmod;optimized;libcolamd;optimized;metis;optimized;libspqr;optimized;libumfpack;debug;libamdd;debug;libcamdd;debug;libccolamdd;debug;libcholmodd;debug;libspqrd;debug;libumfpackd;debug;libcolamdd;debug;metisd;optimized;liblapack;debug;liblapackd;optimized;suitesparseconfig;debug;suitesparseconfigd )
    else()
      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()

    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 libspqr
        PATHS ${SUITESPARSE_LIBRARY_DIRS} )
82
      if (SUITESPARSE_SPQR_LIBRARY)
83
84
85
86
87
88
89
        list ( APPEND SUITESPARSE_LIBRARIES optimized;libspqr;debug;libspqrd)
      else(SUITESPARSE_SPQR_LIBRARY)
        SET(SUITESPARSE_SPQR_VALID FALSE)
      endif (SUITESPARSE_SPQR_LIBRARY)
    endif()


90
  endif( SUITESPARSE_LIBRARY_DIRS )
91
92

else( WIN32 )
93
  if( APPLE)
94
95
    FIND_PATH( CHOLMOD_INCLUDE_DIR cholmod.h
      PATHS  /opt/local/include/ufsparse )
96
97
98
99
100
   
    FIND_LIBRARY(SUITESPARSE_LIBRARY
      NAMES libSuiteSparse.dylib
      PATHS /opt/local/lib)
    message("SUITESPARSE_LIBRARY: ${SUITESPARSE_LIBRARY}")
101

102
103
104
    FIND_PATH( SUITESPARSE_LIBRARY_DIR
      NAMES libSuiteSparse.dylib
      PATHS /opt/local/lib )
105

106
107
    message("SUITESPARSE_LIBRARY_DIR: ${SUITESPARSE_LIBRARY_DIR}")
    list ( APPEND SUITESPARSE_LIBRARY_DIRS ${SUITESPARSE_LIBRARY_DIR} )
David Bommes's avatar
David Bommes committed
108

109
    list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_LIBRARY})
110

111
  else(APPLE)
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    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
      /usr/lib64
      /usr/local/lib
      /usr/lib/x86_64-linux-gnu )
126
127


128
  endif(APPLE)
129

130
  # Add cholmod include directory to collection include directories
131
  if ( CHOLMOD_INCLUDE_DIR )
132
    list ( APPEND SUITESPARSE_INCLUDE_DIRS ${CHOLMOD_INCLUDE_DIR} )
133
  endif( CHOLMOD_INCLUDE_DIR )
134
135


136
  # if we found the library, add it to the defined libraries
137
  if ( SUITESPARSE_LIBRARY_DIR )
David Bommes's avatar
David Bommes committed
138

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
    FIND_LIBRARY(SUITESPARSE_AMD_LIBRARY 
                 NAMES amd
                 PATHS ${SUITESPARSE_LIBRARY_DIR})
    list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_AMD_LIBRARY})
    FIND_LIBRARY(SUITESPARSE_CAMD_LIBRARY 
                 NAMES camd
                 PATHS ${SUITESPARSE_LIBRARY_DIR})
    list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_CAMD_LIBRARY})
    FIND_LIBRARY(SUITESPARSE_CCOLAMD_LIBRARY 
                 NAMES ccolamd
                 PATHS ${SUITESPARSE_LIBRARY_DIR})
    list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_CCOLAMD_LIBRARY})
    FIND_LIBRARY(SUITESPARSE_CHOLMOD_LIBRARY 
                 NAMES cholmod
                 PATHS ${SUITESPARSE_LIBRARY_DIR})
    list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_CHOLMOD_LIBRARY})
    FIND_LIBRARY(SUITESPARSE_COLAMD_LIBRARY
                 NAMES cholmod 
                 PATHS ${SUITESPARSE_LIBRARY_DIR})
    list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_COLAMD_LIBRARY})
    FIND_LIBRARY(SUITESPARSE_CXSPARSE_LIBRARY
                 NAMES cxsparse 
                 PATHS ${SUITESPARSE_LIBRARY_DIR})
    list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_CXSPARSE_LIBRARY})
    FIND_LIBRARY(SUITESPARSE_KLU_LIBRARY
                 NAMES klu 
                 PATHS ${SUITESPARSE_LIBRARY_DIR})
    list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_KLU_LIBRARY})
    FIND_LIBRARY(SUITESPARSE_UMFPACK_LIBRARY
                 NAMES umfpack 
                 PATHS ${SUITESPARSE_LIBRARY_DIR})
    list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_UMFPACK_LIBRARY})

172
173
174
175
176
    #       list ( APPEND SUITESPARSE_LIBRARIES csparse)
    #       list ( APPEND SUITESPARSE_LIBRARIES spqr)

    # Metis and spqr are optional
    FIND_LIBRARY( SUITESPARSE_METIS_LIBRARY
177
178
179
                  NAMES coinmetis metis
                  PATHS "$ENV{IPOPT_HOME}/lib"
                        ${SUITESPARSE_LIBRARY_DIR} )
180
    if (SUITESPARSE_METIS_LIBRARY)
181
      list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_METIS_LIBRARY})
182
    endif(SUITESPARSE_METIS_LIBRARY)
David Bommes's avatar
changed    
David Bommes committed
183

184
185
186
187
188
    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()
David Bommes's avatar
changed    
David Bommes committed
189

190
191
192
193
    if(SUITESPARSE_SPQR_VALID)
      FIND_LIBRARY( SUITESPARSE_SPQR_LIBRARY
        NAMES spqr
        PATHS ${SUITESPARSE_LIBRARY_DIR} )
194
      if (SUITESPARSE_SPQR_LIBRARY)
195
        list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_SPQR_LIBRARY})
196
      endif (SUITESPARSE_SPQR_LIBRARY)
197
198
    endif()

199
  endif( SUITESPARSE_LIBRARY_DIR )
200

201
202
endif( WIN32 )

203
204
if (SUITESPARSE_LIBRARY_DIR AND SUITESPARSE_LIBRARIES)
  if(WIN32)
205
    list (APPEND SUITESPARSE_INCLUDE_DIRS ${CHOLMOD_INCLUDE_DIR}/../../UFconfig )
206
  endif(WIN32)
207
  SET(SUITESPARSE_FOUND TRUE)
208
else (SUITESPARSE_LIBRARY_DIR AND SUITESPARSE_LIBRARIES)
209
  SET( SUITESPARSE_FOUND FALSE )
210
endif (SUITESPARSE_LIBRARY_DIR AND SUITESPARSE_LIBRARIES)
211