FindLAPACK.cmake 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. FindLAPACK
  5. ----------
  6. Find Linear Algebra PACKage (LAPACK) library
  7. This module finds an installed Fortran library that implements the
  8. `LAPACK linear-algebra interface`_.
  9. At least one of the ``C``, ``CXX``, or ``Fortran`` languages must be enabled.
  10. .. _`LAPACK linear-algebra interface`: http://www.netlib.org/lapack/
  11. Input Variables
  12. ^^^^^^^^^^^^^^^
  13. The following variables may be set to influence this module's behavior:
  14. ``BLA_STATIC``
  15. if ``ON`` use static linkage
  16. ``BLA_VENDOR``
  17. Set to one of the :ref:`BLAS/LAPACK Vendors` to search for BLAS only
  18. from the specified vendor. If not set, all vendors are considered.
  19. ``BLA_F95``
  20. if ``ON`` tries to find the BLAS95/LAPACK95 interfaces
  21. ``BLA_PREFER_PKGCONFIG``
  22. .. versionadded:: 3.20
  23. if set ``pkg-config`` will be used to search for a LAPACK library first
  24. and if one is found that is preferred
  25. Imported targets
  26. ^^^^^^^^^^^^^^^^
  27. This module defines the following :prop_tgt:`IMPORTED` targets:
  28. ``LAPACK::LAPACK``
  29. .. versionadded:: 3.18
  30. The libraries to use for LAPACK, if found.
  31. Result Variables
  32. ^^^^^^^^^^^^^^^^
  33. This module defines the following variables:
  34. ``LAPACK_FOUND``
  35. library implementing the LAPACK interface is found
  36. ``LAPACK_LINKER_FLAGS``
  37. uncached list of required linker flags (excluding ``-l`` and ``-L``).
  38. ``LAPACK_LIBRARIES``
  39. uncached list of libraries (using full path name) to link against
  40. to use LAPACK
  41. ``LAPACK95_LIBRARIES``
  42. uncached list of libraries (using full path name) to link against
  43. to use LAPACK95
  44. ``LAPACK95_FOUND``
  45. library implementing the LAPACK95 interface is found
  46. Intel MKL
  47. ^^^^^^^^^
  48. To use the Intel MKL implementation of LAPACK, a project must enable at least
  49. one of the ``C`` or ``CXX`` languages. Set ``BLA_VENDOR`` to an Intel MKL
  50. variant either on the command-line as ``-DBLA_VENDOR=Intel10_64lp`` or in
  51. project code:
  52. .. code-block:: cmake
  53. set(BLA_VENDOR Intel10_64lp)
  54. find_package(LAPACK)
  55. In order to build a project using Intel MKL, and end user must first
  56. establish an Intel MKL environment. See the :module:`FindBLAS` module
  57. section on :ref:`Intel MKL` for details.
  58. #]=======================================================================]
  59. # The approach follows that of the ``autoconf`` macro file, ``acx_lapack.m4``
  60. # (distributed at http://ac-archive.sourceforge.net/ac-archive/acx_lapack.html).
  61. if(CMAKE_Fortran_COMPILER_LOADED)
  62. include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake)
  63. else()
  64. include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
  65. endif()
  66. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  67. function(_add_lapack_target)
  68. if(LAPACK_FOUND AND NOT TARGET LAPACK::LAPACK)
  69. add_library(LAPACK::LAPACK INTERFACE IMPORTED)
  70. # Filter out redundant BLAS info and replace with the BLAS target
  71. set(_lapack_libs "${LAPACK_LIBRARIES}")
  72. set(_lapack_flags "${LAPACK_LINKER_FLAGS}")
  73. if(TARGET BLAS::BLAS)
  74. if(_lapack_libs AND BLAS_LIBRARIES)
  75. foreach(_blas_lib IN LISTS BLAS_LIBRARIES)
  76. list(REMOVE_ITEM _lapack_libs "${_blas_lib}")
  77. endforeach()
  78. endif()
  79. if(_lapack_flags AND BLAS_LINKER_FLAGS)
  80. foreach(_blas_flag IN LISTS BLAS_LINKER_FLAGS)
  81. list(REMOVE_ITEM _lapack_flags "${_blas_flag}")
  82. endforeach()
  83. endif()
  84. list(APPEND _lapack_libs BLAS::BLAS)
  85. endif()
  86. if(_lapack_libs)
  87. set_target_properties(LAPACK::LAPACK PROPERTIES
  88. INTERFACE_LINK_LIBRARIES "${_lapack_libs}"
  89. )
  90. endif()
  91. if(_lapack_flags)
  92. set_target_properties(LAPACK::LAPACK PROPERTIES
  93. INTERFACE_LINK_OPTIONS "${_lapack_flags}"
  94. )
  95. endif()
  96. endif()
  97. endfunction()
  98. # TODO: move this stuff to a separate module
  99. function(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir _subdirs _blas)
  100. # This function checks for the existence of the combination of libraries
  101. # given by _list. If the combination is found, this checks whether can link
  102. # against that library combination using the name of a routine given by _name
  103. # using the linker flags given by _flags. If the combination of libraries is
  104. # found and passes the link test, ${LIBRARIES} is set to the list of complete
  105. # library paths that have been found. Otherwise, ${LIBRARIES} is set to FALSE.
  106. set(_libraries_work TRUE)
  107. set(_libraries)
  108. set(_combined_name)
  109. if(BLA_STATIC)
  110. if(WIN32)
  111. set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
  112. else()
  113. set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  114. endif()
  115. else()
  116. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  117. # for ubuntu's libblas3gf and liblapack3gf packages
  118. set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
  119. endif()
  120. endif()
  121. set(_extaddlibdir "${_addlibdir}")
  122. if(WIN32)
  123. list(APPEND _extaddlibdir ENV LIB)
  124. elseif(APPLE)
  125. list(APPEND _extaddlibdir ENV DYLD_LIBRARY_PATH)
  126. else()
  127. list(APPEND _extaddlibdir ENV LD_LIBRARY_PATH)
  128. endif()
  129. list(APPEND _extaddlibdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
  130. foreach(_library ${_list})
  131. if(_library MATCHES "^-")
  132. # Respect linker flags as-is (required by MKL)
  133. list(APPEND _libraries "${_library}")
  134. else()
  135. string(REGEX REPLACE "[^A-Za-z0-9]" "_" _lib_var "${_library}")
  136. set(_combined_name ${_combined_name}_${_lib_var})
  137. if(NOT "${_deps}" STREQUAL "")
  138. set(_combined_name ${_combined_name}_deps)
  139. endif()
  140. if(_libraries_work)
  141. find_library(${_prefix}_${_lib_var}_LIBRARY
  142. NAMES ${_library}
  143. NAMES_PER_DIR
  144. PATHS ${_extaddlibdir}
  145. PATH_SUFFIXES ${_subdirs}
  146. )
  147. mark_as_advanced(${_prefix}_${_lib_var}_LIBRARY)
  148. list(APPEND _libraries ${${_prefix}_${_lib_var}_LIBRARY})
  149. set(_libraries_work ${${_prefix}_${_lib_var}_LIBRARY})
  150. endif()
  151. endif()
  152. endforeach()
  153. foreach(_flag ${_flags})
  154. string(REGEX REPLACE "[^A-Za-z0-9]" "_" _flag_var "${_flag}")
  155. set(_combined_name ${_combined_name}_${_flag_var})
  156. endforeach()
  157. if(_libraries_work)
  158. # Test this combination of libraries.
  159. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${_libraries} ${_blas} ${_deps})
  160. set(CMAKE_REQUIRED_QUIET ${LAPACK_FIND_QUIETLY})
  161. if(CMAKE_Fortran_COMPILER_LOADED)
  162. check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
  163. else()
  164. check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
  165. endif()
  166. set(CMAKE_REQUIRED_LIBRARIES)
  167. set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
  168. endif()
  169. if(_libraries_work)
  170. if("${_list}${_blas}" STREQUAL "")
  171. set(_libraries "${LIBRARIES}-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
  172. else()
  173. list(APPEND _libraries ${_blas} ${_deps})
  174. endif()
  175. else()
  176. set(_libraries FALSE)
  177. endif()
  178. set(${LIBRARIES} "${_libraries}" PARENT_SCOPE)
  179. endfunction()
  180. macro(_lapack_find_dependency dep)
  181. set(_lapack_quiet_arg)
  182. if(LAPACK_FIND_QUIETLY)
  183. set(_lapack_quiet_arg QUIET)
  184. endif()
  185. set(_lapack_required_arg)
  186. if(LAPACK_FIND_REQUIRED)
  187. set(_lapack_required_arg REQUIRED)
  188. endif()
  189. find_package(${dep} ${ARGN}
  190. ${_lapack_quiet_arg}
  191. ${_lapack_required_arg}
  192. )
  193. if (NOT ${dep}_FOUND)
  194. set(LAPACK_NOT_FOUND_MESSAGE "LAPACK could not be found because dependency ${dep} could not be found.")
  195. endif()
  196. set(_lapack_required_arg)
  197. set(_lapack_quiet_arg)
  198. endmacro()
  199. set(LAPACK_LINKER_FLAGS)
  200. set(LAPACK_LIBRARIES)
  201. set(LAPACK95_LIBRARIES)
  202. set(_lapack_fphsa_req_var LAPACK_LIBRARIES)
  203. # Check the language being used
  204. if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED))
  205. set(LAPACK_NOT_FOUND_MESSAGE
  206. "FindLAPACK requires Fortran, C, or C++ to be enabled.")
  207. endif()
  208. # Load BLAS
  209. if(NOT LAPACK_NOT_FOUND_MESSAGE)
  210. _lapack_find_dependency(BLAS)
  211. endif()
  212. # Search with pkg-config if specified
  213. if(BLA_PREFER_PKGCONFIG)
  214. find_package(PkgConfig)
  215. pkg_check_modules(PKGC_LAPACK lapack)
  216. if(PKGC_LAPACK_FOUND)
  217. set(LAPACK_FOUND TRUE)
  218. set(LAPACK_LIBRARIES "${PKGC_LAPACK_LINK_LIBRARIES}")
  219. if (BLAS_LIBRARIES)
  220. list(APPEND LAPACK_LIBRARIES "${BLAS_LIBRARIES}")
  221. endif()
  222. _add_lapack_target()
  223. return()
  224. endif()
  225. endif()
  226. # Search for different LAPACK distributions if BLAS is found
  227. if(NOT LAPACK_NOT_FOUND_MESSAGE)
  228. set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
  229. if(NOT $ENV{BLA_VENDOR} STREQUAL "")
  230. set(BLA_VENDOR $ENV{BLA_VENDOR})
  231. elseif(NOT BLA_VENDOR)
  232. set(BLA_VENDOR "All")
  233. endif()
  234. # LAPACK in the Intel MKL 10+ library?
  235. if(NOT LAPACK_LIBRARIES
  236. AND (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
  237. AND (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
  238. # System-specific settings
  239. if(NOT WIN32)
  240. set(LAPACK_mkl_LM "-lm")
  241. set(LAPACK_mkl_LDL "-ldl")
  242. endif()
  243. _lapack_find_dependency(Threads)
  244. if(BLA_VENDOR MATCHES "_64ilp")
  245. set(LAPACK_mkl_ILP_MODE "ilp64")
  246. else()
  247. set(LAPACK_mkl_ILP_MODE "lp64")
  248. endif()
  249. set(LAPACK_SEARCH_LIBS "")
  250. if(BLA_F95)
  251. set(LAPACK_mkl_SEARCH_SYMBOL "cheev_f95")
  252. set(_LAPACK_LIBRARIES LAPACK95_LIBRARIES)
  253. set(_BLAS_LIBRARIES ${BLAS95_LIBRARIES})
  254. # old
  255. list(APPEND LAPACK_SEARCH_LIBS
  256. "mkl_lapack95")
  257. # new >= 10.3
  258. list(APPEND LAPACK_SEARCH_LIBS
  259. "mkl_intel_c")
  260. list(APPEND LAPACK_SEARCH_LIBS
  261. "mkl_lapack95_${LAPACK_mkl_ILP_MODE}")
  262. else()
  263. set(LAPACK_mkl_SEARCH_SYMBOL "cheev")
  264. set(_LAPACK_LIBRARIES LAPACK_LIBRARIES)
  265. set(_BLAS_LIBRARIES ${BLAS_LIBRARIES})
  266. # old and new >= 10.3
  267. list(APPEND LAPACK_SEARCH_LIBS
  268. "mkl_lapack")
  269. endif()
  270. # MKL uses a multitude of partially platform-specific subdirectories:
  271. if(BLA_VENDOR STREQUAL "Intel10_32")
  272. set(LAPACK_mkl_ARCH_NAME "ia32")
  273. else()
  274. set(LAPACK_mkl_ARCH_NAME "intel64")
  275. endif()
  276. if(WIN32)
  277. set(LAPACK_mkl_OS_NAME "win")
  278. elseif(APPLE)
  279. set(LAPACK_mkl_OS_NAME "mac")
  280. else()
  281. set(LAPACK_mkl_OS_NAME "lin")
  282. endif()
  283. if(DEFINED ENV{MKLROOT})
  284. file(TO_CMAKE_PATH "$ENV{MKLROOT}" LAPACK_mkl_MKLROOT)
  285. # If MKLROOT points to the subdirectory 'mkl', use the parent directory instead
  286. # so we can better detect other relevant libraries in 'compiler' or 'tbb':
  287. get_filename_component(LAPACK_mkl_MKLROOT_LAST_DIR "${LAPACK_mkl_MKLROOT}" NAME)
  288. if(LAPACK_mkl_MKLROOT_LAST_DIR STREQUAL "mkl")
  289. get_filename_component(LAPACK_mkl_MKLROOT "${LAPACK_mkl_MKLROOT}" DIRECTORY)
  290. endif()
  291. endif()
  292. set(LAPACK_mkl_LIB_PATH_SUFFIXES
  293. "compiler/lib" "compiler/lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}"
  294. "compiler/lib/${LAPACK_mkl_ARCH_NAME}"
  295. "mkl/lib" "mkl/lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}"
  296. "mkl/lib/${LAPACK_mkl_ARCH_NAME}"
  297. "lib" "lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}"
  298. "lib/${LAPACK_mkl_ARCH_NAME}"
  299. )
  300. # First try empty lapack libs (implicitly linked or automatic from BLAS)
  301. if(NOT ${_LAPACK_LIBRARIES})
  302. check_lapack_libraries(
  303. ${_LAPACK_LIBRARIES}
  304. LAPACK
  305. ${LAPACK_mkl_SEARCH_SYMBOL}
  306. ""
  307. ""
  308. "${CMAKE_THREAD_LIBS_INIT};${LAPACK_mkl_LM};${LAPACK_mkl_LDL}"
  309. "${LAPACK_mkl_MKLROOT}"
  310. "${LAPACK_mkl_LIB_PATH_SUFFIXES}"
  311. "${_BLAS_LIBRARIES}"
  312. )
  313. if(LAPACK_WORKS AND NOT _BLAS_LIBRARIES)
  314. # Give a more helpful "found" message
  315. set(LAPACK_WORKS "implicitly linked")
  316. set(_lapack_fphsa_req_var LAPACK_WORKS)
  317. endif()
  318. endif()
  319. # Then try the search libs
  320. foreach(_search ${LAPACK_SEARCH_LIBS})
  321. string(REPLACE " " ";" _search ${_search})
  322. if(NOT ${_LAPACK_LIBRARIES})
  323. check_lapack_libraries(
  324. ${_LAPACK_LIBRARIES}
  325. LAPACK
  326. ${LAPACK_mkl_SEARCH_SYMBOL}
  327. ""
  328. "${_search}"
  329. "${CMAKE_THREAD_LIBS_INIT};${LAPACK_mkl_LM};${LAPACK_mkl_LDL}"
  330. "${LAPACK_mkl_MKLROOT}"
  331. "${LAPACK_mkl_LIB_PATH_SUFFIXES}"
  332. "${_BLAS_LIBRARIES}"
  333. )
  334. endif()
  335. endforeach()
  336. unset(_search)
  337. unset(LAPACK_mkl_ILP_MODE)
  338. unset(LAPACK_mkl_SEARCH_SYMBOL)
  339. unset(LAPACK_mkl_LM)
  340. unset(LAPACK_mkl_LDL)
  341. unset(LAPACK_mkl_MKLROOT)
  342. unset(LAPACK_mkl_ARCH_NAME)
  343. unset(LAPACK_mkl_OS_NAME)
  344. unset(LAPACK_mkl_LIB_PATH_SUFFIXES)
  345. endif()
  346. # gotoblas? (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
  347. if(NOT LAPACK_LIBRARIES
  348. AND (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All"))
  349. check_lapack_libraries(
  350. LAPACK_LIBRARIES
  351. LAPACK
  352. cheev
  353. ""
  354. "goto2"
  355. ""
  356. ""
  357. ""
  358. "${BLAS_LIBRARIES}"
  359. )
  360. endif()
  361. # FlexiBLAS? (http://www.mpi-magdeburg.mpg.de/mpcsc/software/FlexiBLAS/)
  362. if(NOT LAPACK_LIBRARIES
  363. AND (BLA_VENDOR STREQUAL "FlexiBLAS" OR BLA_VENDOR STREQUAL "All"))
  364. check_lapack_libraries(
  365. LAPACK_LIBRARIES
  366. LAPACK
  367. cheev
  368. ""
  369. "flexiblas"
  370. ""
  371. ""
  372. ""
  373. "${BLAS_LIBRARIES}"
  374. )
  375. endif()
  376. # OpenBLAS? (http://www.openblas.net)
  377. if(NOT LAPACK_LIBRARIES
  378. AND (BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All"))
  379. check_lapack_libraries(
  380. LAPACK_LIBRARIES
  381. LAPACK
  382. cheev
  383. ""
  384. "openblas"
  385. ""
  386. ""
  387. ""
  388. "${BLAS_LIBRARIES}"
  389. )
  390. endif()
  391. # ArmPL? (https://developer.arm.com/tools-and-software/server-and-hpc/compile/arm-compiler-for-linux/arm-performance-libraries)
  392. if(NOT LAPACK_LIBRARIES
  393. AND (BLA_VENDOR MATCHES "Arm" OR BLA_VENDOR STREQUAL "All"))
  394. # Check for 64bit Integer support
  395. if(BLA_VENDOR MATCHES "_ilp64")
  396. set(LAPACK_armpl_LIB "armpl_ilp64")
  397. else()
  398. set(LAPACK_armpl_LIB "armpl_lp64")
  399. endif()
  400. # Check for OpenMP support, VIA BLA_VENDOR of Arm_mp or Arm_ipl64_mp
  401. if(BLA_VENDOR MATCHES "_mp")
  402. set(LAPACK_armpl_LIB "${LAPACK_armpl_LIB}_mp")
  403. endif()
  404. check_lapack_libraries(
  405. LAPACK_LIBRARIES
  406. LAPACK
  407. cheev
  408. ""
  409. "${LAPACK_armpl_LIB}"
  410. ""
  411. ""
  412. ""
  413. "${BLAS_LIBRARIES}"
  414. )
  415. endif()
  416. # FLAME's blis library? (https://github.com/flame/blis)
  417. if(NOT LAPACK_LIBRARIES
  418. AND (BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All"))
  419. check_lapack_libraries(
  420. LAPACK_LIBRARIES
  421. LAPACK
  422. cheev
  423. ""
  424. "flame"
  425. ""
  426. ""
  427. ""
  428. "${BLAS_LIBRARIES}"
  429. )
  430. endif()
  431. # BLAS in acml library?
  432. if(BLA_VENDOR MATCHES "ACML" OR BLA_VENDOR STREQUAL "All")
  433. if(BLAS_LIBRARIES MATCHES ".+acml.+")
  434. set(LAPACK_LIBRARIES ${BLAS_LIBRARIES})
  435. endif()
  436. endif()
  437. # Apple LAPACK library?
  438. if(NOT LAPACK_LIBRARIES
  439. AND (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All"))
  440. check_lapack_libraries(
  441. LAPACK_LIBRARIES
  442. LAPACK
  443. cheev
  444. ""
  445. "Accelerate"
  446. ""
  447. ""
  448. ""
  449. "${BLAS_LIBRARIES}"
  450. )
  451. endif()
  452. # Apple NAS (vecLib) library?
  453. if(NOT LAPACK_LIBRARIES
  454. AND (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All"))
  455. check_lapack_libraries(
  456. LAPACK_LIBRARIES
  457. LAPACK
  458. cheev
  459. ""
  460. "vecLib"
  461. ""
  462. ""
  463. ""
  464. "${BLAS_LIBRARIES}"
  465. )
  466. endif()
  467. # Elbrus Math Library?
  468. if(NOT LAPACK_LIBRARIES
  469. AND (BLA_VENDOR MATCHES "EML" OR BLA_VENDOR STREQUAL "All"))
  470. set(LAPACK_EML_LIB "eml")
  471. # Check for OpenMP support, VIA BLA_VENDOR of eml_mt
  472. if(BLA_VENDOR MATCHES "_mt")
  473. set(LAPACK_EML_LIB "${LAPACK_EML_LIB}_mt")
  474. endif()
  475. check_lapack_libraries(
  476. LAPACK_LIBRARIES
  477. LAPACK
  478. cheev
  479. ""
  480. "${LAPACK_EML_LIB}"
  481. ""
  482. ""
  483. ""
  484. "${BLAS_LIBRARIES}"
  485. )
  486. endif()
  487. # Fujitsu SSL2 Library?
  488. if(NOT LAPACK_LIBRARIES
  489. AND (BLA_VENDOR MATCHES "Fujitsu_SSL2" OR BLA_VENDOR STREQUAL "All"))
  490. if(BLA_VENDOR STREQUAL "Fujitsu_SSL2BLAMP")
  491. set(_ssl2_suffix BLAMP)
  492. else()
  493. set(_ssl2_suffix)
  494. endif()
  495. set(_ssl2_blas)
  496. if(BLAS_LIBRARIES STREQUAL "")
  497. set(_ssl2_blas "${BLAS_LINKER_FLAGS}")
  498. else()
  499. set(_ssl2_blas "${BLAS_LIBRARIES} ${BLAS_LINKER_FLAGS}")
  500. endif()
  501. check_lapack_libraries(
  502. LAPACK_LIBRARIES
  503. LAPACK
  504. cheev
  505. "-SSL2${_ssl2_suffix}"
  506. ""
  507. ""
  508. ""
  509. ""
  510. "${_ssl2_blas}"
  511. )
  512. if(LAPACK_LIBRARIES)
  513. set(LAPACK_LINKER_FLAGS "-SSL2${_ssl2_suffix}")
  514. set(_lapack_fphsa_req_var LAPACK_LINKER_FLAGS)
  515. endif()
  516. unset(_ssl2_suffix)
  517. endif()
  518. # NVHPC Library?
  519. if(NOT LAPACK_LIBRARIES
  520. AND (BLA_VENDOR MATCHES "NVHPC" OR BLA_VENDOR STREQUAL "All"))
  521. check_lapack_libraries(
  522. LAPACK_LIBRARIES
  523. LAPACK
  524. cheev
  525. ""
  526. "lapack"
  527. "-fortranlibs"
  528. ""
  529. ""
  530. "${BLAS_LIBRARIES}"
  531. )
  532. endif()
  533. # Generic LAPACK library?
  534. if(NOT LAPACK_LIBRARIES
  535. AND (BLA_VENDOR STREQUAL "Generic"
  536. OR BLA_VENDOR STREQUAL "ATLAS"
  537. OR BLA_VENDOR STREQUAL "All"))
  538. if(BLA_STATIC)
  539. # We do not know for sure how the LAPACK reference implementation
  540. # is built on this host. Guess typical dependencies.
  541. set(_lapack_generic_deps "-lgfortran;-lm")
  542. else()
  543. set(_lapack_generic_deps "")
  544. endif()
  545. check_lapack_libraries(
  546. LAPACK_LIBRARIES
  547. LAPACK
  548. cheev
  549. ""
  550. "lapack"
  551. "${_lapack_generic_deps}"
  552. ""
  553. ""
  554. "${BLAS_LIBRARIES}"
  555. )
  556. unset(_lapack_generic_deps)
  557. endif()
  558. endif()
  559. if(BLA_F95)
  560. set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}")
  561. endif()
  562. if(LAPACK_NOT_FOUND_MESSAGE)
  563. set(LAPACK_NOT_FOUND_MESSAGE
  564. REASON_FAILURE_MESSAGE ${LAPACK_NOT_FOUND_MESSAGE})
  565. endif()
  566. find_package_handle_standard_args(LAPACK REQUIRED_VARS ${_lapack_fphsa_req_var}
  567. ${LAPACK_NOT_FOUND_MESSAGE})
  568. unset(LAPACK_NOT_FOUND_MESSAGE)
  569. if(BLA_F95)
  570. set(LAPACK95_FOUND ${LAPACK_FOUND})
  571. endif()
  572. # On compilers that implicitly link LAPACK (such as ftn, cc, and CC on Cray HPC machines)
  573. # we used a placeholder for empty LAPACK_LIBRARIES to get through our logic above.
  574. if(LAPACK_LIBRARIES STREQUAL "LAPACK_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
  575. set(LAPACK_LIBRARIES "")
  576. endif()
  577. _add_lapack_target()
  578. unset(_lapack_fphsa_req_var)
  579. unset(_LAPACK_LIBRARIES)