1# - Find CBLAS library 2# 3# This module finds an installed fortran library that implements the CBLAS 4# linear-algebra interface (see http://www.netlib.org/blas/), with CBLAS 5# interface. 6# 7# This module sets the following variables: 8# CBLAS_FOUND - set to true if a library implementing the CBLAS interface is found 9# CBLAS_LIBRARIES - list of libraries (using full path name) to link against to use CBLAS 10# CBLAS_INCLUDE_DIR - path to includes 11# CBLAS_INCLUDE_FILE - the file to be included to use CBLAS 12# 13 14SET(CBLAS_LIBRARIES) 15SET(CBLAS_INCLUDE_DIR) 16SET(CBLAS_INCLUDE_FILE) 17 18# CBLAS in Intel mkl 19FIND_PACKAGE(MKL) 20IF (MKL_FOUND AND NOT CBLAS_LIBRARIES) 21 SET(CBLAS_LIBRARIES ${MKL_LIBRARIES}) 22 SET(CBLAS_INCLUDE_DIR ${MKL_INCLUDE_DIR}) 23 SET(CBLAS_INCLUDE_FILE "mkl_cblas.h") 24ENDIF (MKL_FOUND AND NOT CBLAS_LIBRARIES) 25 26# Old CBLAS search 27SET(_verbose TRUE) 28INCLUDE(CheckFunctionExists) 29INCLUDE(CheckIncludeFile) 30 31MACRO(CHECK_ALL_LIBRARIES LIBRARIES _prefix _name _flags _list _include _search_include) 32 # This macro checks for the existence of the combination of fortran libraries 33 # given by _list. If the combination is found, this macro checks (using the 34 # Check_Fortran_Function_Exists macro) whether can link against that library 35 # combination using the name of a routine given by _name using the linker 36 # flags given by _flags. If the combination of libraries is found and passes 37 # the link test, LIBRARIES is set to the list of complete library paths that 38 # have been found. Otherwise, LIBRARIES is set to FALSE. 39 # N.B. _prefix is the prefix applied to the names of all cached variables that 40 # are generated internally and marked advanced by this macro. 41 SET(__list) 42 FOREACH(_elem ${_list}) 43 IF(__list) 44 SET(__list "${__list} - ${_elem}") 45 ELSE(__list) 46 SET(__list "${_elem}") 47 ENDIF(__list) 48 ENDFOREACH(_elem) 49 IF(_verbose) 50 MESSAGE(STATUS "Checking for [${__list}]") 51 ENDIF(_verbose) 52 SET(_libraries_work TRUE) 53 SET(${LIBRARIES}) 54 SET(_combined_name) 55 SET(_paths) 56 FOREACH(_library ${_list}) 57 SET(_combined_name ${_combined_name}_${_library}) 58 # did we find all the libraries in the _list until now? 59 # (we stop at the first unfound one) 60 IF(_libraries_work) 61 IF(APPLE) 62 FIND_LIBRARY(${_prefix}_${_library}_LIBRARY 63 NAMES ${_library} 64 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV 65 DYLD_LIBRARY_PATH 66 ) 67 ELSE(APPLE) 68 FIND_LIBRARY(${_prefix}_${_library}_LIBRARY 69 NAMES ${_library} 70 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV 71 LD_LIBRARY_PATH 72 ) 73 ENDIF(APPLE) 74 MARK_AS_ADVANCED(${_prefix}_${_library}_LIBRARY) 75 IF(${_prefix}_${_library}_LIBRARY) 76 GET_FILENAME_COMPONENT(_path ${${_prefix}_${_library}_LIBRARY} PATH) 77 LIST(APPEND _paths ${_path}/../include ${_path}/../../include) 78 ENDIF(${_prefix}_${_library}_LIBRARY) 79 SET(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY}) 80 SET(_libraries_work ${${_prefix}_${_library}_LIBRARY}) 81 ENDIF(_libraries_work) 82 ENDFOREACH(_library ${_list}) 83 # Test include 84 SET(_bug_search_include ${_search_include}) #CMAKE BUG!!! SHOULD NOT BE THAT 85 IF(_bug_search_include) 86 FIND_PATH(${_prefix}${_combined_name}_INCLUDE ${_include} ${_paths}) 87 MARK_AS_ADVANCED(${_prefix}${_combined_name}_INCLUDE) 88 IF(${_prefix}${_combined_name}_INCLUDE) 89 IF (_verbose) 90 MESSAGE(STATUS "Includes found") 91 ENDIF (_verbose) 92 SET(${_prefix}_INCLUDE_DIR ${${_prefix}${_combined_name}_INCLUDE}) 93 SET(${_prefix}_INCLUDE_FILE ${_include}) 94 ELSE(${_prefix}${_combined_name}_INCLUDE) 95 SET(_libraries_work FALSE) 96 ENDIF(${_prefix}${_combined_name}_INCLUDE) 97 ELSE(_bug_search_include) 98 SET(${_prefix}_INCLUDE_DIR) 99 SET(${_prefix}_INCLUDE_FILE ${_include}) 100 ENDIF(_bug_search_include) 101 # Test this combination of libraries. 102 IF(_libraries_work) 103 SET(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}}) 104 CHECK_FUNCTION_EXISTS(${_name} ${_prefix}${_combined_name}_WORKS) 105 SET(CMAKE_REQUIRED_LIBRARIES) 106 MARK_AS_ADVANCED(${_prefix}${_combined_name}_WORKS) 107 SET(_libraries_work ${${_prefix}${_combined_name}_WORKS}) 108 IF(_verbose AND _libraries_work) 109 MESSAGE(STATUS "Libraries found") 110 ENDIF(_verbose AND _libraries_work) 111 ENDIF(_libraries_work) 112 # Fin 113 IF(NOT _libraries_work) 114 SET(${LIBRARIES} NOTFOUND) 115 ENDIF(NOT _libraries_work) 116ENDMACRO(CHECK_ALL_LIBRARIES) 117 118# Generic CBLAS library 119IF(NOT CBLAS_LIBRARIES) 120 CHECK_ALL_LIBRARIES( 121 CBLAS_LIBRARIES 122 CBLAS 123 cblas_dgemm 124 "" 125 "cblas" 126 "cblas.h" 127 TRUE ) 128ENDIF() 129 130# CBLAS in ATLAS library? (http://math-atlas.sourceforge.net/) 131IF(NOT CBLAS_LIBRARIES) 132 CHECK_ALL_LIBRARIES( 133 CBLAS_LIBRARIES 134 CBLAS 135 cblas_dgemm 136 "" 137 "cblas;atlas" 138 "cblas.h" 139 TRUE ) 140ENDIF() 141 142# CBLAS in BLAS library 143IF(NOT CBLAS_LIBRARIES) 144 CHECK_ALL_LIBRARIES( 145 CBLAS_LIBRARIES 146 CBLAS 147 cblas_dgemm 148 "" 149 "blas" 150 "cblas.h" 151 TRUE ) 152ENDIF() 153 154# Apple CBLAS library? 155IF(NOT CBLAS_LIBRARIES) 156 CHECK_ALL_LIBRARIES( 157 CBLAS_LIBRARIES 158 CBLAS 159 cblas_dgemm 160 "" 161 "Accelerate" 162 "Accelerate/Accelerate.h" 163 FALSE ) 164ENDIF() 165 166IF( NOT CBLAS_LIBRARIES ) 167 CHECK_ALL_LIBRARIES( 168 CBLAS_LIBRARIES 169 CBLAS 170 cblas_dgemm 171 "" 172 "vecLib" 173 "vecLib/vecLib.h" 174 FALSE ) 175ENDIF() 176 177include ( FindPackageHandleStandardArgs ) 178find_package_handle_standard_args ( CBLAS DEFAULT_MSG CBLAS_LIBRARIES 179) 180 181