FindBLAS.cmake 19 KB

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