FindBLAS.cmake 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. # - Find BLAS library
  2. # This module finds an installed fortran library that implements the BLAS
  3. # linear-algebra interface (see http://www.netlib.org/blas/).
  4. # The list of libraries searched for is taken
  5. # from the autoconf macro file, acx_blas.m4 (distributed at
  6. # http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
  7. #
  8. # This module sets the following variables:
  9. # BLAS_FOUND - set to true if a library implementing the BLAS interface
  10. # is found
  11. # BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l
  12. # and -L).
  13. # BLAS_LIBRARIES - uncached list of libraries (using full path name) to
  14. # link against to use BLAS
  15. #
  16. include(CheckFortranFunctionExists)
  17. macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list)
  18. # This macro checks for the existence of the combination of fortran libraries
  19. # given by _list. If the combination is found, this macro checks (using the
  20. # Check_Fortran_Function_Exists macro) whether can link against that library
  21. # combination using the name of a routine given by _name using the linker
  22. # flags given by _flags. If the combination of libraries is found and passes
  23. # the link test, LIBRARIES is set to the list of complete library paths that
  24. # have been found. Otherwise, LIBRARIES is set to FALSE.
  25. # N.B. _prefix is the prefix applied to the names of all cached variables that
  26. # are generated internally and marked advanced by this macro.
  27. set(_libraries_work TRUE)
  28. set(${LIBRARIES})
  29. set(_combined_name)
  30. foreach(_library ${_list})
  31. set(_combined_name ${_combined_name}_${_library})
  32. if(_libraries_work)
  33. if ( APPLE )
  34. find_library(${_prefix}_${_library}_LIBRARY
  35. NAMES ${_library}
  36. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
  37. )
  38. else ( APPLE )
  39. find_library(${_prefix}_${_library}_LIBRARY
  40. NAMES ${_library}
  41. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
  42. )
  43. endif( APPLE )
  44. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  45. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  46. set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
  47. endif(_libraries_work)
  48. endforeach(_library ${_list})
  49. if(_libraries_work)
  50. # Test this combination of libraries.
  51. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}})
  52. #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  53. check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
  54. set(CMAKE_REQUIRED_LIBRARIES)
  55. mark_as_advanced(${_prefix}${_combined_name}_WORKS)
  56. set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
  57. endif(_libraries_work)
  58. if(NOT _libraries_work)
  59. set(${LIBRARIES} FALSE)
  60. endif(NOT _libraries_work)
  61. #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
  62. endmacro(Check_Fortran_Libraries)
  63. set(BLAS_LINKER_FLAGS)
  64. set(BLAS_LIBRARIES)
  65. if(NOT BLAS_LIBRARIES)
  66. # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
  67. check_fortran_libraries(
  68. BLAS_LIBRARIES
  69. BLAS
  70. cblas_dgemm
  71. ""
  72. "cblas;f77blas;atlas"
  73. )
  74. endif(NOT BLAS_LIBRARIES)
  75. # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
  76. if(NOT BLAS_LIBRARIES)
  77. check_fortran_libraries(
  78. BLAS_LIBRARIES
  79. BLAS
  80. sgemm
  81. ""
  82. "sgemm;dgemm;blas"
  83. )
  84. endif(NOT BLAS_LIBRARIES)
  85. # BLAS in Alpha CXML library?
  86. if(NOT BLAS_LIBRARIES)
  87. check_fortran_libraries(
  88. BLAS_LIBRARIES
  89. BLAS
  90. sgemm
  91. ""
  92. "cxml"
  93. )
  94. endif(NOT BLAS_LIBRARIES)
  95. # BLAS in Alpha DXML library? (now called CXML, see above)
  96. if(NOT BLAS_LIBRARIES)
  97. check_fortran_libraries(
  98. BLAS_LIBRARIES
  99. BLAS
  100. sgemm
  101. ""
  102. "dxml"
  103. )
  104. endif(NOT BLAS_LIBRARIES)
  105. # BLAS in Sun Performance library?
  106. if(NOT BLAS_LIBRARIES)
  107. check_fortran_libraries(
  108. BLAS_LIBRARIES
  109. BLAS
  110. sgemm
  111. "-xlic_lib=sunperf"
  112. "sunperf;sunmath"
  113. )
  114. if(BLAS_LIBRARIES)
  115. set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
  116. endif(BLAS_LIBRARIES)
  117. endif(NOT BLAS_LIBRARIES)
  118. # BLAS in SCSL library? (SGI/Cray Scientific Library)
  119. if(NOT BLAS_LIBRARIES)
  120. check_fortran_libraries(
  121. BLAS_LIBRARIES
  122. BLAS
  123. sgemm
  124. ""
  125. "scsl"
  126. )
  127. endif(NOT BLAS_LIBRARIES)
  128. # BLAS in SGIMATH library?
  129. if(NOT BLAS_LIBRARIES)
  130. check_fortran_libraries(
  131. BLAS_LIBRARIES
  132. BLAS
  133. sgemm
  134. ""
  135. "complib.sgimath"
  136. )
  137. endif(NOT BLAS_LIBRARIES)
  138. # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
  139. if(NOT BLAS_LIBRARIES)
  140. check_fortran_libraries(
  141. BLAS_LIBRARIES
  142. BLAS
  143. sgemm
  144. ""
  145. "essl;blas"
  146. )
  147. endif(NOT BLAS_LIBRARIES)
  148. # BLAS in intel mkl library? (shared)
  149. if(NOT BLAS_LIBRARIES)
  150. check_fortran_libraries(
  151. BLAS_LIBRARIES
  152. BLAS
  153. sgemm
  154. ""
  155. "mkl;guide;pthread"
  156. )
  157. endif(NOT BLAS_LIBRARIES)
  158. #BLAS in intel mkl library? (static, 32bit)
  159. if(NOT BLAS_LIBRARIES)
  160. check_fortran_libraries(
  161. BLAS_LIBRARIES
  162. BLAS
  163. sgemm
  164. ""
  165. "mkl_ia32;guide;pthread"
  166. )
  167. endif(NOT BLAS_LIBRARIES)
  168. #BLAS in intel mkl library? (static, em64t 64bit)
  169. if(NOT BLAS_LIBRARIES)
  170. check_fortran_libraries(
  171. BLAS_LIBRARIES
  172. BLAS
  173. sgemm
  174. ""
  175. "mkl_em64t;guide;pthread"
  176. )
  177. endif(NOT BLAS_LIBRARIES)
  178. #BLAS in acml library?
  179. if(NOT BLAS_LIBRARIES)
  180. check_fortran_libraries(
  181. BLAS_LIBRARIES
  182. BLAS
  183. sgemm
  184. ""
  185. "acml"
  186. )
  187. endif(NOT BLAS_LIBRARIES)
  188. # Apple BLAS library?
  189. if(NOT BLAS_LIBRARIES)
  190. check_fortran_libraries(
  191. BLAS_LIBRARIES
  192. BLAS
  193. cblas_dgemm
  194. ""
  195. "Accelerate"
  196. )
  197. endif(NOT BLAS_LIBRARIES)
  198. if ( NOT BLAS_LIBRARIES )
  199. check_fortran_libraries(
  200. BLAS_LIBRARIES
  201. BLAS
  202. cblas_dgemm
  203. ""
  204. "vecLib"
  205. )
  206. endif ( NOT BLAS_LIBRARIES )
  207. # Generic BLAS library?
  208. if(NOT BLAS_LIBRARIES)
  209. check_fortran_libraries(
  210. BLAS_LIBRARIES
  211. BLAS
  212. sgemm
  213. ""
  214. "blas"
  215. )
  216. endif(NOT BLAS_LIBRARIES)
  217. if(BLAS_LIBRARIES)
  218. set(BLAS_FOUND TRUE)
  219. else(BLAS_LIBRARIES)
  220. set(BLAS_FOUND FALSE)
  221. endif(BLAS_LIBRARIES)
  222. if(NOT BLAS_FIND_QUIETLY)
  223. if(BLAS_FOUND)
  224. message(STATUS "A library with BLAS API found.")
  225. else(BLAS_FOUND)
  226. if(BLAS_FIND_REQUIRED)
  227. message(FATAL_ERROR
  228. "A required library with BLAS API not found. Please specify library location."
  229. )
  230. else(BLAS_FIND_REQUIRED)
  231. message(STATUS
  232. "A library with BLAS API not found. Please specify library location."
  233. )
  234. endif(BLAS_FIND_REQUIRED)
  235. endif(BLAS_FOUND)
  236. endif(NOT BLAS_FIND_QUIETLY)