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