summaryrefslogtreecommitdiff
path: root/Modules/FindLAPACK.cmake
diff options
context:
space:
mode:
authorFlorent Pruvost <florent.pruvost@inria.fr>2021-01-14 17:19:07 +0100
committerFlorent Pruvost <florent.pruvost@inria.fr>2021-01-14 17:19:07 +0100
commitd21ad02d44df9e810432bdaf8741beb657d7814d (patch)
tree3c72f6217fc010516e1c644b2329408a8553b38f /Modules/FindLAPACK.cmake
parent438ed46c13bb5fccb5d1b518dab69b6232f79400 (diff)
downloadcmake-d21ad02d44df9e810432bdaf8741beb657d7814d.tar.gz
FindLAPACK: Add pkgconfig support
- mimic FindBLAS Fixes: #21700
Diffstat (limited to 'Modules/FindLAPACK.cmake')
-rw-r--r--Modules/FindLAPACK.cmake58
1 files changed, 42 insertions, 16 deletions
diff --git a/Modules/FindLAPACK.cmake b/Modules/FindLAPACK.cmake
index d5af5da190..45e4be72ff 100644
--- a/Modules/FindLAPACK.cmake
+++ b/Modules/FindLAPACK.cmake
@@ -72,6 +72,12 @@ The following variables may be set to influence this module's behavior:
``BLA_F95``
if ``ON`` tries to find the BLAS95/LAPACK95 interfaces
+``BLA_PREFER_PKGCONFIG``
+ .. versionadded:: 3.20
+
+ if set ``pkg-config`` will be used to search for a LAPACK library first
+ and if one is found that is preferred
+
Imported targets
^^^^^^^^^^^^^^^^
@@ -121,6 +127,26 @@ endif()
include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+function(_add_lapack_target)
+ if(LAPACK_FOUND AND NOT TARGET LAPACK::LAPACK)
+ add_library(LAPACK::LAPACK INTERFACE IMPORTED)
+ set(_lapack_libs "${LAPACK_LIBRARIES}")
+ if(_lapack_libs AND TARGET BLAS::BLAS)
+ # remove the ${BLAS_LIBRARIES} from the interface and replace it
+ # with the BLAS::BLAS target
+ list(REMOVE_ITEM _lapack_libs "${BLAS_LIBRARIES}")
+ list(APPEND _lapack_libs BLAS::BLAS)
+ endif()
+
+ if(_lapack_libs)
+ set_target_properties(LAPACK::LAPACK PROPERTIES
+ INTERFACE_LINK_LIBRARIES "${_lapack_libs}"
+ )
+ endif()
+ unset(_lapack_libs)
+ endif()
+endfunction()
+
macro(_lapack_find_library_setup)
cmake_push_check_state()
set(CMAKE_REQUIRED_QUIET ${LAPACK_FIND_QUIETLY})
@@ -265,6 +291,21 @@ if(NOT LAPACK_NOT_FOUND_MESSAGE)
_lapack_find_dependency(BLAS)
endif()
+# Search with pkg-config if specified
+if(BLA_PREFER_PKGCONFIG)
+ find_package(PkgConfig)
+ pkg_check_modules(PKGC_LAPACK lapack)
+ if(PKGC_LAPACK_FOUND)
+ set(LAPACK_FOUND TRUE)
+ set(LAPACK_LIBRARIES "${PKGC_LAPACK_LINK_LIBRARIES}")
+ if (BLAS_LIBRARIES)
+ list(APPEND LAPACK_LIBRARIES "${BLAS_LIBRARIES}")
+ endif()
+ _add_lapack_target()
+ return()
+ endif()
+endif()
+
# Search for different LAPACK distributions if BLAS is found
if(NOT LAPACK_NOT_FOUND_MESSAGE)
set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
@@ -585,21 +626,6 @@ if(LAPACK_LIBRARIES STREQUAL "LAPACK_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
set(LAPACK_LIBRARIES "")
endif()
-if(LAPACK_FOUND AND NOT TARGET LAPACK::LAPACK)
- add_library(LAPACK::LAPACK INTERFACE IMPORTED)
- set(_lapack_libs "${LAPACK_LIBRARIES}")
- if(_lapack_libs AND TARGET BLAS::BLAS)
- # remove the ${BLAS_LIBRARIES} from the interface and replace it
- # with the BLAS::BLAS target
- list(REMOVE_ITEM _lapack_libs "${BLAS_LIBRARIES}")
- endif()
-
- if(_lapack_libs)
- set_target_properties(LAPACK::LAPACK PROPERTIES
- INTERFACE_LINK_LIBRARIES "${_lapack_libs}"
- )
- endif()
- unset(_lapack_libs)
-endif()
+_add_lapack_target()
_lapack_find_library_teardown()