Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 52 additions & 22 deletions cmake/find_scripts/FindCBLAS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,47 +57,75 @@ This module defines the following variables:

set(_default_pkgs cblas blas-netlib openblas blas-atlas)

set(CBLAS_FOUND)
set(CBLAS_LIBRARIES)
set(CBLAS_INCLUDEDIR)
set(CBLAS_INCLUDE_DIRS)
set(CBLAS_VERSION)
set(CBLAS_LINKER_FLAGS)
set(HAVE_CBLAS_DGEMM)

macro(_test_package)
pkg_check_modules(PKGC_CBLAS QUIET ${CBLAS_PKGCONFIG})
if(PKGC_CBLAS_FOUND)
set(_cblas_found "${PKGC_CBLAS_FOUND}")
set(_cblas_libraries "${PKGC_CBLAS_LINK_LIBRARIES}")
set(_cblas_includedir "${PKGC_CBLAS_INCLUDEDIR}")
set(_cblas_include_dirs ${PKGC_CBLAS_INCLUDEDIR}
${PKGC_CBLAS_INCLUDE_DIRS})
set(_cblas_version "${PKGC_CBLAS_VERSION}")
set(_cblas_linker_flags "${PKGC_CBLAS_LDFLAGS}")

list(REMOVE_DUPLICATES CBLAS_INCLUDE_DIRS)
list(FILTER _cblas_linker_flags EXCLUDE REGEX "^-L\.*|^-l\.*")

include(CheckSymbolExists)
set(CMAKE_REQUIRED_LIBRARIES "${_cblas_libraries}")
set(CMAKE_REQUIRED_INCLUDES "${_cblas_includedir}")
set(CMAKE_REQUIRED_QUIET ON)
check_symbol_exists(cblas_dgemm "cblas.h" HAVE_CBLAS_DGEMM)
unset(CMAKE_REQUIRED_LIBRARIES)
unset(CMAKE_REQUIRED_INCLUDES)
unset(CMAKE_REQUIRED_QUIET)

set(CBLAS_FOUND "${_cblas_found}")
set(CBLAS_LIBRARIES "${_cblas_libraries}")
set(CBLAS_INCLUDEDIR "${_cblas_includedir}")
set(CBLAS_INCLUDE_DIRS "${_cblas_include_dirs}")
set(CBLAS_VERSION "${_cblas_version}")
set(CBLAS_LINKER_FLAGS "${_cblas_linker_flags}")
endif()
endmacro()

macro(_search_cblas_pkgs)
foreach(_pkg ${_default_pkgs})
pkg_check_modules(PKGC_CBLAS QUIET ${_pkg})
if(PKGC_CBLAS_FOUND)
set(CBLAS_PKGCONFIG ${_pkg})
_test_package()
if(HAVE_CBLAS_DGEMM)
break()
endif()
endif()
endforeach()
endmacro()

if(CBLAS_PREFER_PKGCONFIG)
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
if(NOT CBLAS_PKGCONFIG)
if(CBLAS_PKGCONFIG)
_test_package()
else()
_search_cblas_pkgs()
endif()
pkg_check_modules(PKGC_CBLAS QUIET ${CBLAS_PKGCONFIG})
if(PKGC_CBLAS_FOUND)
set(CBLAS_FOUND ${PKGC_CBLAS_FOUND})
set(CBLAS_LIBRARIES "${PKGC_CBLAS_LINK_LIBRARIES}")
set(CBLAS_INCLUDEDIR "${PKGC_CBLAS_INCLUDEDIR}")
set(CBLAS_INCLUDE_DIRS ${PKGC_CBLAS_INCLUDEDIR}
${PKGC_CBLAS_INCLUDE_DIRS})
set(CBLAS_VERSION "${PKGC_CBLAS_VERSION}")
set(CBLAS_LINKER_FLAGS "${PKGC_CBLAS_LDFLAGS}")

list(REMOVE_DUPLICATES CBLAS_INCLUDE_DIRS)
list(FILTER CBLAS_LINKER_FLAGS EXCLUDE REGEX "^-L\.*|^-l\.*")
endif()
endif()
endif()

unset(_default_pkgs)

include(CheckSymbolExists)
set(CMAKE_REQUIRED_LIBRARIES ${CBLAS_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${CBLAS_INCLUDEDIR})
set(CMAKE_REQUIRED_QUIET ${CBLAS_FIND_QUIETLY})
check_symbol_exists(cblas_dgemm "cblas.h" HAVE_CBLAS_DGEMM)
unset(CMAKE_REQUIRED_LIBRARIES)
unset(CMAKE_REQUIRED_INCLUDES)
unset(CMAKE_REQUIRED_QUIET)
if(NOT HAVE_CBLAS_DGEMM)
message(STATUS "Looking for cblas_dgemm - not found")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Expand All @@ -106,6 +134,8 @@ find_package_handle_standard_args(
VERSION_VAR CBLAS_VERSION)
mark_as_advanced(CBLAS_LIBRARIES CBLAS_INCLUDEDIR)

message(STATUS "Using CBLAS package: ${CBLAS_PKGCONFIG}")

if(CBLAS_FOUND AND NOT TARGET CBLAS::CBLAS)
add_library(CBLAS::CBLAS INTERFACE IMPORTED)
set_target_properties(
Expand Down
93 changes: 61 additions & 32 deletions cmake/find_scripts/FindLAPACKE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Input Variables

The following variables may be set to influence this module's behavior:

``CBLAS_PREFER_PKGCONFIG``
``LAPACKE_PREFER_PKGCONFIG``

If set ``pkg-config`` will be used to search for a CBLAS library
If set ``pkg-config`` will be used to search for a LAPACKE library
and if one is found that is used.
Note: this is currently the only method.

Expand Down Expand Up @@ -48,61 +48,88 @@ This module defines the following variables:
``LAPACKE_LIBRARIES``
list of libraries (using full path name) to link against to use LAPACKE
``LAPACKE_INCLUDE_DIRS``
path to the CBLAS include directory.
path to the LAPACKE include directory.
``LAPACKE_VERSION``
version of the module providing LAPACKE

#]=======================================================================]

set(_default_pkgs lapacke openblas)

set(LAPACKE_FOUND)
set(LAPACKE_LIBRARIES)
set(LAPACKE_INCLUDEDIR)
set(LAPACKE_INCLUDE_DIRS)
set(LAPACKE_VERSION)
set(LAPACKE_LINKER_FLAGS)
set(HAVE_LAPACKE_DGESV)

macro(_test_package)
pkg_check_modules(PKGC_LAPACKE QUIET ${LAPACKE_PKGCONFIG})
if(PKGC_LAPACKE_FOUND)
set(_lapacke_found ${PKGC_LAPACKE_FOUND})
set(_lapacke_libraries "${PKGC_LAPACKE_LINK_LIBRARIES}")
if(MSVC)
# MSVC needs msvc/lapacke.h to define custom complex types
set(_lapacke_includedir "${CMAKE_SOURCE_DIR}/msvc;${PKGC_LAPACKE_INCLUDEDIR}")
else()
set(_lapacke_includedir "${PKGC_LAPACKE_INCLUDEDIR}")
endif()
set(_lapacke_include_dirs ${PKGC_LAPACKE_INCLUDEDIR}
${PKGC_LAPACKE_INCLUDE_DIRS})
set(_lapacke_version ${PKGC_LAPACKE_VERSION})
set(_lapacke_linker_flags "${PKGC_LAPACKE_LDFLAGS}")

list(REMOVE_DUPLICATES _lapacke_include_dirs)
list(FILTER _lapacke_linker_flags EXCLUDE REGEX "^-L\.*|^-l\.*")
endif()

include(CheckSymbolExists)
set(CMAKE_REQUIRED_LIBRARIES ${_lapacke_libraries})
set(CMAKE_REQUIRED_INCLUDES ${_lapacke_includedir})
set(CMAKE_REQUIRED_QUIET ON)
check_symbol_exists(LAPACKE_dgesv "lapacke.h" HAVE_LAPACKE_DGESV)
unset(CMAKE_REQUIRED_LIBRARIES)
unset(CMAKE_REQUIRED_INCLUDES)
unset(CMAKE_REQUIRED_QUIET)

set(LAPACKE_FOUND ${_lapacke_found})
set(LAPACKE_LIBRARIES ${_lapacke_libraries})
set(LAPACKE_INCLUDEDIR ${_lapacke_includedir})
set(LAPACKE_INCLUDE_DIRS ${_lapacke_include_dirs})
set(LAPACKE_VERSION ${_lapacke_version})
set(LAPACKE_LINKER_FLAGS ${_lapacke_linker_flags})
endmacro()

macro(_search_lapacke_pkgs)
foreach(_pkg ${_default_pkgs})
pkg_check_modules(PKGC_LAPACKE QUIET ${_pkg})
if(PKGC_LAPACKE_FOUND)
set(LAPACKE_PKGCONFIG ${_pkg})
break()
_test_package()
if(HAVE_LAPACKE_DGESV)
break()
endif()
endif()
endforeach()
endmacro()

if(CBLAS_PREFER_PKGCONFIG)
if(LAPACKE_PREFER_PKGCONFIG)
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
if(NOT LAPACKE_PKGCONFIG)
if(LAPACKE_PKGCONFIG)
_test_package()
else()
_search_lapacke_pkgs()
endif()
pkg_check_modules(PKGC_LAPACKE QUIET ${LAPACKE_PKGCONFIG})
if(PKGC_LAPACKE_FOUND)
set(LAPACKE_FOUND ${PKGC_LAPACKE_FOUND})
set(LAPACKE_LIBRARIES "${PKGC_LAPACKE_LINK_LIBRARIES}")
if(MSVC)
# MSVC needs msvc/lapacke.h to define custom complex types
set(LAPACKE_INCLUDEDIR "${CMAKE_SOURCE_DIR}/msvc;${PKGC_LAPACKE_INCLUDEDIR}")
else()
set(LAPACKE_INCLUDEDIR "${PKGC_LAPACKE_INCLUDEDIR}")
endif()
set(LAPACKE_INCLUDE_DIRS ${PKGC_LAPACKE_INCLUDEDIR}
${PKGC_LAPACKE_INCLUDE_DIRS})
set(LAPACKE_VERSION ${PKGC_LAPACKE_VERSION})
set(LAPACKE_LINKER_FLAGS "${PKGC_LAPACKE_LDFLAGS}")

list(REMOVE_DUPLICATES LAPACKE_INCLUDE_DIRS)
list(FILTER LAPACKE_LINKER_FLAGS EXCLUDE REGEX "^-L\.*|^-l\.*")
endif()
endif()
endif()

unset(_default_pkgs)

include(CheckSymbolExists)
set(CMAKE_REQUIRED_LIBRARIES ${LAPACKE_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${LAPACKE_INCLUDEDIR})
set(CMAKE_REQUIRED_QUIET ${LAPACKE_FIND_QUIETLY})
check_symbol_exists(LAPACKE_dgesv "lapacke.h" HAVE_LAPACKE_DGESV)
unset(CMAKE_REQUIRED_LIBRARIES)
unset(CMAKE_REQUIRED_INCLUDES)
unset(CMAKE_REQUIRED_QUIET)
if(NOT HAVE_LAPACKE_DGESV)
message(STATUS "Looking for LAPACKE_dgesv - not found")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Expand All @@ -112,6 +139,8 @@ find_package_handle_standard_args(
VERSION_VAR LAPACKE_VERSION)
mark_as_advanced(LAPACKE_LIBRARIES LAPACKE_INCLUDEDIR)

message(STATUS "Using LAPACKE package: ${LAPACKE_PKGCONFIG}")

if(LAPACKE_FOUND AND NOT TARGET LAPACKE::LAPACKE)
add_library(LAPACKE::LAPACKE INTERFACE IMPORTED)
set_target_properties(
Expand Down
3 changes: 3 additions & 0 deletions cmake/modules/CheckDependentLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ if(WITH_LAPACKE)
if(NOT WITH_CBLAS)
message(FATAL_ERROR "LAPACKE support requires CBLAS")
endif()
if(NOT LAPACKE_PREFER_PKGCONFIG)
set(LAPACKE_PREFER_PKGCONFIG ON)
endif()
find_package(LAPACKE REQUIRED)
endif()

Expand Down
Loading