1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

FindLAPACK: Add pkgconfig support

- mimic FindBLAS

Fixes: #21700
This commit is contained in:
Florent Pruvost
2021-01-14 17:19:07 +01:00
parent 438ed46c13
commit d21ad02d44

View File

@@ -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()