FindBLAS.cmake 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindBLAS
  5. --------
  6. Find BLAS library
  7. This module finds an installed fortran library that implements the
  8. BLAS linear-algebra interface (see http://www.netlib.org/blas/). The
  9. list of libraries searched for is taken from the autoconf macro file,
  10. acx_blas.m4 (distributed at
  11. http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
  12. This module sets the following variables:
  13. ::
  14. BLAS_FOUND - set to true if a library implementing the BLAS interface
  15. is found
  16. BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l
  17. and -L).
  18. BLAS_LIBRARIES - uncached list of libraries (using full path name) to
  19. link against to use BLAS (may be empty if compiler implicitly links
  20. BLAS)
  21. BLAS95_LIBRARIES - uncached list of libraries (using full path name)
  22. to link against to use BLAS95 interface
  23. BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface
  24. is found
  25. The following variables can be used to control this module:
  26. ::
  27. BLA_STATIC if set on this determines what kind of linkage we do (static)
  28. BLA_VENDOR if set checks only the specified vendor, if not set checks
  29. all the possibilities
  30. BLA_F95 if set on tries to find the f95 interfaces for BLAS/LAPACK
  31. BLA_PREFER_PKGCONFIG if set pkg-config will be used to search for a BLAS
  32. library first and if one is found that is preferred
  33. List of vendors (BLA_VENDOR) valid in this module:
  34. * Goto
  35. * OpenBLAS
  36. * FLAME
  37. * ATLAS PhiPACK
  38. * CXML
  39. * DXML
  40. * SunPerf
  41. * SCSL
  42. * SGIMATH
  43. * IBMESSL
  44. * Intel10_32 (intel mkl v10 32 bit)
  45. * Intel10_64lp (intel mkl v10+ 64 bit, threaded code, lp64 model)
  46. * Intel10_64lp_seq (intel mkl v10+ 64 bit, sequential code, lp64 model)
  47. * Intel10_64ilp (intel mkl v10+ 64 bit, threaded code, ilp64 model)
  48. * Intel10_64ilp_seq (intel mkl v10+ 64 bit, sequential code, ilp64 model)
  49. * Intel (older versions of mkl 32 and 64 bit)
  50. * ACML
  51. * ACML_MP
  52. * ACML_GPU
  53. * Apple
  54. * NAS
  55. * Generic
  56. .. note::
  57. C/CXX should be enabled to use Intel mkl
  58. #]=======================================================================]
  59. include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
  60. include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake)
  61. include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
  62. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  63. cmake_push_check_state()
  64. set(CMAKE_REQUIRED_QUIET ${BLAS_FIND_QUIETLY})
  65. set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  66. # Check the language being used
  67. if( NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED) )
  68. if(BLAS_FIND_REQUIRED)
  69. message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
  70. else()
  71. message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
  72. return()
  73. endif()
  74. endif()
  75. if(BLA_PREFER_PKGCONFIG)
  76. find_package(PkgConfig)
  77. pkg_check_modules(PKGC_BLAS blas)
  78. if(PKGC_BLAS_FOUND)
  79. set(BLAS_LIBRARIES "${PKGC_BLAS_LINK_LIBRARIES}")
  80. return()
  81. endif()
  82. endif()
  83. macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread)
  84. # This macro checks for the existence of the combination of fortran libraries
  85. # given by _list. If the combination is found, this macro checks (using the
  86. # Check_Fortran_Function_Exists macro) whether can link against that library
  87. # combination using the name of a routine given by _name using the linker
  88. # flags given by _flags. If the combination of libraries is found and passes
  89. # the link test, LIBRARIES is set to the list of complete library paths that
  90. # have been found. Otherwise, LIBRARIES is set to FALSE.
  91. # N.B. _prefix is the prefix applied to the names of all cached variables that
  92. # are generated internally and marked advanced by this macro.
  93. set(_libdir ${ARGN})
  94. set(_libraries_work TRUE)
  95. set(${LIBRARIES})
  96. set(_combined_name)
  97. if (NOT _libdir)
  98. if (WIN32)
  99. set(_libdir ENV LIB)
  100. elseif (APPLE)
  101. set(_libdir ENV DYLD_LIBRARY_PATH)
  102. else ()
  103. set(_libdir ENV LD_LIBRARY_PATH)
  104. endif ()
  105. endif ()
  106. foreach(_library ${_list})
  107. set(_combined_name ${_combined_name}_${_library})
  108. if(_libraries_work)
  109. if (BLA_STATIC)
  110. if (WIN32)
  111. set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
  112. endif ()
  113. if (APPLE)
  114. set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
  115. else ()
  116. set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  117. endif ()
  118. else ()
  119. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  120. # for ubuntu's libblas3gf and liblapack3gf packages
  121. set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
  122. endif ()
  123. endif ()
  124. find_library(${_prefix}_${_library}_LIBRARY
  125. NAMES ${_library}
  126. PATHS ${_libdir}
  127. )
  128. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  129. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  130. set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
  131. endif()
  132. endforeach()
  133. if(_libraries_work)
  134. # Test this combination of libraries.
  135. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_thread})
  136. # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  137. if (CMAKE_Fortran_COMPILER_LOADED)
  138. check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
  139. else()
  140. check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
  141. endif()
  142. set(CMAKE_REQUIRED_LIBRARIES)
  143. mark_as_advanced(${_prefix}${_combined_name}_WORKS)
  144. set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
  145. endif()
  146. if(_libraries_work)
  147. if("${_list}" STREQUAL "")
  148. set(${LIBRARIES} "${LIBRARIES}-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
  149. endif()
  150. else()
  151. set(${LIBRARIES} FALSE)
  152. endif()
  153. #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
  154. endmacro()
  155. set(BLAS_LINKER_FLAGS)
  156. set(BLAS_LIBRARIES)
  157. set(BLAS95_LIBRARIES)
  158. if (NOT $ENV{BLA_VENDOR} STREQUAL "")
  159. set(BLA_VENDOR $ENV{BLA_VENDOR})
  160. else ()
  161. if(NOT BLA_VENDOR)
  162. set(BLA_VENDOR "All")
  163. endif()
  164. endif ()
  165. if (BLA_VENDOR STREQUAL "All")
  166. if(NOT BLAS_LIBRARIES)
  167. # Implicitly linked BLAS libraries
  168. check_fortran_libraries(
  169. BLAS_LIBRARIES
  170. BLAS
  171. sgemm
  172. ""
  173. ""
  174. ""
  175. )
  176. endif()
  177. endif ()
  178. #BLAS in intel mkl 10+ library? (em64t 64bit)
  179. if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
  180. if (NOT BLAS_LIBRARIES)
  181. if (BLA_VENDOR MATCHES "_64ilp")
  182. set(BLAS_mkl_ILP_MODE "ilp64")
  183. else ()
  184. set(BLAS_mkl_ILP_MODE "lp64")
  185. endif ()
  186. if (NOT WIN32)
  187. set(LM "-lm")
  188. endif ()
  189. if (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
  190. if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  191. find_package(Threads)
  192. else()
  193. find_package(Threads REQUIRED)
  194. endif()
  195. set(BLAS_SEARCH_LIBS "")
  196. if(BLA_F95)
  197. set(BLAS_mkl_SEARCH_SYMBOL SGEMM)
  198. set(_LIBRARIES BLAS95_LIBRARIES)
  199. if (WIN32)
  200. if (BLA_STATIC)
  201. set(BLAS_mkl_DLL_SUFFIX "")
  202. else()
  203. set(BLAS_mkl_DLL_SUFFIX "_dll")
  204. endif()
  205. # Find the main file (32-bit or 64-bit)
  206. set(BLAS_SEARCH_LIBS_WIN_MAIN "")
  207. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  208. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  209. "mkl_blas95${BLAS_mkl_DLL_SUFFIX} mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
  210. endif()
  211. if (BLA_VENDOR MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
  212. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  213. "mkl_blas95_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX} mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
  214. endif ()
  215. # Add threading/sequential libs
  216. set(BLAS_SEARCH_LIBS_WIN_THREAD "")
  217. if (BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
  218. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  219. "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
  220. endif()
  221. if (NOT BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
  222. # old version
  223. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  224. "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  225. # mkl >= 10.3
  226. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  227. "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  228. endif()
  229. # Cartesian product of the above
  230. foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
  231. foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
  232. list(APPEND BLAS_SEARCH_LIBS
  233. "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
  234. endforeach()
  235. endforeach()
  236. else ()
  237. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  238. list(APPEND BLAS_SEARCH_LIBS
  239. "mkl_blas95 mkl_intel mkl_intel_thread mkl_core guide")
  240. endif ()
  241. if (BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  242. # old version
  243. list(APPEND BLAS_SEARCH_LIBS
  244. "mkl_blas95 mkl_intel_${BLAS_mkl_ILP_MODE} mkl_intel_thread mkl_core guide")
  245. # mkl >= 10.3
  246. if (CMAKE_C_COMPILER MATCHES ".+gcc")
  247. list(APPEND BLAS_SEARCH_LIBS
  248. "mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_intel_${BLAS_mkl_ILP_MODE} mkl_gnu_thread mkl_core gomp")
  249. else ()
  250. list(APPEND BLAS_SEARCH_LIBS
  251. "mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_intel_${BLAS_mkl_ILP_MODE} mkl_intel_thread mkl_core iomp5")
  252. endif ()
  253. endif ()
  254. if (BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  255. list(APPEND BLAS_SEARCH_LIBS
  256. "mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_intel_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core")
  257. endif ()
  258. endif ()
  259. else ()
  260. set(BLAS_mkl_SEARCH_SYMBOL sgemm)
  261. set(_LIBRARIES BLAS_LIBRARIES)
  262. if (WIN32)
  263. if (BLA_STATIC)
  264. set(BLAS_mkl_DLL_SUFFIX "")
  265. else()
  266. set(BLAS_mkl_DLL_SUFFIX "_dll")
  267. endif()
  268. # Find the main file (32-bit or 64-bit)
  269. set(BLAS_SEARCH_LIBS_WIN_MAIN "")
  270. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  271. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  272. "mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
  273. endif()
  274. if (BLA_VENDOR MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
  275. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  276. "mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
  277. endif ()
  278. # Add threading/sequential libs
  279. set(BLAS_SEARCH_LIBS_WIN_THREAD "")
  280. if (NOT BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
  281. # old version
  282. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  283. "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  284. # mkl >= 10.3
  285. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  286. "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  287. endif()
  288. if (BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
  289. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  290. "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
  291. endif()
  292. # Cartesian product of the above
  293. foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
  294. foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
  295. list(APPEND BLAS_SEARCH_LIBS
  296. "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
  297. endforeach()
  298. endforeach()
  299. else ()
  300. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  301. list(APPEND BLAS_SEARCH_LIBS
  302. "mkl_intel mkl_intel_thread mkl_core guide")
  303. endif ()
  304. if (BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  305. # old version
  306. list(APPEND BLAS_SEARCH_LIBS
  307. "mkl_intel_${BLAS_mkl_ILP_MODE} mkl_intel_thread mkl_core guide")
  308. # mkl >= 10.3
  309. if (CMAKE_C_COMPILER MATCHES ".+gcc")
  310. list(APPEND BLAS_SEARCH_LIBS
  311. "mkl_intel_${BLAS_mkl_ILP_MODE} mkl_gnu_thread mkl_core gomp")
  312. else ()
  313. list(APPEND BLAS_SEARCH_LIBS
  314. "mkl_intel_${BLAS_mkl_ILP_MODE} mkl_intel_thread mkl_core iomp5")
  315. endif ()
  316. endif ()
  317. if (BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  318. list(APPEND BLAS_SEARCH_LIBS
  319. "mkl_intel_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core")
  320. endif ()
  321. #older vesions of intel mkl libs
  322. if (BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
  323. list(APPEND BLAS_SEARCH_LIBS
  324. "mkl")
  325. list(APPEND BLAS_SEARCH_LIBS
  326. "mkl_ia32")
  327. list(APPEND BLAS_SEARCH_LIBS
  328. "mkl_em64t")
  329. endif ()
  330. endif ()
  331. endif ()
  332. foreach (IT ${BLAS_SEARCH_LIBS})
  333. string(REPLACE " " ";" SEARCH_LIBS ${IT})
  334. if (NOT ${_LIBRARIES})
  335. check_fortran_libraries(
  336. ${_LIBRARIES}
  337. BLAS
  338. ${BLAS_mkl_SEARCH_SYMBOL}
  339. ""
  340. "${SEARCH_LIBS}"
  341. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  342. )
  343. endif ()
  344. endforeach ()
  345. endif ()
  346. unset(BLAS_mkl_ILP_MODE)
  347. endif ()
  348. endif ()
  349. if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
  350. if(NOT BLAS_LIBRARIES)
  351. # gotoblas (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
  352. check_fortran_libraries(
  353. BLAS_LIBRARIES
  354. BLAS
  355. sgemm
  356. ""
  357. "goto2"
  358. ""
  359. )
  360. endif()
  361. endif ()
  362. if (BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All")
  363. if(NOT BLAS_LIBRARIES)
  364. # OpenBLAS (http://www.openblas.net)
  365. check_fortran_libraries(
  366. BLAS_LIBRARIES
  367. BLAS
  368. sgemm
  369. ""
  370. "openblas"
  371. ""
  372. )
  373. endif()
  374. endif ()
  375. if (BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All")
  376. if(NOT BLAS_LIBRARIES)
  377. # FLAME's blis library (https://github.com/flame/blis)
  378. check_fortran_libraries(
  379. BLAS_LIBRARIES
  380. BLAS
  381. sgemm
  382. ""
  383. "blis"
  384. ""
  385. )
  386. endif()
  387. endif ()
  388. if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
  389. if(NOT BLAS_LIBRARIES)
  390. # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
  391. check_fortran_libraries(
  392. BLAS_LIBRARIES
  393. BLAS
  394. dgemm
  395. ""
  396. "f77blas;atlas"
  397. ""
  398. )
  399. endif()
  400. endif ()
  401. # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
  402. if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
  403. if(NOT BLAS_LIBRARIES)
  404. check_fortran_libraries(
  405. BLAS_LIBRARIES
  406. BLAS
  407. sgemm
  408. ""
  409. "sgemm;dgemm;blas"
  410. ""
  411. )
  412. endif()
  413. endif ()
  414. # BLAS in Alpha CXML library?
  415. if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
  416. if(NOT BLAS_LIBRARIES)
  417. check_fortran_libraries(
  418. BLAS_LIBRARIES
  419. BLAS
  420. sgemm
  421. ""
  422. "cxml"
  423. ""
  424. )
  425. endif()
  426. endif ()
  427. # BLAS in Alpha DXML library? (now called CXML, see above)
  428. if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
  429. if(NOT BLAS_LIBRARIES)
  430. check_fortran_libraries(
  431. BLAS_LIBRARIES
  432. BLAS
  433. sgemm
  434. ""
  435. "dxml"
  436. ""
  437. )
  438. endif()
  439. endif ()
  440. # BLAS in Sun Performance library?
  441. if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
  442. if(NOT BLAS_LIBRARIES)
  443. check_fortran_libraries(
  444. BLAS_LIBRARIES
  445. BLAS
  446. sgemm
  447. "-xlic_lib=sunperf"
  448. "sunperf;sunmath"
  449. ""
  450. )
  451. if(BLAS_LIBRARIES)
  452. set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
  453. endif()
  454. endif()
  455. endif ()
  456. # BLAS in SCSL library? (SGI/Cray Scientific Library)
  457. if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
  458. if(NOT BLAS_LIBRARIES)
  459. check_fortran_libraries(
  460. BLAS_LIBRARIES
  461. BLAS
  462. sgemm
  463. ""
  464. "scsl"
  465. ""
  466. )
  467. endif()
  468. endif ()
  469. # BLAS in SGIMATH library?
  470. if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
  471. if(NOT BLAS_LIBRARIES)
  472. check_fortran_libraries(
  473. BLAS_LIBRARIES
  474. BLAS
  475. sgemm
  476. ""
  477. "complib.sgimath"
  478. ""
  479. )
  480. endif()
  481. endif ()
  482. # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
  483. if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
  484. if(NOT BLAS_LIBRARIES)
  485. check_fortran_libraries(
  486. BLAS_LIBRARIES
  487. BLAS
  488. sgemm
  489. ""
  490. "essl;blas"
  491. ""
  492. )
  493. endif()
  494. endif ()
  495. #BLAS in acml library?
  496. if (BLA_VENDOR MATCHES "ACML" OR BLA_VENDOR STREQUAL "All")
  497. if( ((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
  498. ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
  499. ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS))
  500. )
  501. # try to find acml in "standard" paths
  502. if( WIN32 )
  503. file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" )
  504. else()
  505. file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
  506. endif()
  507. if( WIN32 )
  508. file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
  509. else()
  510. file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" )
  511. endif()
  512. list(GET _ACML_ROOT 0 _ACML_ROOT)
  513. list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
  514. if( _ACML_ROOT )
  515. get_filename_component( _ACML_ROOT ${_ACML_ROOT} PATH )
  516. if( SIZEOF_INTEGER EQUAL 8 )
  517. set( _ACML_PATH_SUFFIX "_int64" )
  518. else()
  519. set( _ACML_PATH_SUFFIX "" )
  520. endif()
  521. if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
  522. set( _ACML_COMPILER32 "ifort32" )
  523. set( _ACML_COMPILER64 "ifort64" )
  524. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
  525. set( _ACML_COMPILER32 "sun32" )
  526. set( _ACML_COMPILER64 "sun64" )
  527. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
  528. set( _ACML_COMPILER32 "pgi32" )
  529. if( WIN32 )
  530. set( _ACML_COMPILER64 "win64" )
  531. else()
  532. set( _ACML_COMPILER64 "pgi64" )
  533. endif()
  534. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Open64" )
  535. # 32 bit builds not supported on Open64 but for code simplicity
  536. # We'll just use the same directory twice
  537. set( _ACML_COMPILER32 "open64_64" )
  538. set( _ACML_COMPILER64 "open64_64" )
  539. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
  540. set( _ACML_COMPILER32 "nag32" )
  541. set( _ACML_COMPILER64 "nag64" )
  542. else()
  543. set( _ACML_COMPILER32 "gfortran32" )
  544. set( _ACML_COMPILER64 "gfortran64" )
  545. endif()
  546. if( BLA_VENDOR STREQUAL "ACML_MP" )
  547. set(_ACML_MP_LIB_DIRS
  548. "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
  549. "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib" )
  550. else()
  551. set(_ACML_LIB_DIRS
  552. "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
  553. "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib" )
  554. endif()
  555. endif()
  556. elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
  557. set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
  558. endif()
  559. if( BLA_VENDOR STREQUAL "ACML_MP" )
  560. foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
  561. check_fortran_libraries (
  562. BLAS_LIBRARIES
  563. BLAS
  564. sgemm
  565. "" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS}
  566. )
  567. if( BLAS_LIBRARIES )
  568. break()
  569. endif()
  570. endforeach()
  571. elseif( BLA_VENDOR STREQUAL "ACML_GPU" )
  572. foreach( BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
  573. check_fortran_libraries (
  574. BLAS_LIBRARIES
  575. BLAS
  576. sgemm
  577. "" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS}
  578. )
  579. if( BLAS_LIBRARIES )
  580. break()
  581. endif()
  582. endforeach()
  583. else()
  584. foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} )
  585. check_fortran_libraries (
  586. BLAS_LIBRARIES
  587. BLAS
  588. sgemm
  589. "" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS}
  590. )
  591. if( BLAS_LIBRARIES )
  592. break()
  593. endif()
  594. endforeach()
  595. endif()
  596. # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
  597. if(NOT BLAS_LIBRARIES)
  598. check_fortran_libraries(
  599. BLAS_LIBRARIES
  600. BLAS
  601. sgemm
  602. ""
  603. "acml;acml_mv"
  604. ""
  605. )
  606. endif()
  607. if(NOT BLAS_LIBRARIES)
  608. check_fortran_libraries(
  609. BLAS_LIBRARIES
  610. BLAS
  611. sgemm
  612. ""
  613. "acml_mp;acml_mv"
  614. ""
  615. )
  616. endif()
  617. if(NOT BLAS_LIBRARIES)
  618. check_fortran_libraries(
  619. BLAS_LIBRARIES
  620. BLAS
  621. sgemm
  622. ""
  623. "acml;acml_mv;CALBLAS"
  624. ""
  625. )
  626. endif()
  627. endif () # ACML
  628. # Apple BLAS library?
  629. if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  630. if(NOT BLAS_LIBRARIES)
  631. check_fortran_libraries(
  632. BLAS_LIBRARIES
  633. BLAS
  634. dgemm
  635. ""
  636. "Accelerate"
  637. ""
  638. )
  639. endif()
  640. endif ()
  641. if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  642. if ( NOT BLAS_LIBRARIES )
  643. check_fortran_libraries(
  644. BLAS_LIBRARIES
  645. BLAS
  646. dgemm
  647. ""
  648. "vecLib"
  649. ""
  650. )
  651. endif ()
  652. endif ()
  653. # Generic BLAS library?
  654. if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  655. if(NOT BLAS_LIBRARIES)
  656. check_fortran_libraries(
  657. BLAS_LIBRARIES
  658. BLAS
  659. sgemm
  660. ""
  661. "blas"
  662. ""
  663. )
  664. endif()
  665. endif ()
  666. if(BLA_F95)
  667. find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS95_LIBRARIES)
  668. set(BLAS95_FOUND ${BLAS_FOUND})
  669. if(BLAS_FOUND)
  670. set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
  671. endif()
  672. else()
  673. find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS_LIBRARIES)
  674. endif()
  675. # On compilers that implicitly link BLAS (such as ftn, cc, and CC on Cray HPC machines)
  676. # we used a placeholder for empty BLAS_LIBRARIES to get through our logic above.
  677. if (BLAS_LIBRARIES STREQUAL "BLAS_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
  678. set(BLAS_LIBRARIES "")
  679. endif()
  680. cmake_pop_check_state()
  681. set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})