Commit acda88a5 authored by Sean Warren's avatar Sean Warren Committed by Davis E. King

Determine lapack fortran linking convention in CMake (#934)

* Determine lapack fortran linking convention in CMake

Looks for lapack function with and without trailing underscore - allows use of CLAPACK on windows where functions are decorated but fortran_id.h otherwise assumes they are not

* Use enable_preprocessor_switch for LAPACK decoration detection

* Add lapack decoration defines to config.h.in

* Use correct variable for lapack_libraries
parent 02fbcede
......@@ -502,6 +502,13 @@ if (NOT TARGET dlib)
if (DLIB_USE_LAPACK)
if (lapack_found)
set (dlib_needed_libraries ${dlib_needed_libraries} ${lapack_libraries})
if (lapack_with_underscore)
set(LAPACK_FORCE_UNDERSCORE 1)
enable_preprocessor_switch(LAPACK_FORCE_UNDERSCORE)
elseif (lapack_without_underscore)
set(LAPACK_FORCE_NOUNDERSCORE 1)
enable_preprocessor_switch(LAPACK_FORCE_NOUNDERSCORE)
endif ()
else()
set(DLIB_USE_LAPACK OFF CACHE STRING ${DLIB_USE_LAPACK_STR} FORCE )
toggle_preprocessor_switch(DLIB_USE_LAPACK)
......
......@@ -26,6 +26,8 @@ SET(blas_found 0)
SET(lapack_found 0)
SET(found_intel_mkl 0)
SET(found_intel_mkl_headers 0)
SET(lapack_with_underscore 0)
SET(lapack_without_underscore 0)
message(STATUS "Searching for BLAS and LAPACK")
......@@ -346,3 +348,22 @@ if (NOT lapack_found)
endif()
endif()
# If using lapack, determine whether to mangle functions
if (lapack_found)
include(CheckFunctionExists)
include(CheckFortranFunctionExists)
set(CMAKE_REQUIRED_LIBRARIES ${lapack_libraries})
check_function_exists("sgesv" LAPACK_FOUND_C_UNMANGLED)
check_function_exists("sgesv_" LAPACK_FOUND_C_MANGLED)
if (CMAKE_Fortran_COMPILER_LOADED)
check_fortran_function_exists("sgesv" LAPACK_FOUND_FORTRAN_UNMANGLED)
check_fortran_function_exists("sgesv_" LAPACK_FOUND_FORTRAN_MANGLED)
endif ()
if (LAPACK_FOUND_C_MANGLED OR LAPACK_FOUND_FORTRAN_MANGLED)
set(lapack_with_underscore 1)
elseif (LAPACK_FOUND_C_UNMANGLED OR LAPACK_FOUND_FORTRAN_UNMANGLED)
set(lapack_without_underscore 1)
endif ()
endif()
......@@ -14,6 +14,9 @@
#cmakedefine DLIB_NO_GUI_SUPPORT
#cmakedefine DLIB_ENABLE_STACK_TRACE
#cmakedefine LAPACK_FORCE_UNDERSCORE
#cmakedefine LAPACK_FORCE_NOUNDERSCORE
// You should also consider telling dlib to link against libjpeg, libpng, libgif, fftw, CUDA,
// and a BLAS and LAPACK library. To do this you need to uncomment the following #defines.
#cmakedefine DLIB_JPEG_SUPPORT
......
......@@ -18,7 +18,11 @@
// First we need to know what the conventions for linking
// C with Fortran is on this platform/toolset
#if defined(__GNUC__) || defined(__ICC) || defined(__sgi) || defined(__COMO__) || defined(__KCC)
#if defined(LAPACK_FORCE_UNDERSCORE)
#define DLIB_BIND_FORTRAN_LOWERCASE_UNDERSCORE
#elif defined(LAPACK_FORCE_NOUNDERSCORE)
#define DLIB_BIND_FORTRAN_LOWERCASE
#elif defined(__GNUC__) || defined(__ICC) || defined(__sgi) || defined(__COMO__) || defined(__KCC)
#define DLIB_BIND_FORTRAN_LOWERCASE_UNDERSCORE
#elif defined(__IBMCPP__) || defined(_MSC_VER) || defined(__BORLANDC__)
#define DLIB_BIND_FORTRAN_LOWERCASE
......
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