FindBLAS.cmake 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. if (NOT _LANGUAGES_ MATCHES Fortran)
  42. include(CheckFunctionExists)
  43. else ()
  44. include(CheckFortranFunctionExists)
  45. endif()
  46. macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _threads)
  47. # This macro checks for the existence of the combination of fortran libraries
  48. # given by _list. If the combination is found, this macro checks (using the
  49. # Check_Fortran_Function_Exists macro) whether can link against that library
  50. # combination using the name of a routine given by _name using the linker
  51. # flags given by _flags. If the combination of libraries is found and passes
  52. # the link test, LIBRARIES is set to the list of complete library paths that
  53. # have been found. Otherwise, LIBRARIES is set to FALSE.
  54. # N.B. _prefix is the prefix applied to the names of all cached variables that
  55. # are generated internally and marked advanced by this macro.
  56. set(_libraries_work TRUE)
  57. set(${LIBRARIES})
  58. set(_combined_name)
  59. foreach(_library ${_list})
  60. set(_combined_name ${_combined_name}_${_library})
  61. if(_libraries_work)
  62. if ( WIN32 )
  63. if(BLA_STATIC)
  64. set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
  65. endif(BLA_STATIC)
  66. find_library(${_prefix}_${_library}_LIBRARY
  67. NAMES ${_library}
  68. PATHS ENV LIB
  69. )
  70. endif ( WIN32 )
  71. if ( APPLE )
  72. if(BLA_STATIC)
  73. set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
  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 DYLD_LIBRARY_PATH
  78. )
  79. else ( APPLE )
  80. if(BLA_STATIC)
  81. set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
  82. endif(BLA_STATIC)
  83. find_library(${_prefix}_${_library}_LIBRARY
  84. NAMES ${_library}
  85. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
  86. )
  87. endif( APPLE )
  88. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  89. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  90. set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
  91. endif(_libraries_work)
  92. endforeach(_library ${_list})
  93. if(_libraries_work)
  94. # Test this combination of libraries.
  95. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_threads})
  96. # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  97. if (_LANGUAGES_ MATCHES Fortran)
  98. check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
  99. else()
  100. check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
  101. endif()
  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. # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
  231. if(NOT BLAS_LIBRARIES)
  232. check_fortran_libraries(
  233. BLAS_LIBRARIES
  234. BLAS
  235. sgemm
  236. ""
  237. "acml;acml_mv"
  238. ""
  239. )
  240. endif(NOT BLAS_LIBRARIES)
  241. if(NOT BLAS_LIBRARIES)
  242. check_fortran_libraries(
  243. BLAS_LIBRARIES
  244. BLAS
  245. sgemm
  246. ""
  247. "acml_mp;acml_mv"
  248. ""
  249. )
  250. endif(NOT BLAS_LIBRARIES)
  251. endif (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
  252. # Apple BLAS library?
  253. if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  254. if(NOT BLAS_LIBRARIES)
  255. check_fortran_libraries(
  256. BLAS_LIBRARIES
  257. BLAS
  258. cblas_dgemm
  259. ""
  260. "Accelerate"
  261. ""
  262. )
  263. endif(NOT BLAS_LIBRARIES)
  264. endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  265. if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  266. if ( NOT BLAS_LIBRARIES )
  267. check_fortran_libraries(
  268. BLAS_LIBRARIES
  269. BLAS
  270. cblas_dgemm
  271. ""
  272. "vecLib"
  273. ""
  274. )
  275. endif ( NOT BLAS_LIBRARIES )
  276. endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  277. # Generic BLAS library?
  278. if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  279. if(NOT BLAS_LIBRARIES)
  280. check_fortran_libraries(
  281. BLAS_LIBRARIES
  282. BLAS
  283. sgemm
  284. ""
  285. "blas"
  286. ""
  287. )
  288. endif(NOT BLAS_LIBRARIES)
  289. endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  290. #BLAS in intel mkl 10 library? (em64t 64bit)
  291. if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  292. if (NOT WIN32)
  293. set(LM "-lm")
  294. endif ()
  295. if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  296. if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  297. find_package(Threads)
  298. else(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  299. find_package(Threads REQUIRED)
  300. endif(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  301. if (WIN32)
  302. if(BLA_F95)
  303. if(NOT BLAS95_LIBRARIES)
  304. check_fortran_libraries(
  305. BLAS95_LIBRARIES
  306. BLAS
  307. sgemm
  308. ""
  309. "mkl_blas95;mkl_intel_c;mkl_intel_thread;mkl_core;libguide40"
  310. ""
  311. )
  312. endif(NOT BLAS95_LIBRARIES)
  313. else(BLA_F95)
  314. if(NOT BLAS_LIBRARIES)
  315. check_fortran_libraries(
  316. BLAS_LIBRARIES
  317. BLAS
  318. SGEMM
  319. ""
  320. "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40"
  321. ""
  322. )
  323. endif(NOT BLAS_LIBRARIES)
  324. endif(BLA_F95)
  325. else(WIN32)
  326. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  327. if(BLA_F95)
  328. if(NOT BLAS95_LIBRARIES)
  329. check_fortran_libraries(
  330. BLAS95_LIBRARIES
  331. BLAS
  332. sgemm
  333. ""
  334. "mkl_blas95;mkl_intel;mkl_intel_thread;mkl_core;guide"
  335. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  336. )
  337. endif(NOT BLAS95_LIBRARIES)
  338. else(BLA_F95)
  339. if(NOT BLAS_LIBRARIES)
  340. check_fortran_libraries(
  341. BLAS_LIBRARIES
  342. BLAS
  343. sgemm
  344. ""
  345. "mkl_intel;mkl_intel_thread;mkl_core;guide"
  346. "${CMAKE_THREAD_LIBS_INIT}"
  347. "${LM}"
  348. )
  349. endif(NOT BLAS_LIBRARIES)
  350. endif(BLA_F95)
  351. endif (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  352. if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
  353. if(BLA_F95)
  354. if(NOT BLAS95_LIBRARIES)
  355. check_fortran_libraries(
  356. BLAS95_LIBRARIES
  357. BLAS
  358. sgemm
  359. ""
  360. "mkl_blas95;mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
  361. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  362. )
  363. endif(NOT BLAS95_LIBRARIES)
  364. else(BLA_F95)
  365. if(NOT BLAS_LIBRARIES)
  366. check_fortran_libraries(
  367. BLAS_LIBRARIES
  368. BLAS
  369. sgemm
  370. ""
  371. "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
  372. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  373. )
  374. endif(NOT BLAS_LIBRARIES)
  375. endif(BLA_F95)
  376. endif (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
  377. endif (WIN32)
  378. #older vesions of intel mkl libs
  379. # BLAS in intel mkl library? (shared)
  380. if(NOT BLAS_LIBRARIES)
  381. check_fortran_libraries(
  382. BLAS_LIBRARIES
  383. BLAS
  384. sgemm
  385. ""
  386. "mkl;guide"
  387. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  388. )
  389. endif(NOT BLAS_LIBRARIES)
  390. #BLAS in intel mkl library? (static, 32bit)
  391. if(NOT BLAS_LIBRARIES)
  392. check_fortran_libraries(
  393. BLAS_LIBRARIES
  394. BLAS
  395. sgemm
  396. ""
  397. "mkl_ia32;guide"
  398. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  399. )
  400. endif(NOT BLAS_LIBRARIES)
  401. #BLAS in intel mkl library? (static, em64t 64bit)
  402. if(NOT BLAS_LIBRARIES)
  403. check_fortran_libraries(
  404. BLAS_LIBRARIES
  405. BLAS
  406. sgemm
  407. ""
  408. "mkl_em64t;guide"
  409. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  410. )
  411. endif(NOT BLAS_LIBRARIES)
  412. endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  413. endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  414. if(BLA_F95)
  415. if(BLAS95_LIBRARIES)
  416. set(BLAS95_FOUND TRUE)
  417. else(BLAS95_LIBRARIES)
  418. set(BLAS95_FOUND FALSE)
  419. endif(BLAS95_LIBRARIES)
  420. if(NOT BLAS_FIND_QUIETLY)
  421. if(BLAS95_FOUND)
  422. message(STATUS "A library with BLAS95 API found.")
  423. else(BLAS95_FOUND)
  424. if(BLAS_FIND_REQUIRED)
  425. message(FATAL_ERROR
  426. "A required library with BLAS95 API not found. Please specify library location.")
  427. else(BLAS_FIND_REQUIRED)
  428. message(STATUS
  429. "A library with BLAS95 API not found. Please specify library location.")
  430. endif(BLAS_FIND_REQUIRED)
  431. endif(BLAS95_FOUND)
  432. endif(NOT BLAS_FIND_QUIETLY)
  433. set(BLAS_FOUND TRUE)
  434. set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
  435. else(BLA_F95)
  436. if(BLAS_LIBRARIES)
  437. set(BLAS_FOUND TRUE)
  438. else(BLAS_LIBRARIES)
  439. set(BLAS_FOUND FALSE)
  440. endif(BLAS_LIBRARIES)
  441. if(NOT BLAS_FIND_QUIETLY)
  442. if(BLAS_FOUND)
  443. message(STATUS "A library with BLAS API found.")
  444. else(BLAS_FOUND)
  445. if(BLAS_FIND_REQUIRED)
  446. message(FATAL_ERROR
  447. "A required library with BLAS API not found. Please specify library location."
  448. )
  449. else(BLAS_FIND_REQUIRED)
  450. message(STATUS
  451. "A library with BLAS API not found. Please specify library location."
  452. )
  453. endif(BLAS_FIND_REQUIRED)
  454. endif(BLAS_FOUND)
  455. endif(NOT BLAS_FIND_QUIETLY)
  456. endif(BLA_F95)