Commit 3a7ee535 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'blas-lapack-static'

051c3a04 Find{BLAS,LAPACK}: Add test case covering BLA_STATIC with Intel MKL
f3f71568 Find{BLAS,LAPACK}: Add test case covering BLA_STATIC with Generic vendor
cb6889a0 FindLAPACK: Fix finding generic LAPACK with BLA_STATIC
193714d6 Find{BLAS,LAPACK}: Simplify search for static libraries
2e2db28e

 Find{BLAS,LAPACK}: Simplify check_function_exists state maintenance
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !6036
parents aa7d08e9 051c3a04
set(CMake_TEST_FindALSA "ON" CACHE BOOL "")
set(CMake_TEST_FindBLAS "All" CACHE STRING "")
set(CMake_TEST_FindBLAS_STATIC "Generic" CACHE STRING "")
set(CMake_TEST_FindBoost "ON" CACHE BOOL "")
set(CMake_TEST_FindBoost_Python "ON" CACHE BOOL "")
set(CMake_TEST_FindBZip2 "ON" CACHE BOOL "")
......@@ -24,6 +25,7 @@ set(CMake_TEST_FindIntl "ON" CACHE BOOL "")
set(CMake_TEST_FindJPEG "ON" CACHE BOOL "")
set(CMake_TEST_FindJsonCpp "ON" CACHE BOOL "")
set(CMake_TEST_FindLAPACK "All" CACHE STRING "")
set(CMake_TEST_FindLAPACK_STATIC "Generic" CACHE STRING "")
set(CMake_TEST_FindLibArchive "ON" CACHE BOOL "")
set(CMake_TEST_FindLibinput "ON" CACHE BOOL "")
set(CMake_TEST_FindLibLZMA "ON" CACHE BOOL "")
......
set(CMake_TEST_FindALSA "ON" CACHE BOOL "")
set(CMake_TEST_FindBLAS "All" CACHE STRING "")
set(CMake_TEST_FindBLAS_STATIC "Generic" CACHE STRING "")
set(CMake_TEST_FindBoost "ON" CACHE BOOL "")
set(CMake_TEST_FindBoost_Python "ON" CACHE BOOL "")
set(CMake_TEST_FindBZip2 "ON" CACHE BOOL "")
......@@ -24,6 +25,7 @@ set(CMake_TEST_FindIntl "ON" CACHE BOOL "")
set(CMake_TEST_FindJPEG "ON" CACHE BOOL "")
set(CMake_TEST_FindJsonCpp "ON" CACHE BOOL "")
set(CMake_TEST_FindLAPACK "All" CACHE STRING "")
set(CMake_TEST_FindLAPACK_STATIC "Generic" CACHE STRING "")
set(CMake_TEST_FindLibArchive "ON" CACHE BOOL "")
set(CMake_TEST_FindLibinput "ON" CACHE BOOL "")
set(CMake_TEST_FindLibLZMA "ON" CACHE BOOL "")
......
set(CMake_TEST_FindALSA "ON" CACHE BOOL "")
set(CMake_TEST_FindBLAS "All" CACHE STRING "")
set(CMake_TEST_FindBLAS_STATIC "Generic" CACHE STRING "")
set(CMake_TEST_FindBoost "ON" CACHE BOOL "")
set(CMake_TEST_FindBoost_Python "ON" CACHE BOOL "")
set(CMake_TEST_FindBZip2 "ON" CACHE BOOL "")
......@@ -24,6 +25,7 @@ set(CMake_TEST_FindIntl "ON" CACHE BOOL "")
set(CMake_TEST_FindJPEG "ON" CACHE BOOL "")
set(CMake_TEST_FindJsonCpp "ON" CACHE BOOL "")
set(CMake_TEST_FindLAPACK "All" CACHE STRING "")
set(CMake_TEST_FindLAPACK_STATIC "Generic" CACHE STRING "")
set(CMake_TEST_FindLibArchive "ON" CACHE BOOL "")
set(CMake_TEST_FindLibinput "ON" CACHE BOOL "")
set(CMake_TEST_FindLibLZMA "ON" CACHE BOOL "")
......
set(CMake_TEST_FindBLAS "Intel10_64lp" CACHE STRING "")
set(CMake_TEST_FindBLAS_STATIC "Intel10_64lp" CACHE STRING "")
set(CMake_TEST_FindLAPACK "Intel10_64lp" CACHE STRING "")
set(CMake_TEST_FindLAPACK_STATIC "Intel10_64lp" CACHE STRING "")
include("${CMAKE_CURRENT_LIST_DIR}/configure_external_test.cmake")
......@@ -176,10 +176,7 @@ if(CMAKE_Fortran_COMPILER_LOADED)
else()
include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
cmake_push_check_state()
set(CMAKE_REQUIRED_QUIET ${BLAS_FIND_QUIETLY})
if(BLA_PREFER_PKGCONFIG)
find_package(PkgConfig)
......@@ -192,20 +189,6 @@ if(BLA_PREFER_PKGCONFIG)
endif()
endif()
set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(BLA_STATIC)
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
else()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# for ubuntu's libblas3gf and liblapack3gf packages
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
endif()
endif()
# TODO: move this stuff to a separate module
function(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir _subdirs)
......@@ -220,6 +203,19 @@ function(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlib
set(_libraries)
set(_combined_name)
if(BLA_STATIC)
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
else()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# for ubuntu's libblas3gf and liblapack3gf packages
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
endif()
endif()
set(_extaddlibdir "${_addlibdir}")
if(WIN32)
list(APPEND _extaddlibdir ENV LIB)
......@@ -261,6 +257,7 @@ function(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlib
if(_libraries_work)
# Test this combination of libraries.
set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${_libraries} ${_deps})
set(CMAKE_REQUIRED_QUIET ${BLAS_FIND_QUIETLY})
if(CMAKE_Fortran_COMPILER_LOADED)
check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
else()
......@@ -628,8 +625,6 @@ if(BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All")
endif()
set(_threadlibs "${CMAKE_THREAD_LIBS_INIT}")
if(BLA_STATIC)
set(_blas_STATIC_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
set(CMAKE_FIND_LIBRARY_SUFFIXES "${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}")
if (CMAKE_C_COMPILER_LOADED)
find_package(OpenMP COMPONENTS C)
list(PREPEND _threadlibs "${OpenMP_C_LIBRARIES}")
......@@ -637,8 +632,6 @@ if(BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All")
find_package(OpenMP COMPONENTS CXX)
list(PREPEND _threadlibs "${OpenMP_CXX_LIBRARIES}")
endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES "${_blas_STATIC_CMAKE_FIND_LIBRARY_SUFFIXES}")
unset(_blas_STATIC_CMAKE_FIND_LIBRARY_SUFFIXES)
endif()
check_blas_libraries(
BLAS_LIBRARIES
......@@ -1086,5 +1079,3 @@ if(NOT BLA_F95)
endif()
_add_blas_target()
cmake_pop_check_state()
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
......@@ -127,7 +127,6 @@ if(CMAKE_Fortran_COMPILER_LOADED)
else()
include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
function(_add_lapack_target)
......@@ -163,31 +162,6 @@ function(_add_lapack_target)
endif()
endfunction()
macro(_lapack_find_library_setup)
cmake_push_check_state()
set(CMAKE_REQUIRED_QUIET ${LAPACK_FIND_QUIETLY})
set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(BLA_STATIC)
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
else()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# for ubuntu's libblas3gf and liblapack3gf packages
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
endif()
endif()
endmacro()
macro(_lapack_find_library_teardown)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
unset(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
cmake_pop_check_state()
endmacro()
# TODO: move this stuff to a separate module
function(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir _subdirs _blas)
......@@ -202,6 +176,19 @@ function(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addl
set(_libraries)
set(_combined_name)
if(BLA_STATIC)
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif()
else()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# for ubuntu's libblas3gf and liblapack3gf packages
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
endif()
endif()
set(_extaddlibdir "${_addlibdir}")
if(WIN32)
list(APPEND _extaddlibdir ENV LIB)
......@@ -243,6 +230,7 @@ function(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addl
if(_libraries_work)
# Test this combination of libraries.
set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${_libraries} ${_blas} ${_deps})
set(CMAKE_REQUIRED_QUIET ${LAPACK_FIND_QUIETLY})
if(CMAKE_Fortran_COMPILER_LOADED)
check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
else()
......@@ -285,8 +273,6 @@ macro(_lapack_find_dependency dep)
set(_lapack_quiet_arg)
endmacro()
_lapack_find_library_setup()
set(LAPACK_LINKER_FLAGS)
set(LAPACK_LIBRARIES)
set(LAPACK95_LIBRARIES)
......@@ -634,17 +620,25 @@ if(NOT LAPACK_NOT_FOUND_MESSAGE)
AND (BLA_VENDOR STREQUAL "Generic"
OR BLA_VENDOR STREQUAL "ATLAS"
OR BLA_VENDOR STREQUAL "All"))
if(BLA_STATIC)
# We do not know for sure how the LAPACK reference implementation
# is built on this host. Guess typical dependencies.
set(_lapack_generic_deps "-lgfortran;-lm")
else()
set(_lapack_generic_deps "")
endif()
check_lapack_libraries(
LAPACK_LIBRARIES
LAPACK
cheev
""
"lapack"
""
"${_lapack_generic_deps}"
""
""
"${BLAS_LIBRARIES}"
)
unset(_lapack_generic_deps)
endif()
endif()
......@@ -671,5 +665,3 @@ if(LAPACK_LIBRARIES STREQUAL "LAPACK_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
endif()
_add_lapack_target()
_lapack_find_library_teardown()
......@@ -10,3 +10,16 @@ foreach(vendor IN LISTS CMake_TEST_FindBLAS)
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
endforeach()
foreach(vendor IN LISTS CMake_TEST_FindBLAS_STATIC)
add_test(NAME FindBLAS.Test_${vendor}_Static COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindBLAS/Test"
"${CMake_BINARY_DIR}/Tests/FindBLAS/Test_${vendor}_Static"
${build_generator_args}
--build-project TestFindBLAS
--build-options ${build_options} -DBLA_VENDOR=${vendor} -DBLA_STATIC=ON
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
endforeach()
......@@ -13,7 +13,7 @@ target_link_libraries(test_var PRIVATE ${BLAS_LIBRARIES})
add_test(NAME test_var COMMAND test_var)
if(BLA_VENDOR STREQUAL "Intel10_64lp")
if(NOT BLAS_LIBRARIES MATCHES "^[^;]*mkl_intel_lp64")
if(NOT BLAS_LIBRARIES MATCHES "^(-Wl,--start-group;)?[^;]*mkl_intel_lp64")
message(FATAL_ERROR "BLAS_LIBRARIES does not start in mkl_intel_lp64:\n ${BLAS_LIBRARIES}")
endif()
endif()
......@@ -10,3 +10,16 @@ foreach(vendor IN LISTS CMake_TEST_FindLAPACK)
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
endforeach()
foreach(vendor IN LISTS CMake_TEST_FindLAPACK_STATIC)
add_test(NAME FindLAPACK.Test_${vendor}_Static COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindLAPACK/Test"
"${CMake_BINARY_DIR}/Tests/FindLAPACK/Test_${vendor}_Static"
${build_generator_args}
--build-project TestFindLAPACK
--build-options ${build_options} -DBLA_VENDOR=${vendor} -DBLA_STATIC=ON
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
endforeach()
......@@ -13,7 +13,7 @@ target_link_libraries(test_var PRIVATE ${LAPACK_LIBRARIES})
add_test(NAME test_var COMMAND test_var)
if(BLA_VENDOR STREQUAL "Intel10_64lp")
if(NOT LAPACK_LIBRARIES MATCHES "^[^;]*mkl_intel_lp64")
if(NOT LAPACK_LIBRARIES MATCHES "^(-Wl,--start-group;)?[^;]*mkl_intel_lp64")
message(FATAL_ERROR "LAPACK_LIBRARIES does not start in mkl_intel_lp64:\n ${LAPACK_LIBRARIES}")
endif()
endif()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment