FindBLAS.cmake 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. # BLAS95_LIBRARIES - uncached list of libraries (using full path name) # to link against to use BLAS95 interface
  16. #
  17. include(CheckFortranFunctionExists)
  18. macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list)
  19. # This macro checks for the existence of the combination of fortran libraries
  20. # given by _list. If the combination is found, this macro checks (using the
  21. # Check_Fortran_Function_Exists macro) whether can link against that library
  22. # combination using the name of a routine given by _name using the linker
  23. # flags given by _flags. If the combination of libraries is found and passes
  24. # the link test, LIBRARIES is set to the list of complete library paths that
  25. # have been found. Otherwise, LIBRARIES is set to FALSE.
  26. # N.B. _prefix is the prefix applied to the names of all cached variables that
  27. # are generated internally and marked advanced by this macro.
  28. set(_libraries_work TRUE)
  29. set(${LIBRARIES})
  30. set(_combined_name)
  31. foreach(_library ${_list})
  32. set(_combined_name ${_combined_name}_${_library})
  33. if(_libraries_work)
  34. if ( WIN32 )
  35. find_library(${_prefix}_${_library}_LIBRARY
  36. NAMES ${_library}
  37. PATHS ENV LIB
  38. )
  39. endif ( WIN32 )
  40. if ( APPLE )
  41. find_library(${_prefix}_${_library}_LIBRARY
  42. NAMES ${_library}
  43. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
  44. )
  45. else ( APPLE )
  46. find_library(${_prefix}_${_library}_LIBRARY
  47. NAMES ${_library}
  48. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
  49. )
  50. endif( APPLE )
  51. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  52. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  53. set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
  54. endif(_libraries_work)
  55. endforeach(_library ${_list})
  56. if(_libraries_work)
  57. # Test this combination of libraries.
  58. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}})
  59. #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  60. check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
  61. set(CMAKE_REQUIRED_LIBRARIES)
  62. mark_as_advanced(${_prefix}${_combined_name}_WORKS)
  63. set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
  64. endif(_libraries_work)
  65. if(NOT _libraries_work)
  66. set(${LIBRARIES} FALSE)
  67. endif(NOT _libraries_work)
  68. #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
  69. endmacro(Check_Fortran_Libraries)
  70. set(BLAS_LINKER_FLAGS)
  71. set(BLAS_LIBRARIES)
  72. set(BLAS95_LIBRARIES)
  73. if(NOT BLAS_LIBRARIES)
  74. # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
  75. check_fortran_libraries(
  76. BLAS_LIBRARIES
  77. BLAS
  78. cblas_dgemm
  79. ""
  80. "cblas;f77blas;atlas"
  81. )
  82. endif(NOT BLAS_LIBRARIES)
  83. # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
  84. if(NOT BLAS_LIBRARIES)
  85. check_fortran_libraries(
  86. BLAS_LIBRARIES
  87. BLAS
  88. sgemm
  89. ""
  90. "sgemm;dgemm;blas"
  91. )
  92. endif(NOT BLAS_LIBRARIES)
  93. # BLAS in Alpha CXML library?
  94. if(NOT BLAS_LIBRARIES)
  95. check_fortran_libraries(
  96. BLAS_LIBRARIES
  97. BLAS
  98. sgemm
  99. ""
  100. "cxml"
  101. )
  102. endif(NOT BLAS_LIBRARIES)
  103. # BLAS in Alpha DXML library? (now called CXML, see above)
  104. if(NOT BLAS_LIBRARIES)
  105. check_fortran_libraries(
  106. BLAS_LIBRARIES
  107. BLAS
  108. sgemm
  109. ""
  110. "dxml"
  111. )
  112. endif(NOT BLAS_LIBRARIES)
  113. # BLAS in Sun Performance library?
  114. if(NOT BLAS_LIBRARIES)
  115. check_fortran_libraries(
  116. BLAS_LIBRARIES
  117. BLAS
  118. sgemm
  119. "-xlic_lib=sunperf"
  120. "sunperf;sunmath"
  121. )
  122. if(BLAS_LIBRARIES)
  123. set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
  124. endif(BLAS_LIBRARIES)
  125. endif(NOT BLAS_LIBRARIES)
  126. # BLAS in SCSL library? (SGI/Cray Scientific Library)
  127. if(NOT BLAS_LIBRARIES)
  128. check_fortran_libraries(
  129. BLAS_LIBRARIES
  130. BLAS
  131. sgemm
  132. ""
  133. "scsl"
  134. )
  135. endif(NOT BLAS_LIBRARIES)
  136. # BLAS in SGIMATH library?
  137. if(NOT BLAS_LIBRARIES)
  138. check_fortran_libraries(
  139. BLAS_LIBRARIES
  140. BLAS
  141. sgemm
  142. ""
  143. "complib.sgimath"
  144. )
  145. endif(NOT BLAS_LIBRARIES)
  146. # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
  147. if(NOT BLAS_LIBRARIES)
  148. check_fortran_libraries(
  149. BLAS_LIBRARIES
  150. BLAS
  151. sgemm
  152. ""
  153. "essl;blas"
  154. )
  155. endif(NOT BLAS_LIBRARIES)
  156. #BLAS in intel mkl 10 library? (em64t 64bit)
  157. if(NOT BLAS_LIBRARIES)
  158. check_fortran_libraries(
  159. BLAS_LIBRARIES
  160. BLAS
  161. sgemm
  162. ""
  163. "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide;pthread"
  164. )
  165. endif(NOT BLAS_LIBRARIES)
  166. if(NOT BLAS95_LIBRARIES)
  167. check_fortran_libraries(
  168. BLAS95_LIBRARIES
  169. BLAS
  170. sgemm
  171. ""
  172. "mkl_blas95;mkl_intel_lp64;mkl_intel_thread;mkl_core;guide;pthread"
  173. )
  174. endif(NOT BLAS95_LIBRARIES)
  175. ### windows version of intel mkl 10
  176. if(NOT BLAS_LIBRARIES)
  177. check_fortran_libraries(
  178. BLAS_LIBRARIES
  179. BLAS
  180. SGEMM
  181. ""
  182. "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40"
  183. )
  184. endif(NOT BLAS_LIBRARIES)
  185. if(NOT BLAS95_LIBRARIES)
  186. check_fortran_libraries(
  187. BLAS95_LIBRARIES
  188. BLAS
  189. sgemm
  190. ""
  191. "mkl_blas95;mkl_intel_c;mkl_intel_thread;mkl_core;libguide40"
  192. )
  193. endif(NOT BLAS95_LIBRARIES)
  194. # linux 32 bit
  195. if(NOT BLAS95_LIBRARIES)
  196. check_fortran_libraries(
  197. BLAS95_LIBRARIES
  198. BLAS
  199. sgemm
  200. ""
  201. "mkl_blas95;mkl_intel;mkl_intel_thread;mkl_core;guide;pthread"
  202. )
  203. endif(NOT BLAS95_LIBRARIES)
  204. #older vesions of intel mkl libs
  205. # BLAS in intel mkl library? (shared)
  206. if(NOT BLAS_LIBRARIES)
  207. check_fortran_libraries(
  208. BLAS_LIBRARIES
  209. BLAS
  210. sgemm
  211. ""
  212. "mkl;guide;pthread"
  213. )
  214. endif(NOT BLAS_LIBRARIES)
  215. #BLAS in intel mkl library? (static, 32bit)
  216. if(NOT BLAS_LIBRARIES)
  217. check_fortran_libraries(
  218. BLAS_LIBRARIES
  219. BLAS
  220. sgemm
  221. ""
  222. "mkl_ia32;guide;pthread"
  223. )
  224. endif(NOT BLAS_LIBRARIES)
  225. #BLAS in intel mkl library? (static, em64t 64bit)
  226. if(NOT BLAS_LIBRARIES)
  227. check_fortran_libraries(
  228. BLAS_LIBRARIES
  229. BLAS
  230. sgemm
  231. ""
  232. "mkl_em64t;guide;pthread"
  233. )
  234. endif(NOT BLAS_LIBRARIES)
  235. #BLAS in acml library?
  236. if(NOT BLAS_LIBRARIES)
  237. check_fortran_libraries(
  238. BLAS_LIBRARIES
  239. BLAS
  240. sgemm
  241. ""
  242. "acml"
  243. )
  244. endif(NOT BLAS_LIBRARIES)
  245. # Apple BLAS library?
  246. if(NOT BLAS_LIBRARIES)
  247. check_fortran_libraries(
  248. BLAS_LIBRARIES
  249. BLAS
  250. cblas_dgemm
  251. ""
  252. "Accelerate"
  253. )
  254. endif(NOT BLAS_LIBRARIES)
  255. if ( NOT BLAS_LIBRARIES )
  256. check_fortran_libraries(
  257. BLAS_LIBRARIES
  258. BLAS
  259. cblas_dgemm
  260. ""
  261. "vecLib"
  262. )
  263. endif ( NOT BLAS_LIBRARIES )
  264. # Generic BLAS library?
  265. if(NOT BLAS_LIBRARIES)
  266. check_fortran_libraries(
  267. BLAS_LIBRARIES
  268. BLAS
  269. sgemm
  270. ""
  271. "blas"
  272. )
  273. endif(NOT BLAS_LIBRARIES)
  274. if(BLAS_LIBRARIES)
  275. set(BLAS_FOUND TRUE)
  276. else(BLAS_LIBRARIES)
  277. set(BLAS_FOUND FALSE)
  278. endif(BLAS_LIBRARIES)
  279. if(NOT BLAS_FIND_QUIETLY)
  280. if(BLAS_FOUND)
  281. message(STATUS "A library with BLAS API found.")
  282. else(BLAS_FOUND)
  283. if(BLAS_FIND_REQUIRED)
  284. message(FATAL_ERROR
  285. "A required library with BLAS API not found. Please specify library location."
  286. )
  287. else(BLAS_FIND_REQUIRED)
  288. message(STATUS
  289. "A library with BLAS API not found. Please specify library location."
  290. )
  291. endif(BLAS_FIND_REQUIRED)
  292. endif(BLAS_FOUND)
  293. endif(NOT BLAS_FIND_QUIETLY)