Find{BLAS,LAPACK}: Fix when used in pure Fortran projects (#16039)

Use `CMAKE_<LANG>_COMPILER_LOADED` to detect enabled languages because
`if( _LANGUAGES_ MATCHES C )` is always true on Windows as the RC
language is activated automatically and matches C.
This commit is contained in:
Melven Roehrig-Zoellner 2016-04-03 23:00:44 +02:00 committed by Brad King
parent e0cc8bf5d7
commit 1694112dfa
2 changed files with 18 additions and 14 deletions

View File

@ -59,12 +59,7 @@ set(CMAKE_REQUIRED_QUIET ${BLAS_FIND_QUIETLY})
set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
# Check the language being used # Check the language being used
get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES ) if( NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED) )
if( _LANGUAGES_ MATCHES Fortran )
set( _CHECK_FORTRAN TRUE )
elseif( (_LANGUAGES_ MATCHES C) OR (_LANGUAGES_ MATCHES CXX) )
set( _CHECK_FORTRAN FALSE )
else()
if(BLAS_FIND_REQUIRED) if(BLAS_FIND_REQUIRED)
message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.") message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
else() else()
@ -132,7 +127,7 @@ if(_libraries_work)
# Test this combination of libraries. # Test this combination of libraries.
set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_thread}) set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_thread})
# message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}") # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
if (_CHECK_FORTRAN) 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()
check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS) check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
@ -483,7 +478,7 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
if (NOT WIN32) if (NOT WIN32)
set(LM "-lm") set(LM "-lm")
endif () endif ()
if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) if (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED) if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
find_package(Threads) find_package(Threads)
else() else()

View File

@ -48,11 +48,20 @@
set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES) # Check the language being used
if (NOT _LANGUAGES_ MATCHES Fortran) if( NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED) )
include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake) if(LAPACK_FIND_REQUIRED)
else () message(FATAL_ERROR "FindLAPACK requires Fortran, C, or C++ to be enabled.")
else()
message(STATUS "Looking for LAPACK... - NOT found (Unsupported languages)")
return()
endif()
endif()
if (CMAKE_Fortran_COMPILER_LOADED)
include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake) include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake)
else ()
include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
endif () endif ()
include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake) include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
@ -125,7 +134,7 @@ if(_libraries_work)
set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_threads}) set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_threads})
endif() endif()
# message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}") # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
if (NOT _LANGUAGES_ MATCHES Fortran) if (NOT CMAKE_Fortran_COMPILER_LOADED)
check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS) check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
else () else ()
check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS) check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
@ -250,7 +259,7 @@ if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
if (NOT WIN32) if (NOT WIN32)
set(LM "-lm") set(LM "-lm")
endif () endif ()
if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) if (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
find_PACKAGE(Threads) find_PACKAGE(Threads)
else() else()