1*da0073e9SAndroid Build Coastguard Worker# - Find LAPACK library 2*da0073e9SAndroid Build Coastguard Worker# This module finds an installed fortran library that implements the LAPACK 3*da0073e9SAndroid Build Coastguard Worker# linear-algebra interface (see http://www.netlib.org/lapack/). 4*da0073e9SAndroid Build Coastguard Worker# 5*da0073e9SAndroid Build Coastguard Worker# The approach follows that taken for the autoconf macro file, acx_lapack.m4 6*da0073e9SAndroid Build Coastguard Worker# (distributed at http://ac-archive.sourceforge.net/ac-archive/acx_lapack.html). 7*da0073e9SAndroid Build Coastguard Worker# 8*da0073e9SAndroid Build Coastguard Worker# This module sets the following variables: 9*da0073e9SAndroid Build Coastguard Worker# LAPACK_FOUND - set to true if a library implementing the LAPACK interface is found 10*da0073e9SAndroid Build Coastguard Worker# LAPACK_LIBRARIES - list of libraries (using full path name) for LAPACK 11*da0073e9SAndroid Build Coastguard Worker 12*da0073e9SAndroid Build Coastguard Worker# Note: I do not think it is a good idea to mixup different BLAS/LAPACK versions 13*da0073e9SAndroid Build Coastguard Worker# Hence, this script wants to find a Lapack library matching your Blas library 14*da0073e9SAndroid Build Coastguard Worker 15*da0073e9SAndroid Build Coastguard Worker# Do nothing if LAPACK was found before 16*da0073e9SAndroid Build Coastguard WorkerIF(NOT LAPACK_FOUND) 17*da0073e9SAndroid Build Coastguard Worker 18*da0073e9SAndroid Build Coastguard WorkerSET(LAPACK_LIBRARIES) 19*da0073e9SAndroid Build Coastguard WorkerSET(LAPACK_INFO) 20*da0073e9SAndroid Build Coastguard Worker 21*da0073e9SAndroid Build Coastguard WorkerIF(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) 22*da0073e9SAndroid Build Coastguard Worker FIND_PACKAGE(BLAS) 23*da0073e9SAndroid Build Coastguard WorkerELSE(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) 24*da0073e9SAndroid Build Coastguard Worker FIND_PACKAGE(BLAS REQUIRED) 25*da0073e9SAndroid Build Coastguard WorkerENDIF(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) 26*da0073e9SAndroid Build Coastguard Worker 27*da0073e9SAndroid Build Coastguard Worker# Old search lapack script 28*da0073e9SAndroid Build Coastguard Workerinclude(CheckFortranFunctionExists) 29*da0073e9SAndroid Build Coastguard Workerinclude(CheckFunctionExists) 30*da0073e9SAndroid Build Coastguard Worker 31*da0073e9SAndroid Build Coastguard Workermacro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas) 32*da0073e9SAndroid Build Coastguard Worker # This macro checks for the existence of the combination of fortran libraries 33*da0073e9SAndroid Build Coastguard Worker # given by _list. If the combination is found, this macro checks (using the 34*da0073e9SAndroid Build Coastguard Worker # Check_Fortran_Function_Exists macro) whether can link against that library 35*da0073e9SAndroid Build Coastguard Worker # combination using the name of a routine given by _name using the linker 36*da0073e9SAndroid Build Coastguard Worker # flags given by _flags. If the combination of libraries is found and passes 37*da0073e9SAndroid Build Coastguard Worker # the link test, LIBRARIES is set to the list of complete library paths that 38*da0073e9SAndroid Build Coastguard Worker # have been found. Otherwise, LIBRARIES is set to FALSE. 39*da0073e9SAndroid Build Coastguard Worker # N.B. _prefix is the prefix applied to the names of all cached variables that 40*da0073e9SAndroid Build Coastguard Worker # are generated internally and marked advanced by this macro. 41*da0073e9SAndroid Build Coastguard Worker set(_libraries_work TRUE) 42*da0073e9SAndroid Build Coastguard Worker set(${LIBRARIES}) 43*da0073e9SAndroid Build Coastguard Worker set(_combined_name) 44*da0073e9SAndroid Build Coastguard Worker foreach(_library ${_list}) 45*da0073e9SAndroid Build Coastguard Worker set(_combined_name ${_combined_name}_${_library}) 46*da0073e9SAndroid Build Coastguard Worker if(_libraries_work) 47*da0073e9SAndroid Build Coastguard Worker if (WIN32) 48*da0073e9SAndroid Build Coastguard Worker find_library(${_prefix}_${_library}_LIBRARY 49*da0073e9SAndroid Build Coastguard Worker NAMES ${_library} PATHS ENV LIB PATHS ENV PATH) 50*da0073e9SAndroid Build Coastguard Worker else (WIN32) 51*da0073e9SAndroid Build Coastguard Worker if(APPLE) 52*da0073e9SAndroid Build Coastguard Worker find_library(${_prefix}_${_library}_LIBRARY 53*da0073e9SAndroid Build Coastguard Worker NAMES ${_library} 54*da0073e9SAndroid Build Coastguard Worker PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 /usr/lib/aarch64-linux-gnu 55*da0073e9SAndroid Build Coastguard Worker ENV DYLD_LIBRARY_PATH) 56*da0073e9SAndroid Build Coastguard Worker else(APPLE) 57*da0073e9SAndroid Build Coastguard Worker find_library(${_prefix}_${_library}_LIBRARY 58*da0073e9SAndroid Build Coastguard Worker NAMES ${_library} 59*da0073e9SAndroid Build Coastguard Worker PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 /usr/lib/aarch64-linux-gnu 60*da0073e9SAndroid Build Coastguard Worker ENV LD_LIBRARY_PATH) 61*da0073e9SAndroid Build Coastguard Worker endif(APPLE) 62*da0073e9SAndroid Build Coastguard Worker endif(WIN32) 63*da0073e9SAndroid Build Coastguard Worker mark_as_advanced(${_prefix}_${_library}_LIBRARY) 64*da0073e9SAndroid Build Coastguard Worker set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY}) 65*da0073e9SAndroid Build Coastguard Worker set(_libraries_work ${${_prefix}_${_library}_LIBRARY}) 66*da0073e9SAndroid Build Coastguard Worker endif(_libraries_work) 67*da0073e9SAndroid Build Coastguard Worker endforeach(_library ${_list}) 68*da0073e9SAndroid Build Coastguard Worker if(_libraries_work) 69*da0073e9SAndroid Build Coastguard Worker # Test this combination of libraries. 70*da0073e9SAndroid Build Coastguard Worker set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas}) 71*da0073e9SAndroid Build Coastguard Worker if (CMAKE_Fortran_COMPILER_WORKS) 72*da0073e9SAndroid Build Coastguard Worker check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS) 73*da0073e9SAndroid Build Coastguard Worker else (CMAKE_Fortran_COMPILER_WORKS) 74*da0073e9SAndroid Build Coastguard Worker check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS) 75*da0073e9SAndroid Build Coastguard Worker endif (CMAKE_Fortran_COMPILER_WORKS) 76*da0073e9SAndroid Build Coastguard Worker set(CMAKE_REQUIRED_LIBRARIES) 77*da0073e9SAndroid Build Coastguard Worker mark_as_advanced(${_prefix}${_combined_name}_WORKS) 78*da0073e9SAndroid Build Coastguard Worker set(_libraries_work ${${_prefix}${_combined_name}_WORKS}) 79*da0073e9SAndroid Build Coastguard Worker endif(_libraries_work) 80*da0073e9SAndroid Build Coastguard Worker if(NOT _libraries_work) 81*da0073e9SAndroid Build Coastguard Worker set(${LIBRARIES} FALSE) 82*da0073e9SAndroid Build Coastguard Worker endif(NOT _libraries_work) 83*da0073e9SAndroid Build Coastguard Workerendmacro(Check_Lapack_Libraries) 84*da0073e9SAndroid Build Coastguard Worker 85*da0073e9SAndroid Build Coastguard Worker 86*da0073e9SAndroid Build Coastguard Workerif(BLAS_FOUND) 87*da0073e9SAndroid Build Coastguard Worker 88*da0073e9SAndroid Build Coastguard Worker # Intel MKL 89*da0073e9SAndroid Build Coastguard Worker IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "mkl")) 90*da0073e9SAndroid Build Coastguard Worker IF(MKL_LAPACK_LIBRARIES) 91*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_LIBRARIES ${MKL_LAPACK_LIBRARIES} ${MKL_LIBRARIES}) 92*da0073e9SAndroid Build Coastguard Worker ELSE(MKL_LAPACK_LIBRARIES) 93*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_LIBRARIES ${MKL_LIBRARIES}) 94*da0073e9SAndroid Build Coastguard Worker ENDIF(MKL_LAPACK_LIBRARIES) 95*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_INCLUDE_DIR ${MKL_INCLUDE_DIR}) 96*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_INFO "mkl") 97*da0073e9SAndroid Build Coastguard Worker ENDIF() 98*da0073e9SAndroid Build Coastguard Worker 99*da0073e9SAndroid Build Coastguard Worker # NVPL 100*da0073e9SAndroid Build Coastguard Worker IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "nvpl")) 101*da0073e9SAndroid Build Coastguard Worker FIND_PACKAGE(NVPL_LAPACK REQUIRED) 102*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_LIBRARIES nvpl::lapack_lp64_omp) 103*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_INFO "nvpl") 104*da0073e9SAndroid Build Coastguard Worker ENDIF() 105*da0073e9SAndroid Build Coastguard Worker 106*da0073e9SAndroid Build Coastguard Worker # Accelerate 107*da0073e9SAndroid Build Coastguard Worker IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "accelerate")) 108*da0073e9SAndroid Build Coastguard Worker SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES}) 109*da0073e9SAndroid Build Coastguard Worker check_function_exists("cheev_" ACCELERATE_LAPACK_WORKS) 110*da0073e9SAndroid Build Coastguard Worker set(CMAKE_REQUIRED_LIBRARIES) 111*da0073e9SAndroid Build Coastguard Worker if(ACCELERATE_LAPACK_WORKS) 112*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_INFO "accelerate") 113*da0073e9SAndroid Build Coastguard Worker else() 114*da0073e9SAndroid Build Coastguard Worker message(STATUS "Strangely, this Accelerate library does not support Lapack?!") 115*da0073e9SAndroid Build Coastguard Worker endif() 116*da0073e9SAndroid Build Coastguard Worker endif() 117*da0073e9SAndroid Build Coastguard Worker 118*da0073e9SAndroid Build Coastguard Worker # vecLib 119*da0073e9SAndroid Build Coastguard Worker IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "veclib")) 120*da0073e9SAndroid Build Coastguard Worker SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES}) 121*da0073e9SAndroid Build Coastguard Worker check_function_exists("cheev_" VECLIB_LAPACK_WORKS) 122*da0073e9SAndroid Build Coastguard Worker set(CMAKE_REQUIRED_LIBRARIES) 123*da0073e9SAndroid Build Coastguard Worker if(VECLIB_LAPACK_WORKS) 124*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_INFO "veclib") 125*da0073e9SAndroid Build Coastguard Worker else() 126*da0073e9SAndroid Build Coastguard Worker message(STATUS "Strangely, this vecLib library does not support Lapack?!") 127*da0073e9SAndroid Build Coastguard Worker endif() 128*da0073e9SAndroid Build Coastguard Worker endif() 129*da0073e9SAndroid Build Coastguard Worker 130*da0073e9SAndroid Build Coastguard Worker # FlexiBLAS 131*da0073e9SAndroid Build Coastguard Worker IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "flexi")) 132*da0073e9SAndroid Build Coastguard Worker SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES}) 133*da0073e9SAndroid Build Coastguard Worker check_function_exists("cheev_" FLEXIBLAS_LAPACK_WORKS) 134*da0073e9SAndroid Build Coastguard Worker set(CMAKE_REQUIRED_LIBRARIES) 135*da0073e9SAndroid Build Coastguard Worker if(FLEXIBLAS_LAPACK_WORKS) 136*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_INFO "flexi") 137*da0073e9SAndroid Build Coastguard Worker else() 138*da0073e9SAndroid Build Coastguard Worker message(STATUS "Strangely, this FlexiBLAS library does not support Lapack?!") 139*da0073e9SAndroid Build Coastguard Worker endif() 140*da0073e9SAndroid Build Coastguard Worker endif() 141*da0073e9SAndroid Build Coastguard Worker 142*da0073e9SAndroid Build Coastguard Worker # OpenBlas 143*da0073e9SAndroid Build Coastguard Worker IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "open")) 144*da0073e9SAndroid Build Coastguard Worker SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES}) 145*da0073e9SAndroid Build Coastguard Worker check_function_exists("cheev_" OPEN_LAPACK_WORKS) 146*da0073e9SAndroid Build Coastguard Worker if(OPEN_LAPACK_WORKS) 147*da0073e9SAndroid Build Coastguard Worker check_function_exists("cgesdd_" LAPACK_CGESDD_WORKS) 148*da0073e9SAndroid Build Coastguard Worker if(NOT LAPACK_CGESDD_WORKS) 149*da0073e9SAndroid Build Coastguard Worker find_library(GFORTRAN_LIBRARY 150*da0073e9SAndroid Build Coastguard Worker NAMES libgfortran.a gfortran 151*da0073e9SAndroid Build Coastguard Worker PATHS ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}) 152*da0073e9SAndroid Build Coastguard Worker list(APPEND CMAKE_REQUIRED_LIBRARIES "${GFORTRAN_LIBRARY}") 153*da0073e9SAndroid Build Coastguard Worker unset(LAPACK_CGESDD_WORKS CACHE) 154*da0073e9SAndroid Build Coastguard Worker check_function_exists("cgesdd_" LAPACK_CGESDD_WORKS) 155*da0073e9SAndroid Build Coastguard Worker if(LAPACK_CGESDD_WORKS) 156*da0073e9SAndroid Build Coastguard Worker list(APPEND LAPACK_LIBRARIES "${GFORTRAN_LIBRARY}") 157*da0073e9SAndroid Build Coastguard Worker else() 158*da0073e9SAndroid Build Coastguard Worker message(WARNING "OpenBlas has been compiled with Lapack support, but cgesdd can not be used") 159*da0073e9SAndroid Build Coastguard Worker set(OPEN_LAPACK_WORKS NO) 160*da0073e9SAndroid Build Coastguard Worker endif() 161*da0073e9SAndroid Build Coastguard Worker endif() 162*da0073e9SAndroid Build Coastguard Worker endif() 163*da0073e9SAndroid Build Coastguard Worker 164*da0073e9SAndroid Build Coastguard Worker set(CMAKE_REQUIRED_LIBRARIES) 165*da0073e9SAndroid Build Coastguard Worker if(OPEN_LAPACK_WORKS) 166*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_INFO "open") 167*da0073e9SAndroid Build Coastguard Worker else() 168*da0073e9SAndroid Build Coastguard Worker message(STATUS "It seems OpenBlas has not been compiled with Lapack support") 169*da0073e9SAndroid Build Coastguard Worker endif() 170*da0073e9SAndroid Build Coastguard Worker endif() 171*da0073e9SAndroid Build Coastguard Worker 172*da0073e9SAndroid Build Coastguard Worker # GotoBlas 173*da0073e9SAndroid Build Coastguard Worker IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "goto")) 174*da0073e9SAndroid Build Coastguard Worker SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES}) 175*da0073e9SAndroid Build Coastguard Worker check_function_exists("cheev_" GOTO_LAPACK_WORKS) 176*da0073e9SAndroid Build Coastguard Worker set(CMAKE_REQUIRED_LIBRARIES) 177*da0073e9SAndroid Build Coastguard Worker if(GOTO_LAPACK_WORKS) 178*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_INFO "goto") 179*da0073e9SAndroid Build Coastguard Worker else() 180*da0073e9SAndroid Build Coastguard Worker message(STATUS "It seems GotoBlas has not been compiled with Lapack support") 181*da0073e9SAndroid Build Coastguard Worker endif() 182*da0073e9SAndroid Build Coastguard Worker endif() 183*da0073e9SAndroid Build Coastguard Worker 184*da0073e9SAndroid Build Coastguard Worker # FLAME 185*da0073e9SAndroid Build Coastguard Worker IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "FLAME")) 186*da0073e9SAndroid Build Coastguard Worker check_lapack_libraries( 187*da0073e9SAndroid Build Coastguard Worker LAPACK_LIBRARIES 188*da0073e9SAndroid Build Coastguard Worker LAPACK 189*da0073e9SAndroid Build Coastguard Worker cheev 190*da0073e9SAndroid Build Coastguard Worker "" 191*da0073e9SAndroid Build Coastguard Worker "flame" 192*da0073e9SAndroid Build Coastguard Worker "${BLAS_LIBRARIES}" 193*da0073e9SAndroid Build Coastguard Worker ) 194*da0073e9SAndroid Build Coastguard Worker if(LAPACK_LIBRARIES) 195*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_INFO "FLAME") 196*da0073e9SAndroid Build Coastguard Worker endif(LAPACK_LIBRARIES) 197*da0073e9SAndroid Build Coastguard Worker endif() 198*da0073e9SAndroid Build Coastguard Worker 199*da0073e9SAndroid Build Coastguard Worker # ACML 200*da0073e9SAndroid Build Coastguard Worker IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "acml")) 201*da0073e9SAndroid Build Coastguard Worker SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES}) 202*da0073e9SAndroid Build Coastguard Worker check_function_exists("cheev_" ACML_LAPACK_WORKS) 203*da0073e9SAndroid Build Coastguard Worker set(CMAKE_REQUIRED_LIBRARIES) 204*da0073e9SAndroid Build Coastguard Worker if(ACML_LAPACK_WORKS) 205*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_INFO "acml") 206*da0073e9SAndroid Build Coastguard Worker else() 207*da0073e9SAndroid Build Coastguard Worker message(STATUS "Strangely, this ACML library does not support Lapack?!") 208*da0073e9SAndroid Build Coastguard Worker endif() 209*da0073e9SAndroid Build Coastguard Worker endif() 210*da0073e9SAndroid Build Coastguard Worker 211*da0073e9SAndroid Build Coastguard Worker # Generic LAPACK library? 212*da0073e9SAndroid Build Coastguard Worker IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "generic")) 213*da0073e9SAndroid Build Coastguard Worker check_lapack_libraries( 214*da0073e9SAndroid Build Coastguard Worker LAPACK_LIBRARIES 215*da0073e9SAndroid Build Coastguard Worker LAPACK 216*da0073e9SAndroid Build Coastguard Worker cheev 217*da0073e9SAndroid Build Coastguard Worker "" 218*da0073e9SAndroid Build Coastguard Worker "lapack" 219*da0073e9SAndroid Build Coastguard Worker "${BLAS_LIBRARIES}" 220*da0073e9SAndroid Build Coastguard Worker ) 221*da0073e9SAndroid Build Coastguard Worker if(LAPACK_LIBRARIES) 222*da0073e9SAndroid Build Coastguard Worker SET(LAPACK_INFO "generic") 223*da0073e9SAndroid Build Coastguard Worker endif(LAPACK_LIBRARIES) 224*da0073e9SAndroid Build Coastguard Worker endif() 225*da0073e9SAndroid Build Coastguard Worker 226*da0073e9SAndroid Build Coastguard Workerelse(BLAS_FOUND) 227*da0073e9SAndroid Build Coastguard Worker message(STATUS "LAPACK requires BLAS") 228*da0073e9SAndroid Build Coastguard Workerendif(BLAS_FOUND) 229*da0073e9SAndroid Build Coastguard Worker 230*da0073e9SAndroid Build Coastguard Workerif(LAPACK_INFO) 231*da0073e9SAndroid Build Coastguard Worker set(LAPACK_FOUND TRUE) 232*da0073e9SAndroid Build Coastguard Workerelse(LAPACK_INFO) 233*da0073e9SAndroid Build Coastguard Worker set(LAPACK_FOUND FALSE) 234*da0073e9SAndroid Build Coastguard Workerendif(LAPACK_INFO) 235*da0073e9SAndroid Build Coastguard Worker 236*da0073e9SAndroid Build Coastguard WorkerIF (NOT LAPACK_FOUND AND LAPACK_FIND_REQUIRED) 237*da0073e9SAndroid Build Coastguard Worker message(FATAL_ERROR "Cannot find a library with LAPACK API. Please specify library location.") 238*da0073e9SAndroid Build Coastguard WorkerENDIF (NOT LAPACK_FOUND AND LAPACK_FIND_REQUIRED) 239*da0073e9SAndroid Build Coastguard WorkerIF(NOT LAPACK_FIND_QUIETLY) 240*da0073e9SAndroid Build Coastguard Worker IF(LAPACK_FOUND) 241*da0073e9SAndroid Build Coastguard Worker MESSAGE(STATUS "Found a library with LAPACK API (${LAPACK_INFO}).") 242*da0073e9SAndroid Build Coastguard Worker ELSE(LAPACK_FOUND) 243*da0073e9SAndroid Build Coastguard Worker MESSAGE(STATUS "Cannot find a library with LAPACK API. Not using LAPACK.") 244*da0073e9SAndroid Build Coastguard Worker ENDIF(LAPACK_FOUND) 245*da0073e9SAndroid Build Coastguard WorkerENDIF(NOT LAPACK_FIND_QUIETLY) 246*da0073e9SAndroid Build Coastguard Worker 247*da0073e9SAndroid Build Coastguard Worker# Do nothing if LAPACK was found before 248*da0073e9SAndroid Build Coastguard WorkerENDIF(NOT LAPACK_FOUND) 249