Skip to content

Commit 612aa39

Browse files
committed
FindLapack.cmake
1 parent ba12fc9 commit 612aa39

File tree

1 file changed

+47
-17
lines changed

1 file changed

+47
-17
lines changed

cmake/Modules/FindLAPACK.cmake

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ find_library(ATLAS_LIB
8888
NAMES_PER_DIR
8989
PATH_SUFFIXES atlas)
9090

91-
pkg_check_modules(pc_atlas_lapack lapack-atlas QUIET)
91+
pkg_check_modules(pc_atlas_lapack lapack-atlas)
9292

9393
find_library(LAPACK_ATLAS
9494
NAMES ptlapack lapack_atlas lapack
9595
NAMES_PER_DIR
9696
PATH_SUFFIXES atlas
9797
HINTS ${pc_atlas_lapack_LIBRARY_DIRS} ${pc_atlas_lapack_LIBDIR})
9898

99-
pkg_check_modules(pc_atlas_blas blas-atlas QUIET)
99+
pkg_check_modules(pc_atlas_blas blas-atlas)
100100

101101
find_library(BLAS_LIBRARY
102102
NAMES ptf77blas f77blas blas
@@ -159,10 +159,8 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL PGI)
159159
set(_lapack_hints ${_pgi_path}/../)
160160
endif()
161161

162-
pkg_check_modules(pc_lapack lapack-netlib QUIET)
163-
if(NOT pc_lapack_FOUND)
164-
pkg_check_modules(pc_lapack lapack QUIET) # Netlib on Cygwin, Homebrew and others
165-
endif()
162+
pkg_search_module(pc_lapack lapack lapack-netlib)
163+
166164
find_library(LAPACK_LIB
167165
NAMES lapack
168166
NAMES_PER_DIR
@@ -176,7 +174,7 @@ else()
176174
endif()
177175

178176
if(LAPACKE IN_LIST LAPACK_FIND_COMPONENTS)
179-
pkg_check_modules(pc_lapacke lapacke QUIET)
177+
pkg_check_modules(pc_lapacke lapacke)
180178
find_library(LAPACKE_LIBRARY
181179
NAMES lapacke
182180
NAMES_PER_DIR
@@ -205,9 +203,9 @@ if(LAPACKE IN_LIST LAPACK_FIND_COMPONENTS)
205203
mark_as_advanced(LAPACKE_LIBRARY LAPACKE_INCLUDE_DIR)
206204
endif(LAPACKE IN_LIST LAPACK_FIND_COMPONENTS)
207205

208-
pkg_check_modules(pc_blas blas-netlib QUIET)
206+
pkg_check_modules(pc_blas blas-netlib)
209207
if(NOT pc_blas_FOUND)
210-
pkg_check_modules(pc_blas blas QUIET) # Netlib on Cygwin and others
208+
pkg_check_modules(pc_blas blas) # Netlib on Cygwin and others
211209
endif()
212210
find_library(BLAS_LIBRARY
213211
NAMES refblas blas
@@ -239,15 +237,15 @@ endfunction(netlib_libs)
239237
#===============================
240238
function(openblas_libs)
241239

242-
pkg_check_modules(pc_lapack lapack-openblas QUIET)
240+
pkg_check_modules(pc_lapack lapack-openblas)
243241
find_library(LAPACK_LIBRARY
244242
NAMES lapack
245243
NAMES_PER_DIR
246244
HINTS ${pc_lapack_LIBRARY_DIRS} ${pc_lapack_LIBDIR}
247245
PATH_SUFFIXES openblas)
248246

249247

250-
pkg_check_modules(pc_blas blas-openblas QUIET)
248+
pkg_check_modules(pc_blas blas-openblas)
251249
find_library(BLAS_LIBRARY
252250
NAMES openblas blas
253251
NAMES_PER_DIR
@@ -341,7 +339,7 @@ if(NOT (OpenBLAS IN_LIST LAPACK_FIND_COMPONENTS
341339
endif()
342340
endif()
343341

344-
find_package(PkgConfig QUIET)
342+
find_package(PkgConfig)
345343

346344
# ==== generic MKL variables ====
347345

@@ -350,7 +348,7 @@ if(MKL IN_LIST LAPACK_FIND_COMPONENTS)
350348
# double-quotes are necessary per CMake to_cmake_path docs.
351349
file(TO_CMAKE_PATH "$ENV{MKLROOT}" MKLROOT)
352350

353-
list(APPEND CMAKE_PREFIX_PATH ${MKLROOT}/bin/pkgconfig)
351+
list(APPEND CMAKE_PREFIX_PATH ${MKLROOT}/tools/pkgconfig)
354352

355353
if(NOT WIN32)
356354
find_package(Threads)
@@ -370,7 +368,7 @@ if(MKL IN_LIST LAPACK_FIND_COMPONENTS)
370368

371369
unset(_mkl_libs)
372370
if(LAPACK95 IN_LIST LAPACK_FIND_COMPONENTS)
373-
list(APPEND _mkl_libs mkl_blas95_${_mkl_bitflag}lp64 mkl_lapack95_${_mkl_bitflag}lp64)
371+
set(_mkl_libs mkl_blas95_${_mkl_bitflag}lp64 mkl_lapack95_${_mkl_bitflag}lp64)
374372
endif()
375373

376374
unset(_tbb)
@@ -381,15 +379,15 @@ if(MKL IN_LIST LAPACK_FIND_COMPONENTS)
381379
list(APPEND _mkl_libs tbb.lib)
382380
endif()
383381
elseif(OpenMP IN_LIST LAPACK_FIND_COMPONENTS)
384-
pkg_check_modules(pc_mkl mkl-${_mkltype}-${_mkl_bitflag}lp64-iomp QUIET)
382+
pkg_check_modules(pc_mkl mkl-${_mkltype}-${_mkl_bitflag}lp64-iomp)
385383

386384
set(_mp iomp5)
387385
if(WIN32)
388386
set(_mp libiomp5md) # "lib" is indeed necessary, even on CMake 3.14.0
389387
endif()
390388
list(APPEND _mkl_libs mkl_intel_thread mkl_core ${_mp})
391389
else()
392-
pkg_check_modules(pc_mkl mkl-${_mkltype}-${_mkl_bitflag}lp64-seq QUIET)
390+
pkg_check_modules(pc_mkl mkl-${_mkltype}-${_mkl_bitflag}lp64-seq)
393391
list(APPEND _mkl_libs mkl_sequential mkl_core)
394392
endif()
395393

@@ -434,9 +432,41 @@ elseif(OpenBLAS IN_LIST LAPACK_FIND_COMPONENTS)
434432

435433
endif()
436434

435+
# -- verify library works
436+
437+
set(CMAKE_REQUIRED_FLAGS)
438+
set(CMAKE_REQUIRED_LINK_OPTIONS)
439+
set(CMAKE_REQUIRED_INCLUDES)
440+
set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARY})
441+
442+
if(LAPACK_LIBRARY)
443+
if(CMAKE_Fortran_COMPILER)
444+
include(CheckFortranSourceCompiles)
445+
check_fortran_source_compiles("program check_lapack
446+
implicit none
447+
double precision, external :: disnan
448+
print *, disnan(0.)
449+
end" LAPACK_real64_links SRC_EXT f90)
450+
451+
check_fortran_source_compiles("program check_lapack
452+
implicit none
453+
real, external :: sisnan
454+
print *, sisnan(0.)
455+
end" LAPACK_real32_links SRC_EXT f90)
456+
457+
if(LAPACK_real64_links OR LAPACK_real32_links)
458+
set(LAPACK_links TRUE)
459+
endif()
460+
else(CMAKE_Fortran_COMPILER)
461+
set(LAPACK_links TRUE) # complex to check with various distinct LapackE APIs
462+
endif(CMAKE_Fortran_COMPILER)
463+
endif(LAPACK_LIBRARY)
464+
465+
set(CMAKE_REQUIRED_LIBRARIES)
466+
437467
include(FindPackageHandleStandardArgs)
438468
find_package_handle_standard_args(LAPACK
439-
REQUIRED_VARS LAPACK_LIBRARY
469+
REQUIRED_VARS LAPACK_LIBRARY LAPACK_links
440470
HANDLE_COMPONENTS)
441471

442472
set(BLAS_LIBRARIES ${BLAS_LIBRARY})

0 commit comments

Comments
 (0)