FindBLAS.cmake 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. if(NOT BLAS_LIBRARIES)
  223. check_fortran_libraries(
  224. BLAS_LIBRARIES
  225. BLAS
  226. sgemm
  227. ""
  228. "acml"
  229. ""
  230. )
  231. endif(NOT BLAS_LIBRARIES)
  232. endif (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
  233. # Apple BLAS library?
  234. if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  235. if(NOT BLAS_LIBRARIES)
  236. check_fortran_libraries(
  237. BLAS_LIBRARIES
  238. BLAS
  239. cblas_dgemm
  240. ""
  241. "Accelerate"
  242. ""
  243. )
  244. endif(NOT BLAS_LIBRARIES)
  245. endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  246. if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  247. if ( NOT BLAS_LIBRARIES )
  248. check_fortran_libraries(
  249. BLAS_LIBRARIES
  250. BLAS
  251. cblas_dgemm
  252. ""
  253. "vecLib"
  254. ""
  255. )
  256. endif ( NOT BLAS_LIBRARIES )
  257. endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  258. # Generic BLAS library?
  259. if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  260. if(NOT BLAS_LIBRARIES)
  261. check_fortran_libraries(
  262. BLAS_LIBRARIES
  263. BLAS
  264. sgemm
  265. ""
  266. "blas"
  267. ""
  268. )
  269. endif(NOT BLAS_LIBRARIES)
  270. endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  271. #BLAS in intel mkl 10 library? (em64t 64bit)
  272. if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  273. if (NOT WIN32)
  274. set(LM "-lm")
  275. endif ()
  276. if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  277. if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  278. find_package(Threads)
  279. else(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  280. find_package(Threads REQUIRED)
  281. endif(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  282. if (WIN32)
  283. if(BLA_F95)
  284. if(NOT BLAS95_LIBRARIES)
  285. check_fortran_libraries(
  286. BLAS95_LIBRARIES
  287. BLAS
  288. sgemm
  289. ""
  290. "mkl_blas95;mkl_intel_c;mkl_intel_thread;mkl_core;libguide40"
  291. ""
  292. )
  293. endif(NOT BLAS95_LIBRARIES)
  294. else(BLA_F95)
  295. if(NOT BLAS_LIBRARIES)
  296. check_fortran_libraries(
  297. BLAS_LIBRARIES
  298. BLAS
  299. SGEMM
  300. ""
  301. "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40"
  302. ""
  303. )
  304. endif(NOT BLAS_LIBRARIES)
  305. endif(BLA_F95)
  306. else(WIN32)
  307. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  308. if(BLA_F95)
  309. if(NOT BLAS95_LIBRARIES)
  310. check_fortran_libraries(
  311. BLAS95_LIBRARIES
  312. BLAS
  313. sgemm
  314. ""
  315. "mkl_blas95;mkl_intel;mkl_intel_thread;mkl_core;guide"
  316. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  317. )
  318. endif(NOT BLAS95_LIBRARIES)
  319. else(BLA_F95)
  320. if(NOT BLAS_LIBRARIES)
  321. check_fortran_libraries(
  322. BLAS_LIBRARIES
  323. BLAS
  324. sgemm
  325. ""
  326. "mkl_intel;mkl_intel_thread;mkl_core;guide"
  327. "${CMAKE_THREAD_LIBS_INIT}"
  328. "${LM}"
  329. )
  330. endif(NOT BLAS_LIBRARIES)
  331. endif(BLA_F95)
  332. endif (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  333. if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
  334. if(BLA_F95)
  335. if(NOT BLAS95_LIBRARIES)
  336. check_fortran_libraries(
  337. BLAS95_LIBRARIES
  338. BLAS
  339. sgemm
  340. ""
  341. "mkl_blas95;mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
  342. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  343. )
  344. endif(NOT BLAS95_LIBRARIES)
  345. else(BLA_F95)
  346. if(NOT BLAS_LIBRARIES)
  347. check_fortran_libraries(
  348. BLAS_LIBRARIES
  349. BLAS
  350. sgemm
  351. ""
  352. "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
  353. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  354. )
  355. endif(NOT BLAS_LIBRARIES)
  356. endif(BLA_F95)
  357. endif (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
  358. endif (WIN32)
  359. #older vesions of intel mkl libs
  360. # BLAS in intel mkl library? (shared)
  361. if(NOT BLAS_LIBRARIES)
  362. check_fortran_libraries(
  363. BLAS_LIBRARIES
  364. BLAS
  365. sgemm
  366. ""
  367. "mkl;guide"
  368. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  369. )
  370. endif(NOT BLAS_LIBRARIES)
  371. #BLAS in intel mkl library? (static, 32bit)
  372. if(NOT BLAS_LIBRARIES)
  373. check_fortran_libraries(
  374. BLAS_LIBRARIES
  375. BLAS
  376. sgemm
  377. ""
  378. "mkl_ia32;guide"
  379. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  380. )
  381. endif(NOT BLAS_LIBRARIES)
  382. #BLAS in intel mkl library? (static, em64t 64bit)
  383. if(NOT BLAS_LIBRARIES)
  384. check_fortran_libraries(
  385. BLAS_LIBRARIES
  386. BLAS
  387. sgemm
  388. ""
  389. "mkl_em64t;guide"
  390. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  391. )
  392. endif(NOT BLAS_LIBRARIES)
  393. endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  394. endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  395. if(BLA_F95)
  396. if(BLAS95_LIBRARIES)
  397. set(BLAS95_FOUND TRUE)
  398. else(BLAS95_LIBRARIES)
  399. set(BLAS95_FOUND FALSE)
  400. endif(BLAS95_LIBRARIES)
  401. if(NOT BLAS_FIND_QUIETLY)
  402. if(BLAS95_FOUND)
  403. message(STATUS "A library with BLAS95 API found.")
  404. else(BLAS95_FOUND)
  405. if(BLAS_FIND_REQUIRED)
  406. message(FATAL_ERROR
  407. "A required library with BLAS95 API not found. Please specify library location.")
  408. else(BLAS_FIND_REQUIRED)
  409. message(STATUS
  410. "A library with BLAS95 API not found. Please specify library location.")
  411. endif(BLAS_FIND_REQUIRED)
  412. endif(BLAS95_FOUND)
  413. endif(NOT BLAS_FIND_QUIETLY)
  414. set(BLAS_FOUND TRUE)
  415. set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
  416. else(BLA_F95)
  417. if(BLAS_LIBRARIES)
  418. set(BLAS_FOUND TRUE)
  419. else(BLAS_LIBRARIES)
  420. set(BLAS_FOUND FALSE)
  421. endif(BLAS_LIBRARIES)
  422. if(NOT BLAS_FIND_QUIETLY)
  423. if(BLAS_FOUND)
  424. message(STATUS "A library with BLAS API found.")
  425. else(BLAS_FOUND)
  426. if(BLAS_FIND_REQUIRED)
  427. message(FATAL_ERROR
  428. "A required library with BLAS API not found. Please specify library location."
  429. )
  430. else(BLAS_FIND_REQUIRED)
  431. message(STATUS
  432. "A library with BLAS API not found. Please specify library location."
  433. )
  434. endif(BLAS_FIND_REQUIRED)
  435. endif(BLAS_FOUND)
  436. endif(NOT BLAS_FIND_QUIETLY)
  437. endif(BLA_F95)