FindBLAS.cmake 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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 (WIN32)
  182. if (BLA_STATIC)
  183. set(BLAS_mkl_DLL_SUFFIX "")
  184. else()
  185. set(BLAS_mkl_DLL_SUFFIX "_dll")
  186. endif()
  187. endif()
  188. if (BLA_VENDOR MATCHES "_64ilp")
  189. set(BLAS_mkl_ILP_MODE "ilp64")
  190. else ()
  191. set(BLAS_mkl_ILP_MODE "lp64")
  192. endif ()
  193. if (NOT WIN32)
  194. set(LM "-lm")
  195. endif ()
  196. if (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
  197. if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  198. find_package(Threads)
  199. else()
  200. find_package(Threads REQUIRED)
  201. endif()
  202. set(BLAS_SEARCH_LIBS "")
  203. if(BLA_F95)
  204. set(BLAS_mkl_SEARCH_SYMBOL sgemm_f95)
  205. set(_LIBRARIES BLAS95_LIBRARIES)
  206. if (WIN32)
  207. # Find the main file (32-bit or 64-bit)
  208. set(BLAS_SEARCH_LIBS_WIN_MAIN "")
  209. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  210. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  211. "mkl_blas95${BLAS_mkl_DLL_SUFFIX} mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
  212. endif()
  213. if (BLA_VENDOR MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
  214. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  215. "mkl_blas95_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX} mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
  216. endif ()
  217. # Add threading/sequential libs
  218. set(BLAS_SEARCH_LIBS_WIN_THREAD "")
  219. if (BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
  220. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  221. "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
  222. endif()
  223. if (NOT BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
  224. # old version
  225. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  226. "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  227. # mkl >= 10.3
  228. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  229. "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  230. endif()
  231. # Cartesian product of the above
  232. foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
  233. foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
  234. list(APPEND BLAS_SEARCH_LIBS
  235. "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
  236. endforeach()
  237. endforeach()
  238. else ()
  239. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  240. list(APPEND BLAS_SEARCH_LIBS
  241. "mkl_blas95 mkl_intel mkl_intel_thread mkl_core guide")
  242. endif ()
  243. if (BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  244. # old version
  245. list(APPEND BLAS_SEARCH_LIBS
  246. "mkl_blas95 mkl_intel_${BLAS_mkl_ILP_MODE} mkl_intel_thread mkl_core guide")
  247. # mkl >= 10.3
  248. if (CMAKE_C_COMPILER MATCHES ".+gcc")
  249. list(APPEND BLAS_SEARCH_LIBS
  250. "mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_intel_${BLAS_mkl_ILP_MODE} mkl_gnu_thread mkl_core gomp")
  251. else ()
  252. list(APPEND BLAS_SEARCH_LIBS
  253. "mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_intel_${BLAS_mkl_ILP_MODE} mkl_intel_thread mkl_core iomp5")
  254. endif ()
  255. endif ()
  256. if (BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  257. list(APPEND BLAS_SEARCH_LIBS
  258. "mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_intel_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core")
  259. endif ()
  260. endif ()
  261. else ()
  262. set(BLAS_mkl_SEARCH_SYMBOL sgemm)
  263. set(_LIBRARIES BLAS_LIBRARIES)
  264. if (WIN32)
  265. # Find the main file (32-bit or 64-bit)
  266. set(BLAS_SEARCH_LIBS_WIN_MAIN "")
  267. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  268. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  269. "mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
  270. endif()
  271. if (BLA_VENDOR MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
  272. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  273. "mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
  274. endif ()
  275. # Add threading/sequential libs
  276. set(BLAS_SEARCH_LIBS_WIN_THREAD "")
  277. if (NOT BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
  278. # old version
  279. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  280. "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  281. # mkl >= 10.3
  282. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  283. "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  284. endif()
  285. if (BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
  286. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  287. "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
  288. endif()
  289. # Cartesian product of the above
  290. foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
  291. foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
  292. list(APPEND BLAS_SEARCH_LIBS
  293. "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
  294. endforeach()
  295. endforeach()
  296. else ()
  297. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  298. list(APPEND BLAS_SEARCH_LIBS
  299. "mkl_intel mkl_intel_thread mkl_core guide")
  300. endif ()
  301. if (BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  302. # old version
  303. list(APPEND BLAS_SEARCH_LIBS
  304. "mkl_intel_${BLAS_mkl_ILP_MODE} mkl_intel_thread mkl_core guide")
  305. # mkl >= 10.3
  306. if (CMAKE_C_COMPILER MATCHES ".+gcc")
  307. list(APPEND BLAS_SEARCH_LIBS
  308. "mkl_intel_${BLAS_mkl_ILP_MODE} mkl_gnu_thread mkl_core gomp")
  309. else ()
  310. list(APPEND BLAS_SEARCH_LIBS
  311. "mkl_intel_${BLAS_mkl_ILP_MODE} mkl_intel_thread mkl_core iomp5")
  312. endif ()
  313. endif ()
  314. if (BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  315. list(APPEND BLAS_SEARCH_LIBS
  316. "mkl_intel_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core")
  317. endif ()
  318. #older vesions of intel mkl libs
  319. if (BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
  320. list(APPEND BLAS_SEARCH_LIBS
  321. "mkl")
  322. list(APPEND BLAS_SEARCH_LIBS
  323. "mkl_ia32")
  324. list(APPEND BLAS_SEARCH_LIBS
  325. "mkl_em64t")
  326. endif ()
  327. endif ()
  328. endif ()
  329. foreach (IT ${BLAS_SEARCH_LIBS})
  330. string(REPLACE " " ";" SEARCH_LIBS ${IT})
  331. if (NOT ${_LIBRARIES})
  332. check_fortran_libraries(
  333. ${_LIBRARIES}
  334. BLAS
  335. ${BLAS_mkl_SEARCH_SYMBOL}
  336. ""
  337. "${SEARCH_LIBS}"
  338. "${CMAKE_THREAD_LIBS_INIT};${LM}"
  339. )
  340. endif ()
  341. endforeach ()
  342. endif ()
  343. unset(BLAS_mkl_ILP_MODE)
  344. endif ()
  345. endif ()
  346. if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
  347. if(NOT BLAS_LIBRARIES)
  348. # gotoblas (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
  349. check_fortran_libraries(
  350. BLAS_LIBRARIES
  351. BLAS
  352. sgemm
  353. ""
  354. "goto2"
  355. ""
  356. )
  357. endif()
  358. endif ()
  359. if (BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All")
  360. if(NOT BLAS_LIBRARIES)
  361. # OpenBLAS (http://www.openblas.net)
  362. check_fortran_libraries(
  363. BLAS_LIBRARIES
  364. BLAS
  365. sgemm
  366. ""
  367. "openblas"
  368. ""
  369. )
  370. endif()
  371. endif ()
  372. if (BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All")
  373. if(NOT BLAS_LIBRARIES)
  374. # FLAME's blis library (https://github.com/flame/blis)
  375. check_fortran_libraries(
  376. BLAS_LIBRARIES
  377. BLAS
  378. sgemm
  379. ""
  380. "blis"
  381. ""
  382. )
  383. endif()
  384. endif ()
  385. if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
  386. if(NOT BLAS_LIBRARIES)
  387. # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
  388. check_fortran_libraries(
  389. BLAS_LIBRARIES
  390. BLAS
  391. dgemm
  392. ""
  393. "f77blas;atlas"
  394. ""
  395. )
  396. endif()
  397. endif ()
  398. # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
  399. if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
  400. if(NOT BLAS_LIBRARIES)
  401. check_fortran_libraries(
  402. BLAS_LIBRARIES
  403. BLAS
  404. sgemm
  405. ""
  406. "sgemm;dgemm;blas"
  407. ""
  408. )
  409. endif()
  410. endif ()
  411. # BLAS in Alpha CXML library?
  412. if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
  413. if(NOT BLAS_LIBRARIES)
  414. check_fortran_libraries(
  415. BLAS_LIBRARIES
  416. BLAS
  417. sgemm
  418. ""
  419. "cxml"
  420. ""
  421. )
  422. endif()
  423. endif ()
  424. # BLAS in Alpha DXML library? (now called CXML, see above)
  425. if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
  426. if(NOT BLAS_LIBRARIES)
  427. check_fortran_libraries(
  428. BLAS_LIBRARIES
  429. BLAS
  430. sgemm
  431. ""
  432. "dxml"
  433. ""
  434. )
  435. endif()
  436. endif ()
  437. # BLAS in Sun Performance library?
  438. if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
  439. if(NOT BLAS_LIBRARIES)
  440. check_fortran_libraries(
  441. BLAS_LIBRARIES
  442. BLAS
  443. sgemm
  444. "-xlic_lib=sunperf"
  445. "sunperf;sunmath"
  446. ""
  447. )
  448. if(BLAS_LIBRARIES)
  449. set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
  450. endif()
  451. endif()
  452. endif ()
  453. # BLAS in SCSL library? (SGI/Cray Scientific Library)
  454. if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
  455. if(NOT BLAS_LIBRARIES)
  456. check_fortran_libraries(
  457. BLAS_LIBRARIES
  458. BLAS
  459. sgemm
  460. ""
  461. "scsl"
  462. ""
  463. )
  464. endif()
  465. endif ()
  466. # BLAS in SGIMATH library?
  467. if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
  468. if(NOT BLAS_LIBRARIES)
  469. check_fortran_libraries(
  470. BLAS_LIBRARIES
  471. BLAS
  472. sgemm
  473. ""
  474. "complib.sgimath"
  475. ""
  476. )
  477. endif()
  478. endif ()
  479. # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
  480. if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
  481. if(NOT BLAS_LIBRARIES)
  482. check_fortran_libraries(
  483. BLAS_LIBRARIES
  484. BLAS
  485. sgemm
  486. ""
  487. "essl;blas"
  488. ""
  489. )
  490. endif()
  491. endif ()
  492. #BLAS in acml library?
  493. if (BLA_VENDOR MATCHES "ACML" OR BLA_VENDOR STREQUAL "All")
  494. if( ((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
  495. ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
  496. ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS))
  497. )
  498. # try to find acml in "standard" paths
  499. if( WIN32 )
  500. file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" )
  501. else()
  502. file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
  503. endif()
  504. if( WIN32 )
  505. file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
  506. else()
  507. file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" )
  508. endif()
  509. list(GET _ACML_ROOT 0 _ACML_ROOT)
  510. list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
  511. if( _ACML_ROOT )
  512. get_filename_component( _ACML_ROOT ${_ACML_ROOT} PATH )
  513. if( SIZEOF_INTEGER EQUAL 8 )
  514. set( _ACML_PATH_SUFFIX "_int64" )
  515. else()
  516. set( _ACML_PATH_SUFFIX "" )
  517. endif()
  518. if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
  519. set( _ACML_COMPILER32 "ifort32" )
  520. set( _ACML_COMPILER64 "ifort64" )
  521. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
  522. set( _ACML_COMPILER32 "sun32" )
  523. set( _ACML_COMPILER64 "sun64" )
  524. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
  525. set( _ACML_COMPILER32 "pgi32" )
  526. if( WIN32 )
  527. set( _ACML_COMPILER64 "win64" )
  528. else()
  529. set( _ACML_COMPILER64 "pgi64" )
  530. endif()
  531. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Open64" )
  532. # 32 bit builds not supported on Open64 but for code simplicity
  533. # We'll just use the same directory twice
  534. set( _ACML_COMPILER32 "open64_64" )
  535. set( _ACML_COMPILER64 "open64_64" )
  536. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
  537. set( _ACML_COMPILER32 "nag32" )
  538. set( _ACML_COMPILER64 "nag64" )
  539. else()
  540. set( _ACML_COMPILER32 "gfortran32" )
  541. set( _ACML_COMPILER64 "gfortran64" )
  542. endif()
  543. if( BLA_VENDOR STREQUAL "ACML_MP" )
  544. set(_ACML_MP_LIB_DIRS
  545. "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
  546. "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib" )
  547. else()
  548. set(_ACML_LIB_DIRS
  549. "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
  550. "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib" )
  551. endif()
  552. endif()
  553. elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
  554. set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
  555. endif()
  556. if( BLA_VENDOR STREQUAL "ACML_MP" )
  557. foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
  558. check_fortran_libraries (
  559. BLAS_LIBRARIES
  560. BLAS
  561. sgemm
  562. "" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS}
  563. )
  564. if( BLAS_LIBRARIES )
  565. break()
  566. endif()
  567. endforeach()
  568. elseif( BLA_VENDOR STREQUAL "ACML_GPU" )
  569. foreach( BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
  570. check_fortran_libraries (
  571. BLAS_LIBRARIES
  572. BLAS
  573. sgemm
  574. "" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS}
  575. )
  576. if( BLAS_LIBRARIES )
  577. break()
  578. endif()
  579. endforeach()
  580. else()
  581. foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} )
  582. check_fortran_libraries (
  583. BLAS_LIBRARIES
  584. BLAS
  585. sgemm
  586. "" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS}
  587. )
  588. if( BLAS_LIBRARIES )
  589. break()
  590. endif()
  591. endforeach()
  592. endif()
  593. # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
  594. if(NOT BLAS_LIBRARIES)
  595. check_fortran_libraries(
  596. BLAS_LIBRARIES
  597. BLAS
  598. sgemm
  599. ""
  600. "acml;acml_mv"
  601. ""
  602. )
  603. endif()
  604. if(NOT BLAS_LIBRARIES)
  605. check_fortran_libraries(
  606. BLAS_LIBRARIES
  607. BLAS
  608. sgemm
  609. ""
  610. "acml_mp;acml_mv"
  611. ""
  612. )
  613. endif()
  614. if(NOT BLAS_LIBRARIES)
  615. check_fortran_libraries(
  616. BLAS_LIBRARIES
  617. BLAS
  618. sgemm
  619. ""
  620. "acml;acml_mv;CALBLAS"
  621. ""
  622. )
  623. endif()
  624. endif () # ACML
  625. # Apple BLAS library?
  626. if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  627. if(NOT BLAS_LIBRARIES)
  628. check_fortran_libraries(
  629. BLAS_LIBRARIES
  630. BLAS
  631. dgemm
  632. ""
  633. "Accelerate"
  634. ""
  635. )
  636. endif()
  637. endif ()
  638. if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  639. if ( NOT BLAS_LIBRARIES )
  640. check_fortran_libraries(
  641. BLAS_LIBRARIES
  642. BLAS
  643. dgemm
  644. ""
  645. "vecLib"
  646. ""
  647. )
  648. endif ()
  649. endif ()
  650. # Generic BLAS library?
  651. if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  652. if(NOT BLAS_LIBRARIES)
  653. check_fortran_libraries(
  654. BLAS_LIBRARIES
  655. BLAS
  656. sgemm
  657. ""
  658. "blas"
  659. ""
  660. )
  661. endif()
  662. endif ()
  663. if(BLA_F95)
  664. find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS95_LIBRARIES)
  665. set(BLAS95_FOUND ${BLAS_FOUND})
  666. if(BLAS_FOUND)
  667. set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
  668. endif()
  669. else()
  670. find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS_LIBRARIES)
  671. endif()
  672. # On compilers that implicitly link BLAS (such as ftn, cc, and CC on Cray HPC machines)
  673. # we used a placeholder for empty BLAS_LIBRARIES to get through our logic above.
  674. if (BLAS_LIBRARIES STREQUAL "BLAS_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
  675. set(BLAS_LIBRARIES "")
  676. endif()
  677. cmake_pop_check_state()
  678. set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})