FindBLAS.cmake 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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)
  16. # to link against to use BLAS95 interface
  17. # BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface
  18. # is found
  19. # BLA_STATIC if set on this determines what kind of linkage we do (static)
  20. # BLA_VENDOR if set checks only the specified vendor, if not set checks
  21. # all the posibilities
  22. # BLA_F95 if set on tries to find the f95 interfaces for BLAS/LAPACK
  23. ##########
  24. ### List of vendors (BLA_VENDOR) valid in this module
  25. ## ATLAS, PhiPACK,CXML,DXML,SunPerf,SCSL,SGIMATH,IBMESSL,Intel10_32 (intel mkl v10 32 bit),Intel10_64lp (intel mkl v10 64 bit,lp thread model, lp64 model),
  26. ## Intel( older versions of mkl 32 and 64 bit), ACML,Apple, NAS, Generic
  27. # C/CXX should be enabled to use Intel mkl
  28. get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES)
  29. if(NOT _LANGUAGES_ MATCHES Fortran)
  30. if(BLAS_FIND_REQUIRED)
  31. message(FATAL_ERROR "FindBLAS is Fortran-only so Fortran must be enabled.")
  32. else(BLAS_FIND_REQUIRED)
  33. message(STATUS "Looking for BLAS... - NOT found (Fortran not enabled)") #
  34. return()
  35. endif(BLAS_FIND_REQUIRED)
  36. endif(NOT _LANGUAGES_ MATCHES Fortran)
  37. include(CheckFortranFunctionExists)
  38. macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _threads)
  39. # This macro checks for the existence of the combination of fortran libraries
  40. # given by _list. If the combination is found, this macro checks (using the
  41. # Check_Fortran_Function_Exists macro) whether can link against that library
  42. # combination using the name of a routine given by _name using the linker
  43. # flags given by _flags. If the combination of libraries is found and passes
  44. # the link test, LIBRARIES is set to the list of complete library paths that
  45. # have been found. Otherwise, LIBRARIES is set to FALSE.
  46. # N.B. _prefix is the prefix applied to the names of all cached variables that
  47. # are generated internally and marked advanced by this macro.
  48. set(_libraries_work TRUE)
  49. set(${LIBRARIES})
  50. set(_combined_name)
  51. foreach(_library ${_list})
  52. set(_combined_name ${_combined_name}_${_library})
  53. if(_libraries_work)
  54. if ( WIN32 )
  55. if(BLA_STATIC)
  56. set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
  57. endif(BLA_STATIC)
  58. find_library(${_prefix}_${_library}_LIBRARY
  59. NAMES ${_library}
  60. PATHS ENV LIB
  61. )
  62. endif ( WIN32 )
  63. if ( APPLE )
  64. if(BLA_STATIC)
  65. set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
  66. endif(BLA_STATIC)
  67. find_library(${_prefix}_${_library}_LIBRARY
  68. NAMES ${_library}
  69. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
  70. )
  71. else ( APPLE )
  72. if(BLA_STATIC)
  73. set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
  74. endif(BLA_STATIC)
  75. find_library(${_prefix}_${_library}_LIBRARY
  76. NAMES ${_library}
  77. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
  78. )
  79. endif( APPLE )
  80. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  81. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  82. set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
  83. endif(_libraries_work)
  84. endforeach(_library ${_list})
  85. if(_libraries_work)
  86. # Test this combination of libraries.
  87. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_threads})
  88. # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  89. check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
  90. set(CMAKE_REQUIRED_LIBRARIES)
  91. mark_as_advanced(${_prefix}${_combined_name}_WORKS)
  92. set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
  93. endif(_libraries_work)
  94. if(NOT _libraries_work)
  95. set(${LIBRARIES} FALSE)
  96. endif(NOT _libraries_work)
  97. #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
  98. endmacro(Check_Fortran_Libraries)
  99. set(BLAS_LINKER_FLAGS)
  100. set(BLAS_LIBRARIES)
  101. set(BLAS95_LIBRARIES)
  102. if ($ENV{BLA_VENDOR} MATCHES ".+")
  103. set(BLA_VENDOR $ENV{BLA_VENDOR})
  104. else ($ENV{BLA_VENDOR} MATCHES ".+")
  105. if(NOT BLA_VENDOR)
  106. set(BLA_VENDOR "All")
  107. endif(NOT BLA_VENDOR)
  108. endif ($ENV{BLA_VENDOR} MATCHES ".+")
  109. if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
  110. if(NOT BLAS_LIBRARIES)
  111. # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
  112. check_fortran_libraries(
  113. BLAS_LIBRARIES
  114. BLAS
  115. cblas_dgemm
  116. ""
  117. "cblas;f77blas;atlas"
  118. ""
  119. )
  120. endif(NOT BLAS_LIBRARIES)
  121. endif (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
  122. # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
  123. if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
  124. if(NOT BLAS_LIBRARIES)
  125. check_fortran_libraries(
  126. BLAS_LIBRARIES
  127. BLAS
  128. sgemm
  129. ""
  130. "sgemm;dgemm;blas"
  131. ""
  132. )
  133. endif(NOT BLAS_LIBRARIES)
  134. endif (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
  135. # BLAS in Alpha CXML library?
  136. if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
  137. if(NOT BLAS_LIBRARIES)
  138. check_fortran_libraries(
  139. BLAS_LIBRARIES
  140. BLAS
  141. sgemm
  142. ""
  143. "cxml"
  144. ""
  145. )
  146. endif(NOT BLAS_LIBRARIES)
  147. endif (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
  148. # BLAS in Alpha DXML library? (now called CXML, see above)
  149. if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
  150. if(NOT BLAS_LIBRARIES)
  151. check_fortran_libraries(
  152. BLAS_LIBRARIES
  153. BLAS
  154. sgemm
  155. ""
  156. "dxml"
  157. ""
  158. )
  159. endif(NOT BLAS_LIBRARIES)
  160. endif (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
  161. # BLAS in Sun Performance library?
  162. if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
  163. if(NOT BLAS_LIBRARIES)
  164. check_fortran_libraries(
  165. BLAS_LIBRARIES
  166. BLAS
  167. sgemm
  168. "-xlic_lib=sunperf"
  169. "sunperf;sunmath"
  170. ""
  171. )
  172. if(BLAS_LIBRARIES)
  173. set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
  174. endif(BLAS_LIBRARIES)
  175. endif(NOT BLAS_LIBRARIES)
  176. endif (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
  177. # BLAS in SCSL library? (SGI/Cray Scientific Library)
  178. if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
  179. if(NOT BLAS_LIBRARIES)
  180. check_fortran_libraries(
  181. BLAS_LIBRARIES
  182. BLAS
  183. sgemm
  184. ""
  185. "scsl"
  186. ""
  187. )
  188. endif(NOT BLAS_LIBRARIES)
  189. endif (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
  190. # BLAS in SGIMATH library?
  191. if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
  192. if(NOT BLAS_LIBRARIES)
  193. check_fortran_libraries(
  194. BLAS_LIBRARIES
  195. BLAS
  196. sgemm
  197. ""
  198. "complib.sgimath"
  199. ""
  200. )
  201. endif(NOT BLAS_LIBRARIES)
  202. endif (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
  203. # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
  204. if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
  205. if(NOT BLAS_LIBRARIES)
  206. check_fortran_libraries(
  207. BLAS_LIBRARIES
  208. BLAS
  209. sgemm
  210. ""
  211. "essl;blas"
  212. ""
  213. )
  214. endif(NOT BLAS_LIBRARIES)
  215. endif (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
  216. #BLAS in acml library?
  217. if (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
  218. if(NOT BLAS_LIBRARIES)
  219. check_fortran_libraries(
  220. BLAS_LIBRARIES
  221. BLAS
  222. sgemm
  223. ""
  224. "acml"
  225. ""
  226. )
  227. endif(NOT BLAS_LIBRARIES)
  228. endif (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
  229. # Apple BLAS library?
  230. if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  231. if(NOT BLAS_LIBRARIES)
  232. check_fortran_libraries(
  233. BLAS_LIBRARIES
  234. BLAS
  235. cblas_dgemm
  236. ""
  237. "Accelerate"
  238. ""
  239. )
  240. endif(NOT BLAS_LIBRARIES)
  241. endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  242. if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  243. if ( NOT BLAS_LIBRARIES )
  244. check_fortran_libraries(
  245. BLAS_LIBRARIES
  246. BLAS
  247. cblas_dgemm
  248. ""
  249. "vecLib"
  250. ""
  251. )
  252. endif ( NOT BLAS_LIBRARIES )
  253. endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  254. # Generic BLAS library?
  255. if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  256. if(NOT BLAS_LIBRARIES)
  257. check_fortran_libraries(
  258. BLAS_LIBRARIES
  259. BLAS
  260. sgemm
  261. ""
  262. "blas"
  263. ""
  264. )
  265. endif(NOT BLAS_LIBRARIES)
  266. endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  267. #BLAS in intel mkl 10 library? (em64t 64bit)
  268. if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  269. if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  270. if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  271. find_package(Threads)
  272. else(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  273. find_package(Threads REQUIRED)
  274. endif(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  275. if (WIN32)
  276. if(BLA_F95)
  277. if(NOT BLAS95_LIBRARIES)
  278. check_fortran_libraries(
  279. BLAS95_LIBRARIES
  280. BLAS
  281. sgemm
  282. ""
  283. "mkl_blas95;mkl_intel_c;mkl_intel_thread;mkl_core;libguide40"
  284. ""
  285. )
  286. endif(NOT BLAS95_LIBRARIES)
  287. else(BLA_F95)
  288. if(NOT BLAS_LIBRARIES)
  289. check_fortran_libraries(
  290. BLAS_LIBRARIES
  291. BLAS
  292. SGEMM
  293. ""
  294. "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40"
  295. ""
  296. )
  297. endif(NOT BLAS_LIBRARIES)
  298. endif(BLA_F95)
  299. else(WIN32)
  300. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  301. if(BLA_F95)
  302. if(NOT BLAS95_LIBRARIES)
  303. check_fortran_libraries(
  304. BLAS95_LIBRARIES
  305. BLAS
  306. sgemm
  307. ""
  308. "mkl_blas95;mkl_intel;mkl_intel_thread;mkl_core;guide"
  309. "${CMAKE_THREAD_LIBS_INIT}"
  310. )
  311. endif(NOT BLAS95_LIBRARIES)
  312. else(BLA_F95)
  313. if(NOT BLAS_LIBRARIES)
  314. check_fortran_libraries(
  315. BLAS_LIBRARIES
  316. BLAS
  317. sgemm
  318. ""
  319. "mkl_intel;mkl_intel_thread;mkl_core;guide"
  320. "${CMAKE_THREAD_LIBS_INIT}"
  321. )
  322. endif(NOT BLAS_LIBRARIES)
  323. endif(BLA_F95)
  324. endif (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  325. if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
  326. if(BLA_F95)
  327. if(NOT BLAS95_LIBRARIES)
  328. check_fortran_libraries(
  329. BLAS95_LIBRARIES
  330. BLAS
  331. sgemm
  332. ""
  333. "mkl_blas95;mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
  334. "${CMAKE_THREAD_LIBS_INIT}"
  335. )
  336. endif(NOT BLAS95_LIBRARIES)
  337. else(BLA_F95)
  338. if(NOT BLAS_LIBRARIES)
  339. check_fortran_libraries(
  340. BLAS_LIBRARIES
  341. BLAS
  342. sgemm
  343. ""
  344. "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
  345. "${CMAKE_THREAD_LIBS_INIT}"
  346. )
  347. endif(NOT BLAS_LIBRARIES)
  348. endif(BLA_F95)
  349. endif (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
  350. endif (WIN32)
  351. #older vesions of intel mkl libs
  352. # BLAS in intel mkl library? (shared)
  353. if(NOT BLAS_LIBRARIES)
  354. check_fortran_libraries(
  355. BLAS_LIBRARIES
  356. BLAS
  357. sgemm
  358. ""
  359. "mkl;guide"
  360. "${CMAKE_THREAD_LIBS_INIT}"
  361. )
  362. endif(NOT BLAS_LIBRARIES)
  363. #BLAS in intel mkl library? (static, 32bit)
  364. if(NOT BLAS_LIBRARIES)
  365. check_fortran_libraries(
  366. BLAS_LIBRARIES
  367. BLAS
  368. sgemm
  369. ""
  370. "mkl_ia32;guide"
  371. "${CMAKE_THREAD_LIBS_INIT}"
  372. )
  373. endif(NOT BLAS_LIBRARIES)
  374. #BLAS in intel mkl library? (static, em64t 64bit)
  375. if(NOT BLAS_LIBRARIES)
  376. check_fortran_libraries(
  377. BLAS_LIBRARIES
  378. BLAS
  379. sgemm
  380. ""
  381. "mkl_em64t;guide"
  382. "${CMAKE_THREAD_LIBS_INIT}"
  383. )
  384. endif(NOT BLAS_LIBRARIES)
  385. endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  386. endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  387. if(BLA_F95)
  388. if(BLAS95_LIBRARIES)
  389. set(BLAS95_FOUND TRUE)
  390. else(BLAS95_LIBRARIES)
  391. set(BLAS95_FOUND FALSE)
  392. endif(BLAS95_LIBRARIES)
  393. if(NOT BLAS_FIND_QUIETLY)
  394. if(BLAS95_FOUND)
  395. message(STATUS "A library with BLAS95 API found.")
  396. else(BLAS95_FOUND)
  397. if(BLAS_FIND_REQUIRED)
  398. message(FATAL_ERROR
  399. "A required library with BLAS95 API not found. Please specify library location.")
  400. else(BLAS_FIND_REQUIRED)
  401. message(STATUS
  402. "A library with BLAS95 API not found. Please specify library location.")
  403. endif(BLAS_FIND_REQUIRED)
  404. endif(BLAS95_FOUND)
  405. endif(NOT BLAS_FIND_QUIETLY)
  406. set(BLAS_FOUND TRUE)
  407. set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
  408. else(BLA_F95)
  409. if(BLAS_LIBRARIES)
  410. set(BLAS_FOUND TRUE)
  411. else(BLAS_LIBRARIES)
  412. set(BLAS_FOUND FALSE)
  413. endif(BLAS_LIBRARIES)
  414. if(NOT BLAS_FIND_QUIETLY)
  415. if(BLAS_FOUND)
  416. message(STATUS "A library with BLAS API found.")
  417. else(BLAS_FOUND)
  418. if(BLAS_FIND_REQUIRED)
  419. message(FATAL_ERROR
  420. "A required library with BLAS API not found. Please specify library location."
  421. )
  422. else(BLAS_FIND_REQUIRED)
  423. message(STATUS
  424. "A library with BLAS API not found. Please specify library location."
  425. )
  426. endif(BLAS_FIND_REQUIRED)
  427. endif(BLAS_FOUND)
  428. endif(NOT BLAS_FIND_QUIETLY)
  429. endif(BLA_F95)