FindLAPACK.cmake 21 KB

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