FindBLAS.cmake 19 KB

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