FindBLAS.cmake 22 KB

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