Skip to content

Commit 1fcc411

Browse files
authored
cmake: test CBLAS and LAPACKE packages for req. symbols (#7629)
1 parent 6e79a3f commit 1fcc411

3 files changed

Lines changed: 116 additions & 54 deletions

File tree

cmake/find_scripts/FindCBLAS.cmake

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,47 +57,75 @@ This module defines the following variables:
5757

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

60+
set(CBLAS_FOUND)
61+
set(CBLAS_LIBRARIES)
62+
set(CBLAS_INCLUDEDIR)
63+
set(CBLAS_INCLUDE_DIRS)
64+
set(CBLAS_VERSION)
65+
set(CBLAS_LINKER_FLAGS)
66+
set(HAVE_CBLAS_DGEMM)
67+
68+
macro(_test_package)
69+
pkg_check_modules(PKGC_CBLAS QUIET ${CBLAS_PKGCONFIG})
70+
if(PKGC_CBLAS_FOUND)
71+
set(_cblas_found "${PKGC_CBLAS_FOUND}")
72+
set(_cblas_libraries "${PKGC_CBLAS_LINK_LIBRARIES}")
73+
set(_cblas_includedir "${PKGC_CBLAS_INCLUDEDIR}")
74+
set(_cblas_include_dirs ${PKGC_CBLAS_INCLUDEDIR}
75+
${PKGC_CBLAS_INCLUDE_DIRS})
76+
set(_cblas_version "${PKGC_CBLAS_VERSION}")
77+
set(_cblas_linker_flags "${PKGC_CBLAS_LDFLAGS}")
78+
79+
list(REMOVE_DUPLICATES CBLAS_INCLUDE_DIRS)
80+
list(FILTER _cblas_linker_flags EXCLUDE REGEX "^-L\.*|^-l\.*")
81+
82+
include(CheckSymbolExists)
83+
set(CMAKE_REQUIRED_LIBRARIES "${_cblas_libraries}")
84+
set(CMAKE_REQUIRED_INCLUDES "${_cblas_includedir}")
85+
set(CMAKE_REQUIRED_QUIET ON)
86+
check_symbol_exists(cblas_dgemm "cblas.h" HAVE_CBLAS_DGEMM)
87+
unset(CMAKE_REQUIRED_LIBRARIES)
88+
unset(CMAKE_REQUIRED_INCLUDES)
89+
unset(CMAKE_REQUIRED_QUIET)
90+
91+
set(CBLAS_FOUND "${_cblas_found}")
92+
set(CBLAS_LIBRARIES "${_cblas_libraries}")
93+
set(CBLAS_INCLUDEDIR "${_cblas_includedir}")
94+
set(CBLAS_INCLUDE_DIRS "${_cblas_include_dirs}")
95+
set(CBLAS_VERSION "${_cblas_version}")
96+
set(CBLAS_LINKER_FLAGS "${_cblas_linker_flags}")
97+
endif()
98+
endmacro()
99+
60100
macro(_search_cblas_pkgs)
61101
foreach(_pkg ${_default_pkgs})
62102
pkg_check_modules(PKGC_CBLAS QUIET ${_pkg})
63103
if(PKGC_CBLAS_FOUND)
64104
set(CBLAS_PKGCONFIG ${_pkg})
105+
_test_package()
106+
if(HAVE_CBLAS_DGEMM)
107+
break()
108+
endif()
65109
endif()
66110
endforeach()
67111
endmacro()
68112

69113
if(CBLAS_PREFER_PKGCONFIG)
70114
find_package(PkgConfig QUIET)
71115
if(PKG_CONFIG_FOUND)
72-
if(NOT CBLAS_PKGCONFIG)
116+
if(CBLAS_PKGCONFIG)
117+
_test_package()
118+
else()
73119
_search_cblas_pkgs()
74120
endif()
75-
pkg_check_modules(PKGC_CBLAS QUIET ${CBLAS_PKGCONFIG})
76-
if(PKGC_CBLAS_FOUND)
77-
set(CBLAS_FOUND ${PKGC_CBLAS_FOUND})
78-
set(CBLAS_LIBRARIES "${PKGC_CBLAS_LINK_LIBRARIES}")
79-
set(CBLAS_INCLUDEDIR "${PKGC_CBLAS_INCLUDEDIR}")
80-
set(CBLAS_INCLUDE_DIRS ${PKGC_CBLAS_INCLUDEDIR}
81-
${PKGC_CBLAS_INCLUDE_DIRS})
82-
set(CBLAS_VERSION "${PKGC_CBLAS_VERSION}")
83-
set(CBLAS_LINKER_FLAGS "${PKGC_CBLAS_LDFLAGS}")
84-
85-
list(REMOVE_DUPLICATES CBLAS_INCLUDE_DIRS)
86-
list(FILTER CBLAS_LINKER_FLAGS EXCLUDE REGEX "^-L\.*|^-l\.*")
87-
endif()
88121
endif()
89122
endif()
90123

91124
unset(_default_pkgs)
92125

93-
include(CheckSymbolExists)
94-
set(CMAKE_REQUIRED_LIBRARIES ${CBLAS_LIBRARIES})
95-
set(CMAKE_REQUIRED_INCLUDES ${CBLAS_INCLUDEDIR})
96-
set(CMAKE_REQUIRED_QUIET ${CBLAS_FIND_QUIETLY})
97-
check_symbol_exists(cblas_dgemm "cblas.h" HAVE_CBLAS_DGEMM)
98-
unset(CMAKE_REQUIRED_LIBRARIES)
99-
unset(CMAKE_REQUIRED_INCLUDES)
100-
unset(CMAKE_REQUIRED_QUIET)
126+
if(NOT HAVE_CBLAS_DGEMM)
127+
message(STATUS "Looking for cblas_dgemm - not found")
128+
endif()
101129

102130
include(FindPackageHandleStandardArgs)
103131
find_package_handle_standard_args(
@@ -106,6 +134,8 @@ find_package_handle_standard_args(
106134
VERSION_VAR CBLAS_VERSION)
107135
mark_as_advanced(CBLAS_LIBRARIES CBLAS_INCLUDEDIR)
108136

137+
message(STATUS "Using CBLAS package: ${CBLAS_PKGCONFIG}")
138+
109139
if(CBLAS_FOUND AND NOT TARGET CBLAS::CBLAS)
110140
add_library(CBLAS::CBLAS INTERFACE IMPORTED)
111141
set_target_properties(

cmake/find_scripts/FindLAPACKE.cmake

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Input Variables
1616
1717
The following variables may be set to influence this module's behavior:
1818
19-
``CBLAS_PREFER_PKGCONFIG``
19+
``LAPACKE_PREFER_PKGCONFIG``
2020
21-
If set ``pkg-config`` will be used to search for a CBLAS library
21+
If set ``pkg-config`` will be used to search for a LAPACKE library
2222
and if one is found that is used.
2323
Note: this is currently the only method.
2424
@@ -48,61 +48,88 @@ This module defines the following variables:
4848
``LAPACKE_LIBRARIES``
4949
list of libraries (using full path name) to link against to use LAPACKE
5050
``LAPACKE_INCLUDE_DIRS``
51-
path to the CBLAS include directory.
51+
path to the LAPACKE include directory.
5252
``LAPACKE_VERSION``
5353
version of the module providing LAPACKE
5454
5555
#]=======================================================================]
5656

5757
set(_default_pkgs lapacke openblas)
5858

59+
set(LAPACKE_FOUND)
60+
set(LAPACKE_LIBRARIES)
61+
set(LAPACKE_INCLUDEDIR)
62+
set(LAPACKE_INCLUDE_DIRS)
63+
set(LAPACKE_VERSION)
64+
set(LAPACKE_LINKER_FLAGS)
65+
set(HAVE_LAPACKE_DGESV)
66+
67+
macro(_test_package)
68+
pkg_check_modules(PKGC_LAPACKE QUIET ${LAPACKE_PKGCONFIG})
69+
if(PKGC_LAPACKE_FOUND)
70+
set(_lapacke_found ${PKGC_LAPACKE_FOUND})
71+
set(_lapacke_libraries "${PKGC_LAPACKE_LINK_LIBRARIES}")
72+
if(MSVC)
73+
# MSVC needs msvc/lapacke.h to define custom complex types
74+
set(_lapacke_includedir "${CMAKE_SOURCE_DIR}/msvc;${PKGC_LAPACKE_INCLUDEDIR}")
75+
else()
76+
set(_lapacke_includedir "${PKGC_LAPACKE_INCLUDEDIR}")
77+
endif()
78+
set(_lapacke_include_dirs ${PKGC_LAPACKE_INCLUDEDIR}
79+
${PKGC_LAPACKE_INCLUDE_DIRS})
80+
set(_lapacke_version ${PKGC_LAPACKE_VERSION})
81+
set(_lapacke_linker_flags "${PKGC_LAPACKE_LDFLAGS}")
82+
83+
list(REMOVE_DUPLICATES _lapacke_include_dirs)
84+
list(FILTER _lapacke_linker_flags EXCLUDE REGEX "^-L\.*|^-l\.*")
85+
endif()
86+
87+
include(CheckSymbolExists)
88+
set(CMAKE_REQUIRED_LIBRARIES ${_lapacke_libraries})
89+
set(CMAKE_REQUIRED_INCLUDES ${_lapacke_includedir})
90+
set(CMAKE_REQUIRED_QUIET ON)
91+
check_symbol_exists(LAPACKE_dgesv "lapacke.h" HAVE_LAPACKE_DGESV)
92+
unset(CMAKE_REQUIRED_LIBRARIES)
93+
unset(CMAKE_REQUIRED_INCLUDES)
94+
unset(CMAKE_REQUIRED_QUIET)
95+
96+
set(LAPACKE_FOUND ${_lapacke_found})
97+
set(LAPACKE_LIBRARIES ${_lapacke_libraries})
98+
set(LAPACKE_INCLUDEDIR ${_lapacke_includedir})
99+
set(LAPACKE_INCLUDE_DIRS ${_lapacke_include_dirs})
100+
set(LAPACKE_VERSION ${_lapacke_version})
101+
set(LAPACKE_LINKER_FLAGS ${_lapacke_linker_flags})
102+
endmacro()
103+
59104
macro(_search_lapacke_pkgs)
60105
foreach(_pkg ${_default_pkgs})
61106
pkg_check_modules(PKGC_LAPACKE QUIET ${_pkg})
62107
if(PKGC_LAPACKE_FOUND)
63108
set(LAPACKE_PKGCONFIG ${_pkg})
64-
break()
109+
_test_package()
110+
if(HAVE_LAPACKE_DGESV)
111+
break()
112+
endif()
65113
endif()
66114
endforeach()
67115
endmacro()
68116

69-
if(CBLAS_PREFER_PKGCONFIG)
117+
if(LAPACKE_PREFER_PKGCONFIG)
70118
find_package(PkgConfig QUIET)
71119
if(PKG_CONFIG_FOUND)
72-
if(NOT LAPACKE_PKGCONFIG)
120+
if(LAPACKE_PKGCONFIG)
121+
_test_package()
122+
else()
73123
_search_lapacke_pkgs()
74124
endif()
75-
pkg_check_modules(PKGC_LAPACKE QUIET ${LAPACKE_PKGCONFIG})
76-
if(PKGC_LAPACKE_FOUND)
77-
set(LAPACKE_FOUND ${PKGC_LAPACKE_FOUND})
78-
set(LAPACKE_LIBRARIES "${PKGC_LAPACKE_LINK_LIBRARIES}")
79-
if(MSVC)
80-
# MSVC needs msvc/lapacke.h to define custom complex types
81-
set(LAPACKE_INCLUDEDIR "${CMAKE_SOURCE_DIR}/msvc;${PKGC_LAPACKE_INCLUDEDIR}")
82-
else()
83-
set(LAPACKE_INCLUDEDIR "${PKGC_LAPACKE_INCLUDEDIR}")
84-
endif()
85-
set(LAPACKE_INCLUDE_DIRS ${PKGC_LAPACKE_INCLUDEDIR}
86-
${PKGC_LAPACKE_INCLUDE_DIRS})
87-
set(LAPACKE_VERSION ${PKGC_LAPACKE_VERSION})
88-
set(LAPACKE_LINKER_FLAGS "${PKGC_LAPACKE_LDFLAGS}")
89-
90-
list(REMOVE_DUPLICATES LAPACKE_INCLUDE_DIRS)
91-
list(FILTER LAPACKE_LINKER_FLAGS EXCLUDE REGEX "^-L\.*|^-l\.*")
92-
endif()
93125
endif()
94126
endif()
95127

96128
unset(_default_pkgs)
97129

98-
include(CheckSymbolExists)
99-
set(CMAKE_REQUIRED_LIBRARIES ${LAPACKE_LIBRARIES})
100-
set(CMAKE_REQUIRED_INCLUDES ${LAPACKE_INCLUDEDIR})
101-
set(CMAKE_REQUIRED_QUIET ${LAPACKE_FIND_QUIETLY})
102-
check_symbol_exists(LAPACKE_dgesv "lapacke.h" HAVE_LAPACKE_DGESV)
103-
unset(CMAKE_REQUIRED_LIBRARIES)
104-
unset(CMAKE_REQUIRED_INCLUDES)
105-
unset(CMAKE_REQUIRED_QUIET)
130+
if(NOT HAVE_LAPACKE_DGESV)
131+
message(STATUS "Looking for LAPACKE_dgesv - not found")
132+
endif()
106133

107134
include(FindPackageHandleStandardArgs)
108135
find_package_handle_standard_args(
@@ -112,6 +139,8 @@ find_package_handle_standard_args(
112139
VERSION_VAR LAPACKE_VERSION)
113140
mark_as_advanced(LAPACKE_LIBRARIES LAPACKE_INCLUDEDIR)
114141

142+
message(STATUS "Using LAPACKE package: ${LAPACKE_PKGCONFIG}")
143+
115144
if(LAPACKE_FOUND AND NOT TARGET LAPACKE::LAPACKE)
116145
add_library(LAPACKE::LAPACKE INTERFACE IMPORTED)
117146
set_target_properties(

cmake/modules/CheckDependentLibraries.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ if(WITH_LAPACKE)
224224
if(NOT WITH_CBLAS)
225225
message(FATAL_ERROR "LAPACKE support requires CBLAS")
226226
endif()
227+
if(NOT LAPACKE_PREFER_PKGCONFIG)
228+
set(LAPACKE_PREFER_PKGCONFIG ON)
229+
endif()
227230
find_package(LAPACKE REQUIRED)
228231
endif()
229232

0 commit comments

Comments
 (0)