FindLAPACK.cmake does not work with Intel MKL libraries
FindLAPACK.cmake has two typos:
-
on line 298 and 311,
BLAS
should beLAPACK
. the name matters because if LAPACK package is dependent on BLAS package, BLAS package would be found. This will cause the call to check_fortran_function_exists() failed for LAPACK because the second parameter (BLAS_WORKS
) is defined. -
on line 129,
set(CMAKE_REQUIRED_LIBRARIES ${_flags} "-Wl,--start-group" ${${LIBRARIES}} ${_blas} "-Wl,--end-group" ${_threads})
would fail at linking stage if
${_blas}
or ${${LIBRARIES}}
has "-Wl,--start-group"
or "-Wl,--end-group"
. The fix is easy:
list(REMOVE_ITEM ${LIBRARIES} "-Wl, --start-group") list(REOMVE_ITEM ${LIBRARIES} "-Wl, --end-group") list(REMOVE_ITEM ${_blas} "-Wl, --end-group") list(REMOVE_ITEM ${_blas} "-Wl, --start-group")
I have attached the patch as a diff file. FindLAPACK.cmake.diff:
diff --git a/Modules/FindLAPACK.cmake b/Modules/FindLAPACK.cmake
index a3c87f81eb..4e0bb6ae69 100644
--- a/Modules/FindLAPACK.cmake
+++ b/Modules/FindLAPACK.cmake
@@ -126,6 +126,10 @@ endforeach()
if(_libraries_work)
# Test this combination of libraries.
+ list(REMOVE_ITEM ${LIBRARIES} "-Wl, --start-group")
+ list(REOMVE_ITEM ${LIBRARIES} "-Wl, --end-group")
+ list(REMOVE_ITEM ${_blas} "-Wl, --end-group")
+ list(REMOVE_ITEM ${_blas} "-Wl, --start-group")
if(UNIX AND BLA_STATIC)
set(CMAKE_REQUIRED_LIBRARIES ${_flags} "-Wl,--start-group" ${${LIBRARIES}} ${_blas} "-Wl,--end-group" ${_threads})
else()
@@ -310,7 +314,7 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
if (NOT ${_LIBRARIES})
check_lapack_libraries(
${_LIBRARIES}
- BLAS
+ LAPACK
${LAPACK_mkl_SEARCH_SYMBOL}
""
""
@@ -323,7 +327,7 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
if (NOT ${_LIBRARIES})
check_lapack_libraries(
${_LIBRARIES}
- BLAS
+ LAPACK
${LAPACK_mkl_SEARCH_SYMBOL}
""
"${IT}"