FindBLAS.cmake 23 KB

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