FindBLAS.cmake 19 KB

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