| 1 |
# @HEADER |
| 2 |
# ***************************************************************************** |
| 3 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 4 |
# |
| 5 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 6 |
# SPDX-License-Identifier: BSD-3-Clause |
| 7 |
# ***************************************************************************** |
| 8 |
# @HEADER |
| 9 |
|
| 10 |
# Function that defines variables describing the BLAS name mangling convention |
| 11 |
# |
| 12 |
# Sets the following outputs on success: |
| 13 |
# |
| 14 |
# BLAS_FN_CASE |
| 15 |
# "UPPER" if names are translated to upper-case, |
| 16 |
# "LOWER" otherwise. |
| 17 |
# |
| 18 |
# BLAS_FN_UNDERSCORE |
| 19 |
# "NO_UNDER" if nothing is appended, "UNDER" if |
| 20 |
# one underscore is appended, and "SECOND_UNDER" |
| 21 |
# if a function with an underscore has a second |
| 22 |
# appended. |
| 23 |
# |
| 24 |
# BLAS_FUNC_DEFAULT |
| 25 |
# The default mangling for Fortran functions |
| 26 |
# that do not contain an underscore. |
| 27 |
# |
| 28 |
# The Fortran 2003 name binding facilities and ISO_C_BINDING module |
| 29 |
# should be preferred over cpp macro trickery whenever possible. |
| 30 |
# |
| 31 |
function(blas_mangling) |
| 32 |
|
| 33 |
if(NOT DEFINED BLAS_FN_CASE) |
| 34 |
|
| 35 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 36 |
message("BLAS_MANGLING: Testing name Mangling Schemes!\n") |
| 37 |
endif() |
| 38 |
|
| 39 |
find_file(_blascmakelists blasmangle/ ${CMAKE_MODULE_PATH}) |
| 40 |
if (NOT _blascmakelists) |
| 41 |
message(STATUS "Error, the file blasmangle could not be found so we can not determine Fortran name mangling!") |
| 42 |
return() |
| 43 |
endif() |
| 44 |
|
| 45 |
set(_fcmangledir ${PROJECT_BINARY_DIR}/CMakeFiles/CMakeTmp/blasmangle) |
| 46 |
file(MAKE_DIRECTORY ${_fcmangledir}) |
| 47 |
|
| 48 |
foreach(cdef LOWER UPPER) |
| 49 |
|
| 50 |
foreach(udef UNDER NO_UNDER) |
| 51 |
|
| 52 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 53 |
message("BLAS_MANGLING: Testing ${cdef} ${udef}\n\n") |
| 54 |
endif() |
| 55 |
|
| 56 |
set(_fcmangledir_case "${_fcmangledir}/${cdef}/${udef}") |
| 57 |
file(MAKE_DIRECTORY "${_fcmangledir}/${cdef}") |
| 58 |
file(MAKE_DIRECTORY ${_fcmangledir_case}) |
| 59 |
|
| 60 |
try_compile(_blasmngl ${_fcmangledir_case} ${_blascmakelists} blasmangle |
| 61 |
CMAKE_FLAGS "-DMANGLE_FLAGS:STRING=-DFC_FN_${cdef};-DFC_FN_${udef}" |
| 62 |
OUTPUT_VARIABLE _blasmngl_output |
| 63 |
) |
| 64 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 65 |
message("${_blasmngl_output}\n\n") |
| 66 |
endif() |
| 67 |
|
| 68 |
if(_blasmngl) |
| 69 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 70 |
message("BLAS_MANGLING: Bingo! ${cdef} ${udef} is the correct BLAS name mangling!\n") |
| 71 |
endif() |
| 72 |
set(BLAS_FN_CASE ${cdef} CACHE INTERNAL |
| 73 |
"Case used by Fortran functions" FORCE) |
| 74 |
set(BLAS_FN_UNDERSCORE ${udef} CACHE INTERNAL |
| 75 |
"Underscore convention used by Fortran functions" FORCE) |
| 76 |
break() |
| 77 |
endif() |
| 78 |
|
| 79 |
endforeach() |
| 80 |
|
| 81 |
if(_blasmngl) |
| 82 |
break() |
| 83 |
endif() |
| 84 |
|
| 85 |
endforeach() |
| 86 |
|
| 87 |
if(_blasmngl) |
| 88 |
message(STATUS "BLAS name mangling: ${BLAS_FN_CASE} ${BLAS_FN_UNDERSCORE}") |
| 89 |
else() |
| 90 |
message(STATUS "Warning, cannot automatically determine BLAS mangling.") |
| 91 |
endif() |
| 92 |
|
| 93 |
endif() |
| 94 |
|
| 95 |
if (BLAS_FN_CASE STREQUAL LOWER) |
| 96 |
set(BLAS_NAME_NAME name) |
| 97 |
elseif (BLAS_FN_CASE STREQUAL UPPER) |
| 98 |
set(BLAS_NAME_NAME NAME) |
| 99 |
endif() |
| 100 |
|
| 101 |
if (BLAS_FN_UNDERSCORE) |
| 102 |
if(BLAS_FN_UNDERSCORE STREQUAL "UNDER") |
| 103 |
set(BLAS_FUNC_DEFAULT "(name,NAME) ${BLAS_NAME_NAME} ## _" CACHE INTERNAL "") |
| 104 |
else() |
| 105 |
set(BLAS_FUNC_DEFAULT "(name,NAME) ${BLAS_NAME_NAME}" CACHE INTERNAL "") |
| 106 |
endif() |
| 107 |
endif() |
| 108 |
|
| 109 |
endfunction() |