FindSUITESPARSE.cmake 6.42 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
11
#  SUITESPARSE_SPQR_VALID       - automatic identification whether or not spqr package is installed correctly
12 13 14 15 16 17 18 19 20

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

Jan Möbius's avatar
Jan Möbius committed
21 22 23 24 25
  if ( CMAKE_GENERATOR MATCHES "^Visual Studio 11.*Win64" )
    SET(VS_SEARCH_PATH "c:/libs/vs2012/x64/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 11.*" )
    SET(VS_SEARCH_PATH "c:/libs/vs2012/x32/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 12.*Win64" )
26
    SET(VS_SEARCH_PATH "c:/libs/vs2013/x64/")
Jan Möbius's avatar
Jan Möbius committed
27 28 29 30 31
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 12.*" )
    SET(VS_SEARCH_PATH "c:/libs/vs2013/x32/")
  endif()
 

32
   FIND_PATH( CHOLMOD_INCLUDE_DIR cholmod.h
Jan Möbius's avatar
Jan Möbius committed
33 34 35
              PATHS "C:\\libs\\win32\\SuiteSparse\\Include"
         	    "${VS_SEARCH_PATH}"
	      PATH_SUFFIXES suitesparse-4.2.1/include/suitesparse
36
		                suitesparse-metis-for-windows-1.2.2-install/include/suitesparse
Jan Möbius's avatar
Jan Möbius committed
37
		      )
38 39 40 41 42 43 44 45

   # 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
46
   FIND_PATH( SUITESPARSE_LIBRARY_DIRS 
Jan Möbius's avatar
Jan Möbius committed
47
	       NAMES amd.lib libamd.lib
Jan Möbius's avatar
Jan Möbius committed
48 49
               PATHS "C:\\libs\\win32\\SuiteSparse\\libs" 
                     "${VS_SEARCH_PATH}"
50 51
               PATH_SUFFIXES suitesparse-4.2.1/lib64
                             suitesparse-metis-for-windows-1.2.2-install/lib64			   )
52
				
53
   # if we found the library, add it to the defined libraries
54
   IF ( SUITESPARSE_LIBRARY_DIRS )
55
     if ( EXISTS "${SUITESPARSE_LIBRARY_DIRS}/libamd.lib" )
56
	   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;optimzed;suitesparseconfig;debug;suitesparseconfigd )
57 58 59 60
     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()  
	 
61
   ENDIF( SUITESPARSE_LIBRARY_DIRS )  
62 63

else( WIN32 )
64
   IF( APPLE)
65 66 67
	   FIND_PATH( CHOLMOD_INCLUDE_DIR cholmod.h
        	      PATHS  /opt/local/include/ufsparse )

68
           FIND_PATH( SUITESPARSE_LIBRARY_DIR
69
                      NAMES libSuiteSparse.dylib
70 71
                      PATHS /opt/local/lib )

72 73 74
           list ( APPEND SUITESPARSE_LIBRARY_DIRS ${SUITESPARSE_LIBRARY_DIR} )

           list ( APPEND SUITESPARSE_LIBRARIES SuiteSparse)
75 76 77

   ELSE(APPLE)
	   FIND_PATH( CHOLMOD_INCLUDE_DIR cholmod.h
78
        	      PATHS /usr/local/include 
79 80 81
        	            /usr/include 
        	            /usr/include/suitesparse/ 
        	            ${CMAKE_SOURCE_DIR}/MacOS/Libs/cholmod
82 83 84 85 86
              	      PATH_SUFFIXES cholmod/ CHOLMOD/ )

   	
           FIND_PATH( SUITESPARSE_LIBRARY_DIR
                      NAMES libcholmod.so 
87 88
                      PATHS /usr/lib 
                            /usr/lib64 
89 90
                            /usr/local/lib
			    /usr/lib/x86_64-linux-gnu )
91 92 93 94 95 96 97 98 99 100 101 102


   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 )
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117

       # Skipped, as this is set for apple in the block above
       if (NOT APPLE)
         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)
       endif()
118 119 120 121
   
       # Metis and spqr are optional
       FIND_LIBRARY( SUITESPARSE_METIS_LIBRARY
                     NAMES metis
122
                     PATHS ${SUITESPARSE_LIBRARY_DIR} )
123
       IF (SUITESPARSE_METIS_LIBRARY)			
124
	  list ( APPEND SUITESPARSE_LIBRARIES ${SUITESPARSE_METIS_LIBRARY})
125 126 127 128
       ENDIF(SUITESPARSE_METIS_LIBRARY)

       if(EXISTS  "${CHOLMOD_INCLUDE_DIR}/SuiteSparseQR.hpp")
	  SET(SUITESPARSE_SPQR_VALID TRUE CACHE BOOL "SuiteSparseSPQR valid")
Jan Möbius's avatar
Jan Möbius committed
129
       else()
130 131 132 133 134 135 136 137 138 139
	  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)
Jan Möbius's avatar
Jan Möbius committed
140
       endif()
141 142
       
    ENDIF( SUITESPARSE_LIBRARY_DIR )  
143 144 145 146 147 148 149 150 151 152 153 154
   
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)
ELSE (SUITESPARSE_INCLUDE_DIRS AND SUITESPARSE_LIBRARIES)
   SET( SUITESPARSE_FOUND FALSE )
ENDIF (SUITESPARSE_INCLUDE_DIRS AND SUITESPARSE_LIBRARIES)