FindLAPACK.cmake 22 KB

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