FindBLAS.cmake 20 KB

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