FindLAPACK.cmake 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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 (see http://www.netlib.org/lapack/).
  9. The approach follows that taken for the ``autoconf`` macro file,
  10. ``acx_lapack.m4`` (distributed at
  11. http://ac-archive.sourceforge.net/ac-archive/acx_lapack.html).
  12. Input Variables
  13. ^^^^^^^^^^^^^^^
  14. The following variables may be set to influence this module's behavior:
  15. ``BLA_STATIC``
  16. if ``ON`` use static linkage
  17. ``BLA_VENDOR``
  18. If set, checks only the specified vendor, if not set checks all the
  19. possibilities. List of vendors valid in this module:
  20. * ``FlexiBLAS``
  21. * ``OpenBLAS``
  22. * ``FLAME``
  23. * ``Intel10_32`` (intel mkl v10 32 bit, threaded code)
  24. * ``Intel10_64lp`` (intel mkl v10+ 64 bit, threaded code, lp64 model)
  25. * ``Intel10_64lp_seq`` (intel mkl v10+ 64 bit, sequential code, lp64 model)
  26. * ``Intel10_64ilp`` (intel mkl v10+ 64 bit, threaded code, ilp64 model)
  27. * ``Intel10_64ilp_seq`` (intel mkl v10+ 64 bit, sequential code, ilp64 model)
  28. * ``Intel10_64_dyn`` (intel mkl v10+ 64 bit, single dynamic library)
  29. * ``Intel`` (obsolete versions of mkl 32 and 64 bit)
  30. * ``ACML``
  31. * ``Apple``
  32. * ``NAS``
  33. * ``Arm``
  34. * ``Arm_mp``
  35. * ``Arm_ilp64``
  36. * ``Arm_ilp64_mp``
  37. * ``Generic``
  38. .. versionadded:: 3.6
  39. ``OpenBLAS`` support.
  40. .. versionadded:: 3.11
  41. ``FLAME`` support.
  42. .. versionadded:: 3.13
  43. Added ILP64 MKL variants (``Intel10_64ilp``, ``Intel10_64ilp_seq``).
  44. .. versionadded:: 3.17
  45. Added single dynamic library MKL variant (``Intel10_64_dyn``).
  46. .. versionadded:: 3.18
  47. Arm Performance Libraries support (``Arm``, ``Arm_mp``, ``Arm_ilp64``,
  48. ``Arm_ilp64_mp``).
  49. .. versionadded:: 3.19
  50. ``FlexiBLAS`` support.
  51. ``BLA_F95``
  52. if ``ON`` tries to find the BLAS95/LAPACK95 interfaces
  53. Imported targets
  54. ^^^^^^^^^^^^^^^^
  55. .. versionadded:: 3.18
  56. This module defines the following :prop_tgt:`IMPORTED` target:
  57. ``LAPACK::LAPACK``
  58. The libraries to use for LAPACK, if found.
  59. Result Variables
  60. ^^^^^^^^^^^^^^^^
  61. This module defines the following variables:
  62. ``LAPACK_FOUND``
  63. library implementing the LAPACK interface is found
  64. ``LAPACK_LINKER_FLAGS``
  65. uncached list of required linker flags (excluding ``-l`` and ``-L``).
  66. ``LAPACK_LIBRARIES``
  67. uncached list of libraries (using full path name) to link against
  68. to use LAPACK
  69. ``LAPACK95_LIBRARIES``
  70. uncached list of libraries (using full path name) to link against
  71. to use LAPACK95
  72. ``LAPACK95_FOUND``
  73. library implementing the LAPACK95 interface is found
  74. .. note::
  75. C, CXX or Fortran must be enabled to detect a BLAS/LAPACK library.
  76. C or CXX must be enabled to use Intel Math Kernel Library (MKL).
  77. For example, to use Intel MKL libraries and/or Intel compiler:
  78. .. code-block:: cmake
  79. set(BLA_VENDOR Intel10_64lp)
  80. find_package(LAPACK)
  81. #]=======================================================================]
  82. if(CMAKE_Fortran_COMPILER_LOADED)
  83. include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake)
  84. else()
  85. include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
  86. endif()
  87. include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
  88. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  89. macro(_lapack_find_library_setup)
  90. cmake_push_check_state()
  91. set(CMAKE_REQUIRED_QUIET ${LAPACK_FIND_QUIETLY})
  92. set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  93. if(BLA_STATIC)
  94. if(WIN32)
  95. set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
  96. else()
  97. set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  98. endif()
  99. else()
  100. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  101. # for ubuntu's libblas3gf and liblapack3gf packages
  102. set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
  103. endif()
  104. endif()
  105. endmacro()
  106. macro(_lapack_find_library_teardown)
  107. set(CMAKE_FIND_LIBRARY_SUFFIXES ${_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
  108. unset(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
  109. cmake_pop_check_state()
  110. endmacro()
  111. # TODO: move this stuff to a separate module
  112. macro(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _threadlibs _addlibdir _subdirs _blas)
  113. # This macro checks for the existence of the combination of fortran libraries
  114. # given by _list. If the combination is found, this macro checks (using the
  115. # Check_Fortran_Function_Exists macro) whether can link against that library
  116. # combination using the name of a routine given by _name using the linker
  117. # flags given by _flags. If the combination of libraries is found and passes
  118. # the link test, LIBRARIES is set to the list of complete library paths that
  119. # have been found. Otherwise, LIBRARIES is set to FALSE.
  120. # N.B. _prefix is the prefix applied to the names of all cached variables that
  121. # are generated internally and marked advanced by this macro.
  122. # _addlibdir is a list of additional search paths. _subdirs is a list of path
  123. # suffixes to be used by find_library().
  124. set(_libraries_work TRUE)
  125. set(${LIBRARIES})
  126. set(_combined_name)
  127. set(_extaddlibdir "${_addlibdir}")
  128. if(WIN32)
  129. list(APPEND _extaddlibdir ENV LIB)
  130. elseif(APPLE)
  131. list(APPEND _extaddlibdir ENV DYLD_LIBRARY_PATH)
  132. else()
  133. list(APPEND _extaddlibdir ENV LD_LIBRARY_PATH)
  134. endif()
  135. list(APPEND _extaddlibdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
  136. foreach(_library ${_list})
  137. if(_library MATCHES "^-Wl,--(start|end)-group$")
  138. # Respect linker flags like --start/end-group (required by MKL)
  139. set(${LIBRARIES} ${${LIBRARIES}} "${_library}")
  140. else()
  141. set(_combined_name ${_combined_name}_${_library})
  142. if(_libraries_work)
  143. find_library(${_prefix}_${_library}_LIBRARY
  144. NAMES ${_library}
  145. NAMES_PER_DIR
  146. PATHS ${_extaddlibdir}
  147. PATH_SUFFIXES ${_subdirs}
  148. )
  149. #message("DEBUG: find_library(${_library}) got ${${_prefix}_${_library}_LIBRARY}")
  150. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  151. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  152. set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
  153. endif()
  154. endif()
  155. endforeach()
  156. unset(_library)
  157. if(_libraries_work)
  158. # Test this combination of libraries.
  159. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_threadlibs})
  160. #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  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. set(${LIBRARIES} ${${LIBRARIES}} ${_blas} ${_threadlibs})
  174. endif()
  175. else()
  176. set(${LIBRARIES} FALSE)
  177. endif()
  178. unset(_extaddlibdir)
  179. unset(_libraries_work)
  180. unset(_combined_name)
  181. #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
  182. endmacro()
  183. macro(_lapack_find_dependency dep)
  184. set(_lapack_quiet_arg)
  185. if(LAPACK_FIND_QUIETLY)
  186. set(_lapack_quiet_arg QUIET)
  187. endif()
  188. set(_lapack_required_arg)
  189. if(LAPACK_FIND_REQUIRED)
  190. set(_lapack_required_arg REQUIRED)
  191. endif()
  192. find_package(${dep} ${ARGN}
  193. ${_lapack_quiet_arg}
  194. ${_lapack_required_arg}
  195. )
  196. if (NOT ${dep}_FOUND)
  197. set(LAPACK_NOT_FOUND_MESSAGE "LAPACK could not be found because dependency ${dep} could not be found.")
  198. endif()
  199. set(_lapack_required_arg)
  200. set(_lapack_quiet_arg)
  201. endmacro()
  202. _lapack_find_library_setup()
  203. set(LAPACK_LINKER_FLAGS)
  204. set(LAPACK_LIBRARIES)
  205. set(LAPACK95_LIBRARIES)
  206. # Check the language being used
  207. if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED))
  208. set(LAPACK_NOT_FOUND_MESSAGE
  209. "FindLAPACK requires Fortran, C, or C++ to be enabled.")
  210. endif()
  211. # Load BLAS
  212. if(NOT LAPACK_NOT_FOUND_MESSAGE)
  213. _lapack_find_dependency(BLAS)
  214. endif()
  215. # Search for different LAPACK distributions if BLAS is found
  216. if(NOT LAPACK_NOT_FOUND_MESSAGE)
  217. set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
  218. if(NOT $ENV{BLA_VENDOR} STREQUAL "")
  219. set(BLA_VENDOR $ENV{BLA_VENDOR})
  220. elseif(NOT BLA_VENDOR)
  221. set(BLA_VENDOR "All")
  222. endif()
  223. # LAPACK in the Intel MKL 10+ library?
  224. if(NOT LAPACK_LIBRARIES
  225. AND (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
  226. AND (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
  227. # System-specific settings
  228. if(NOT WIN32)
  229. set(LAPACK_mkl_LM "-lm")
  230. set(LAPACK_mkl_LDL "-ldl")
  231. endif()
  232. _lapack_find_dependency(Threads)
  233. if(BLA_VENDOR MATCHES "_64ilp")
  234. set(LAPACK_mkl_ILP_MODE "ilp64")
  235. else()
  236. set(LAPACK_mkl_ILP_MODE "lp64")
  237. endif()
  238. set(LAPACK_SEARCH_LIBS "")
  239. if(BLA_F95)
  240. set(LAPACK_mkl_SEARCH_SYMBOL "cheev_f95")
  241. set(_LIBRARIES LAPACK95_LIBRARIES)
  242. set(_BLAS_LIBRARIES ${BLAS95_LIBRARIES})
  243. # old
  244. list(APPEND LAPACK_SEARCH_LIBS
  245. "mkl_lapack95")
  246. # new >= 10.3
  247. list(APPEND LAPACK_SEARCH_LIBS
  248. "mkl_intel_c")
  249. list(APPEND LAPACK_SEARCH_LIBS
  250. "mkl_lapack95_${LAPACK_mkl_ILP_MODE}")
  251. else()
  252. set(LAPACK_mkl_SEARCH_SYMBOL "cheev")
  253. set(_LIBRARIES LAPACK_LIBRARIES)
  254. set(_BLAS_LIBRARIES ${BLAS_LIBRARIES})
  255. # old and new >= 10.3
  256. list(APPEND LAPACK_SEARCH_LIBS
  257. "mkl_lapack")
  258. endif()
  259. # MKL uses a multitude of partially platform-specific subdirectories:
  260. if(BLA_VENDOR STREQUAL "Intel10_32")
  261. set(LAPACK_mkl_ARCH_NAME "ia32")
  262. else()
  263. set(LAPACK_mkl_ARCH_NAME "intel64")
  264. endif()
  265. if(WIN32)
  266. set(LAPACK_mkl_OS_NAME "win")
  267. elseif(APPLE)
  268. set(LAPACK_mkl_OS_NAME "mac")
  269. else()
  270. set(LAPACK_mkl_OS_NAME "lin")
  271. endif()
  272. if(DEFINED ENV{MKLROOT})
  273. file(TO_CMAKE_PATH "$ENV{MKLROOT}" LAPACK_mkl_MKLROOT)
  274. # If MKLROOT points to the subdirectory 'mkl', use the parent directory instead
  275. # so we can better detect other relevant libraries in 'compiler' or 'tbb':
  276. get_filename_component(LAPACK_mkl_MKLROOT_LAST_DIR "${LAPACK_mkl_MKLROOT}" NAME)
  277. if(LAPACK_mkl_MKLROOT_LAST_DIR STREQUAL "mkl")
  278. get_filename_component(LAPACK_mkl_MKLROOT "${LAPACK_mkl_MKLROOT}" DIRECTORY)
  279. endif()
  280. endif()
  281. set(LAPACK_mkl_LIB_PATH_SUFFIXES
  282. "compiler/lib" "compiler/lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}"
  283. "compiler/lib/${LAPACK_mkl_ARCH_NAME}"
  284. "mkl/lib" "mkl/lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}"
  285. "mkl/lib/${LAPACK_mkl_ARCH_NAME}"
  286. "lib/${LAPACK_mkl_ARCH_NAME}_${LAPACK_mkl_OS_NAME}")
  287. # First try empty lapack libs
  288. if(NOT ${_LIBRARIES})
  289. check_lapack_libraries(
  290. ${_LIBRARIES}
  291. LAPACK
  292. ${LAPACK_mkl_SEARCH_SYMBOL}
  293. ""
  294. ""
  295. "${CMAKE_THREAD_LIBS_INIT};${LAPACK_mkl_LM};${LAPACK_mkl_LDL}"
  296. "${LAPACK_mkl_MKLROOT}"
  297. "${LAPACK_mkl_LIB_PATH_SUFFIXES}"
  298. "${_BLAS_LIBRARIES}"
  299. )
  300. endif()
  301. # Then try the search libs
  302. foreach(IT ${LAPACK_SEARCH_LIBS})
  303. string(REPLACE " " ";" SEARCH_LIBS ${IT})
  304. if(NOT ${_LIBRARIES})
  305. check_lapack_libraries(
  306. ${_LIBRARIES}
  307. LAPACK
  308. ${LAPACK_mkl_SEARCH_SYMBOL}
  309. ""
  310. "${SEARCH_LIBS}"
  311. "${CMAKE_THREAD_LIBS_INIT};${LAPACK_mkl_LM};${LAPACK_mkl_LDL}"
  312. "${LAPACK_mkl_MKLROOT}"
  313. "${LAPACK_mkl_LIB_PATH_SUFFIXES}"
  314. "${_BLAS_LIBRARIES}"
  315. )
  316. endif()
  317. endforeach()
  318. unset(LAPACK_mkl_ILP_MODE)
  319. unset(LAPACK_mkl_SEARCH_SYMBOL)
  320. unset(LAPACK_mkl_LM)
  321. unset(LAPACK_mkl_LDL)
  322. unset(LAPACK_mkl_MKLROOT)
  323. unset(LAPACK_mkl_ARCH_NAME)
  324. unset(LAPACK_mkl_OS_NAME)
  325. unset(LAPACK_mkl_LIB_PATH_SUFFIXES)
  326. endif()
  327. # gotoblas? (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
  328. if(NOT LAPACK_LIBRARIES
  329. AND (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All"))
  330. check_lapack_libraries(
  331. LAPACK_LIBRARIES
  332. LAPACK
  333. cheev
  334. ""
  335. "goto2"
  336. ""
  337. ""
  338. ""
  339. "${BLAS_LIBRARIES}"
  340. )
  341. endif()
  342. # FlexiBLAS? (http://www.mpi-magdeburg.mpg.de/mpcsc/software/FlexiBLAS/)
  343. if(NOT LAPACK_LIBRARIES
  344. AND (BLA_VENDOR STREQUAL "FlexiBLAS" OR BLA_VENDOR STREQUAL "All"))
  345. check_lapack_libraries(
  346. LAPACK_LIBRARIES
  347. LAPACK
  348. cheev
  349. ""
  350. "flexiblas"
  351. ""
  352. ""
  353. ""
  354. "${BLAS_LIBRARIES}"
  355. )
  356. endif()
  357. # OpenBLAS? (http://www.openblas.net)
  358. if(NOT LAPACK_LIBRARIES
  359. AND (BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All"))
  360. check_lapack_libraries(
  361. LAPACK_LIBRARIES
  362. LAPACK
  363. cheev
  364. ""
  365. "openblas"
  366. ""
  367. ""
  368. ""
  369. "${BLAS_LIBRARIES}"
  370. )
  371. endif()
  372. # ArmPL? (https://developer.arm.com/tools-and-software/server-and-hpc/compile/arm-compiler-for-linux/arm-performance-libraries)
  373. if(NOT LAPACK_LIBRARIES
  374. AND (BLA_VENDOR MATCHES "Arm" OR BLA_VENDOR STREQUAL "All"))
  375. # Check for 64bit Integer support
  376. if(BLA_VENDOR MATCHES "_ilp64")
  377. set(LAPACK_armpl_LIB "armpl_ilp64")
  378. else()
  379. set(LAPACK_armpl_LIB "armpl_lp64")
  380. endif()
  381. # Check for OpenMP support, VIA BLA_VENDOR of Arm_mp or Arm_ipl64_mp
  382. if(BLA_VENDOR MATCHES "_mp")
  383. set(LAPACK_armpl_LIB "${LAPACK_armpl_LIB}_mp")
  384. endif()
  385. check_lapack_libraries(
  386. LAPACK_LIBRARIES
  387. LAPACK
  388. cheev
  389. ""
  390. "${LAPACK_armpl_LIB}"
  391. ""
  392. ""
  393. ""
  394. "${BLAS_LIBRARIES}"
  395. )
  396. endif()
  397. # FLAME's blis library? (https://github.com/flame/blis)
  398. if(NOT LAPACK_LIBRARIES
  399. AND (BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All"))
  400. check_lapack_libraries(
  401. LAPACK_LIBRARIES
  402. LAPACK
  403. cheev
  404. ""
  405. "flame"
  406. ""
  407. ""
  408. ""
  409. "${BLAS_LIBRARIES}"
  410. )
  411. endif()
  412. # BLAS in acml library?
  413. if(BLA_VENDOR MATCHES "ACML" OR BLA_VENDOR STREQUAL "All")
  414. if(BLAS_LIBRARIES MATCHES ".+acml.+")
  415. set(LAPACK_LIBRARIES ${BLAS_LIBRARIES})
  416. endif()
  417. endif()
  418. # Apple LAPACK library?
  419. if(NOT LAPACK_LIBRARIES
  420. AND (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All"))
  421. check_lapack_libraries(
  422. LAPACK_LIBRARIES
  423. LAPACK
  424. cheev
  425. ""
  426. "Accelerate"
  427. ""
  428. ""
  429. ""
  430. "${BLAS_LIBRARIES}"
  431. )
  432. endif()
  433. # Apple NAS (vecLib) library?
  434. if(NOT LAPACK_LIBRARIES
  435. AND (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All"))
  436. check_lapack_libraries(
  437. LAPACK_LIBRARIES
  438. LAPACK
  439. cheev
  440. ""
  441. "vecLib"
  442. ""
  443. ""
  444. ""
  445. "${BLAS_LIBRARIES}"
  446. )
  447. endif()
  448. # Generic LAPACK library?
  449. if(NOT LAPACK_LIBRARIES
  450. AND (BLA_VENDOR STREQUAL "Generic"
  451. OR BLA_VENDOR STREQUAL "ATLAS"
  452. OR BLA_VENDOR STREQUAL "All"))
  453. check_lapack_libraries(
  454. LAPACK_LIBRARIES
  455. LAPACK
  456. cheev
  457. ""
  458. "lapack"
  459. ""
  460. ""
  461. ""
  462. "${BLAS_LIBRARIES}"
  463. )
  464. endif()
  465. endif()
  466. if(BLA_F95)
  467. set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}")
  468. endif()
  469. if(LAPACK_NOT_FOUND_MESSAGE)
  470. set(LAPACK_NOT_FOUND_MESSAGE
  471. REASON_FAILURE_MESSAGE ${LAPACK_NOT_FOUND_MESSAGE})
  472. endif()
  473. find_package_handle_standard_args(LAPACK REQUIRED_VARS LAPACK_LIBRARIES
  474. ${LAPACK_NOT_FOUND_MESSAGE})
  475. unset(LAPACK_NOT_FOUND_MESSAGE)
  476. if(BLA_F95)
  477. set(LAPACK95_FOUND ${LAPACK_FOUND})
  478. endif()
  479. # On compilers that implicitly link LAPACK (such as ftn, cc, and CC on Cray HPC machines)
  480. # we used a placeholder for empty LAPACK_LIBRARIES to get through our logic above.
  481. if(LAPACK_LIBRARIES STREQUAL "LAPACK_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
  482. set(LAPACK_LIBRARIES "")
  483. endif()
  484. if(LAPACK_FOUND AND NOT TARGET LAPACK::LAPACK)
  485. add_library(LAPACK::LAPACK INTERFACE IMPORTED)
  486. set(_lapack_libs "${LAPACK_LIBRARIES}")
  487. if(_lapack_libs AND TARGET BLAS::BLAS)
  488. # remove the ${BLAS_LIBRARIES} from the interface and replace it
  489. # with the BLAS::BLAS target
  490. list(REMOVE_ITEM _lapack_libs "${BLAS_LIBRARIES}")
  491. endif()
  492. if(_lapack_libs)
  493. set_target_properties(LAPACK::LAPACK PROPERTIES
  494. INTERFACE_LINK_LIBRARIES "${_lapack_libs}"
  495. )
  496. endif()
  497. unset(_lapack_libs)
  498. endif()
  499. _lapack_find_library_teardown()