2
# This module finds an installed fortran library that implements the LAPACK
3
# linear-algebra interface (see http://www.netlib.org/lapack/).
5
# The approach follows that taken for the autoconf macro file, acx_lapack.m4
6
# (distributed at http://ac-archive.sourceforge.net/ac-archive/acx_lapack.html).
8
# This module sets the following variables:
9
# LAPACK_FOUND - set to true if a library implementing the LAPACK interface is found
10
# LAPACK_LIBRARIES - list of libraries (using full path name) for LAPACK
12
# Note: I do not think it is a good idea to mixup different BLAS/LAPACK versions
13
# Hence, this script wants to find a Lapack library matching your Blas library
15
# Do nothing if LAPACK was found before
21
IF(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
23
ELSE(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
24
FIND_PACKAGE(BLAS REQUIRED)
25
ENDIF(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
27
# Old search lapack script
28
include(CheckFortranFunctionExists)
29
include(CheckFunctionExists)
31
macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas)
32
# This macro checks for the existence of the combination of fortran libraries
33
# given by _list. If the combination is found, this macro checks (using the
34
# Check_Fortran_Function_Exists macro) whether can link against that library
35
# combination using the name of a routine given by _name using the linker
36
# flags given by _flags. If the combination of libraries is found and passes
37
# the link test, LIBRARIES is set to the list of complete library paths that
38
# have been found. Otherwise, LIBRARIES is set to FALSE.
39
# N.B. _prefix is the prefix applied to the names of all cached variables that
40
# are generated internally and marked advanced by this macro.
41
set(_libraries_work TRUE)
44
foreach(_library ${_list})
45
set(_combined_name ${_combined_name}_${_library})
48
find_library(${_prefix}_${_library}_LIBRARY
49
NAMES ${_library} PATHS ENV LIB PATHS ENV PATH)
52
find_library(${_prefix}_${_library}_LIBRARY
54
PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 /usr/lib/aarch64-linux-gnu
55
ENV DYLD_LIBRARY_PATH)
57
find_library(${_prefix}_${_library}_LIBRARY
59
PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 /usr/lib/aarch64-linux-gnu
63
mark_as_advanced(${_prefix}_${_library}_LIBRARY)
64
set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
65
set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
66
endif(_libraries_work)
67
endforeach(_library ${_list})
69
# Test this combination of libraries.
70
set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas})
71
if (CMAKE_Fortran_COMPILER_WORKS)
72
check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
73
else (CMAKE_Fortran_COMPILER_WORKS)
74
check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
75
endif (CMAKE_Fortran_COMPILER_WORKS)
76
set(CMAKE_REQUIRED_LIBRARIES)
77
mark_as_advanced(${_prefix}${_combined_name}_WORKS)
78
set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
79
endif(_libraries_work)
80
if(NOT _libraries_work)
81
set(${LIBRARIES} FALSE)
82
endif(NOT _libraries_work)
83
endmacro(Check_Lapack_Libraries)
89
IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "mkl"))
90
IF(MKL_LAPACK_LIBRARIES)
91
SET(LAPACK_LIBRARIES ${MKL_LAPACK_LIBRARIES} ${MKL_LIBRARIES})
92
ELSE(MKL_LAPACK_LIBRARIES)
93
SET(LAPACK_LIBRARIES ${MKL_LIBRARIES})
94
ENDIF(MKL_LAPACK_LIBRARIES)
95
SET(LAPACK_INCLUDE_DIR ${MKL_INCLUDE_DIR})
96
SET(LAPACK_INFO "mkl")
100
IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "nvpl"))
101
FIND_PACKAGE(NVPL_LAPACK REQUIRED)
102
SET(LAPACK_LIBRARIES nvpl::lapack_lp64_omp)
103
SET(LAPACK_INFO "nvpl")
107
IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "accelerate"))
108
SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
109
check_function_exists("cheev_" ACCELERATE_LAPACK_WORKS)
110
set(CMAKE_REQUIRED_LIBRARIES)
111
if(ACCELERATE_LAPACK_WORKS)
112
SET(LAPACK_INFO "accelerate")
114
message(STATUS "Strangely, this Accelerate library does not support Lapack?!")
119
IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "veclib"))
120
SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
121
check_function_exists("cheev_" VECLIB_LAPACK_WORKS)
122
set(CMAKE_REQUIRED_LIBRARIES)
123
if(VECLIB_LAPACK_WORKS)
124
SET(LAPACK_INFO "veclib")
126
message(STATUS "Strangely, this vecLib library does not support Lapack?!")
131
IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "flexi"))
132
SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
133
check_function_exists("cheev_" FLEXIBLAS_LAPACK_WORKS)
134
set(CMAKE_REQUIRED_LIBRARIES)
135
if(FLEXIBLAS_LAPACK_WORKS)
136
SET(LAPACK_INFO "flexi")
138
message(STATUS "Strangely, this FlexiBLAS library does not support Lapack?!")
143
IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "open"))
144
SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
145
check_function_exists("cheev_" OPEN_LAPACK_WORKS)
146
if(OPEN_LAPACK_WORKS)
147
check_function_exists("cgesdd_" LAPACK_CGESDD_WORKS)
148
if(NOT LAPACK_CGESDD_WORKS)
149
find_library(GFORTRAN_LIBRARY
150
NAMES libgfortran.a gfortran
151
PATHS ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
152
list(APPEND CMAKE_REQUIRED_LIBRARIES "${GFORTRAN_LIBRARY}")
153
unset(LAPACK_CGESDD_WORKS CACHE)
154
check_function_exists("cgesdd_" LAPACK_CGESDD_WORKS)
155
if(LAPACK_CGESDD_WORKS)
156
list(APPEND LAPACK_LIBRARIES "${GFORTRAN_LIBRARY}")
158
message(WARNING "OpenBlas has been compiled with Lapack support, but cgesdd can not be used")
159
set(OPEN_LAPACK_WORKS NO)
164
set(CMAKE_REQUIRED_LIBRARIES)
165
if(OPEN_LAPACK_WORKS)
166
SET(LAPACK_INFO "open")
168
message(STATUS "It seems OpenBlas has not been compiled with Lapack support")
173
IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "goto"))
174
SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
175
check_function_exists("cheev_" GOTO_LAPACK_WORKS)
176
set(CMAKE_REQUIRED_LIBRARIES)
177
if(GOTO_LAPACK_WORKS)
178
SET(LAPACK_INFO "goto")
180
message(STATUS "It seems GotoBlas has not been compiled with Lapack support")
185
IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "FLAME"))
186
check_lapack_libraries(
195
SET(LAPACK_INFO "FLAME")
196
endif(LAPACK_LIBRARIES)
200
IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "acml"))
201
SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES})
202
check_function_exists("cheev_" ACML_LAPACK_WORKS)
203
set(CMAKE_REQUIRED_LIBRARIES)
204
if(ACML_LAPACK_WORKS)
205
SET(LAPACK_INFO "acml")
207
message(STATUS "Strangely, this ACML library does not support Lapack?!")
211
# Generic LAPACK library?
212
IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "generic"))
213
check_lapack_libraries(
222
SET(LAPACK_INFO "generic")
223
endif(LAPACK_LIBRARIES)
227
message(STATUS "LAPACK requires BLAS")
231
set(LAPACK_FOUND TRUE)
233
set(LAPACK_FOUND FALSE)
236
IF (NOT LAPACK_FOUND AND LAPACK_FIND_REQUIRED)
237
message(FATAL_ERROR "Cannot find a library with LAPACK API. Please specify library location.")
238
ENDIF (NOT LAPACK_FOUND AND LAPACK_FIND_REQUIRED)
239
IF(NOT LAPACK_FIND_QUIETLY)
241
MESSAGE(STATUS "Found a library with LAPACK API (${LAPACK_INFO}).")
243
MESSAGE(STATUS "Cannot find a library with LAPACK API. Not using LAPACK.")
245
ENDIF(NOT LAPACK_FIND_QUIETLY)
247
# Do nothing if LAPACK was found before
248
ENDIF(NOT LAPACK_FOUND)