FindBLAS.cmake 13 KB

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