1
0

FindBLAS.cmake 13 KB

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