1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-17 15:32:10 +08:00

Find{BLAS,LAPACK}: Convert internal CHECK_*_LIBRARIES to functions

This commit is contained in:
Brad King
2021-04-14 14:14:46 -04:00
parent a5a6ac7033
commit a57c4eef76
2 changed files with 32 additions and 47 deletions

View File

@@ -208,22 +208,16 @@ endif()
# TODO: move this stuff to a separate module # TODO: move this stuff to a separate module
macro(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir _subdirs) function(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir _subdirs)
# This macro checks for the existence of the combination of fortran libraries # This function checks for the existence of the combination of libraries
# given by _list. If the combination is found, this macro checks (using the # given by _list. If the combination is found, this checks whether can link
# Check_Fortran_Function_Exists macro) whether can link against that library # against that library combination using the name of a routine given by _name
# combination using the name of a routine given by _name using the linker # using the linker flags given by _flags. If the combination of libraries is
# flags given by _flags. If the combination of libraries is found and passes # found and passes the link test, ${LIBRARIES} is set to the list of complete
# the link test, LIBRARIES is set to the list of complete library paths that # library paths that have been found. Otherwise, ${LIBRARIES} is set to FALSE.
# have been found. Otherwise, LIBRARIES is set to FALSE.
# N.B. _prefix is the prefix applied to the names of all cached variables that
# are generated internally and marked advanced by this macro.
# _addlibdir is a list of additional search paths. _subdirs is a list of path
# suffixes to be used by find_library().
set(_libraries_work TRUE) set(_libraries_work TRUE)
set(${LIBRARIES}) set(_libraries)
set(_combined_name) set(_combined_name)
set(_extaddlibdir "${_addlibdir}") set(_extaddlibdir "${_addlibdir}")
@@ -239,7 +233,7 @@ macro(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir
foreach(_library ${_list}) foreach(_library ${_list})
if(_library MATCHES "^-Wl,--(start|end)-group$") if(_library MATCHES "^-Wl,--(start|end)-group$")
# Respect linker flags like --start/end-group (required by MKL) # Respect linker flags like --start/end-group (required by MKL)
list(APPEND ${LIBRARIES} "${_library}") list(APPEND _libraries "${_library}")
else() else()
set(_combined_name ${_combined_name}_${_library}) set(_combined_name ${_combined_name}_${_library})
if(NOT "${_deps}" STREQUAL "") if(NOT "${_deps}" STREQUAL "")
@@ -253,7 +247,7 @@ macro(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir
PATH_SUFFIXES ${_subdirs} PATH_SUFFIXES ${_subdirs}
) )
mark_as_advanced(${_prefix}_${_library}_LIBRARY) mark_as_advanced(${_prefix}_${_library}_LIBRARY)
list(APPEND ${LIBRARIES} ${${_prefix}_${_library}_LIBRARY}) list(APPEND _libraries ${${_prefix}_${_library}_LIBRARY})
set(_libraries_work ${${_prefix}_${_library}_LIBRARY}) set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
endif() endif()
endif() endif()
@@ -265,7 +259,7 @@ macro(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir
endforeach() endforeach()
if(_libraries_work) if(_libraries_work)
# Test this combination of libraries. # Test this combination of libraries.
set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_deps}) set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${_libraries} ${_deps})
if(CMAKE_Fortran_COMPILER_LOADED) if(CMAKE_Fortran_COMPILER_LOADED)
check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS) check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
else() else()
@@ -277,14 +271,15 @@ macro(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir
if(_libraries_work) if(_libraries_work)
if("${_list}" STREQUAL "") if("${_list}" STREQUAL "")
set(${LIBRARIES} "${LIBRARIES}-PLACEHOLDER-FOR-EMPTY-LIBRARIES") set(_libraries "${LIBRARIES}-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
else() else()
list(APPEND ${LIBRARIES} ${_deps}) list(APPEND _libraries ${_deps})
endif() endif()
else() else()
set(${LIBRARIES} FALSE) set(_libraries FALSE)
endif() endif()
endmacro() set(${LIBRARIES} "${_libraries}" PARENT_SCOPE)
endfunction()
set(BLAS_LINKER_FLAGS) set(BLAS_LINKER_FLAGS)
set(BLAS_LIBRARIES) set(BLAS_LIBRARIES)

View File

@@ -190,22 +190,16 @@ endmacro()
# TODO: move this stuff to a separate module # TODO: move this stuff to a separate module
macro(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir _subdirs _blas) function(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir _subdirs _blas)
# This macro checks for the existence of the combination of fortran libraries # This function checks for the existence of the combination of libraries
# given by _list. If the combination is found, this macro checks (using the # given by _list. If the combination is found, this checks whether can link
# Check_Fortran_Function_Exists macro) whether can link against that library # against that library combination using the name of a routine given by _name
# combination using the name of a routine given by _name using the linker # using the linker flags given by _flags. If the combination of libraries is
# flags given by _flags. If the combination of libraries is found and passes # found and passes the link test, ${LIBRARIES} is set to the list of complete
# the link test, LIBRARIES is set to the list of complete library paths that # library paths that have been found. Otherwise, ${LIBRARIES} is set to FALSE.
# have been found. Otherwise, LIBRARIES is set to FALSE.
# N.B. _prefix is the prefix applied to the names of all cached variables that
# are generated internally and marked advanced by this macro.
# _addlibdir is a list of additional search paths. _subdirs is a list of path
# suffixes to be used by find_library().
set(_libraries_work TRUE) set(_libraries_work TRUE)
set(${LIBRARIES}) set(_libraries)
set(_combined_name) set(_combined_name)
set(_extaddlibdir "${_addlibdir}") set(_extaddlibdir "${_addlibdir}")
@@ -221,7 +215,7 @@ macro(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibd
foreach(_library ${_list}) foreach(_library ${_list})
if(_library MATCHES "^-Wl,--(start|end)-group$") if(_library MATCHES "^-Wl,--(start|end)-group$")
# Respect linker flags like --start/end-group (required by MKL) # Respect linker flags like --start/end-group (required by MKL)
list(APPEND ${LIBRARIES} "${_library}") list(APPEND _libraries "${_library}")
else() else()
set(_combined_name ${_combined_name}_${_library}) set(_combined_name ${_combined_name}_${_library})
if(NOT "${_deps}" STREQUAL "") if(NOT "${_deps}" STREQUAL "")
@@ -235,12 +229,11 @@ macro(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibd
PATH_SUFFIXES ${_subdirs} PATH_SUFFIXES ${_subdirs}
) )
mark_as_advanced(${_prefix}_${_library}_LIBRARY) mark_as_advanced(${_prefix}_${_library}_LIBRARY)
list(APPEND ${LIBRARIES} ${${_prefix}_${_library}_LIBRARY}) list(APPEND _libraries ${${_prefix}_${_library}_LIBRARY})
set(_libraries_work ${${_prefix}_${_library}_LIBRARY}) set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
endif() endif()
endif() endif()
endforeach() endforeach()
unset(_library)
foreach(_flag ${_flags}) foreach(_flag ${_flags})
string(REGEX REPLACE "[^A-Za-z0-9]" "_" _flag_var "${_flag}") string(REGEX REPLACE "[^A-Za-z0-9]" "_" _flag_var "${_flag}")
@@ -248,7 +241,7 @@ macro(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibd
endforeach() endforeach()
if(_libraries_work) if(_libraries_work)
# Test this combination of libraries. # Test this combination of libraries.
set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_deps}) set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${_libraries} ${_blas} ${_deps})
if(CMAKE_Fortran_COMPILER_LOADED) if(CMAKE_Fortran_COMPILER_LOADED)
check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS) check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
else() else()
@@ -260,18 +253,15 @@ macro(CHECK_LAPACK_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibd
if(_libraries_work) if(_libraries_work)
if("${_list}${_blas}" STREQUAL "") if("${_list}${_blas}" STREQUAL "")
set(${LIBRARIES} "${LIBRARIES}-PLACEHOLDER-FOR-EMPTY-LIBRARIES") set(_libraries "${LIBRARIES}-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
else() else()
list(APPEND ${LIBRARIES} ${_blas} ${_deps}) list(APPEND _libraries ${_blas} ${_deps})
endif() endif()
else() else()
set(${LIBRARIES} FALSE) set(_libraries FALSE)
endif() endif()
set(${LIBRARIES} "${_libraries}" PARENT_SCOPE)
unset(_extaddlibdir) endfunction()
unset(_libraries_work)
unset(_combined_name)
endmacro()
macro(_lapack_find_dependency dep) macro(_lapack_find_dependency dep)
set(_lapack_quiet_arg) set(_lapack_quiet_arg)