FindBLAS.cmake 24 KB

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