summaryrefslogtreecommitdiffstats
path: root/Tests/Fortran
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-08-05 17:40:29 (GMT)
committerBrad King <brad.king@kitware.com>2009-08-05 17:40:29 (GMT)
commit80f0201b37576a4229ec9453a31d3be804abbcb4 (patch)
tree55229acdf15a513e9acaa6058178f6e76c36c61a /Tests/Fortran
parent7b36fd637cf9fa3fdc70edec924a48a4ca76f5ac (diff)
downloadCMake-80f0201b37576a4229ec9453a31d3be804abbcb4.zip
CMake-80f0201b37576a4229ec9453a31d3be804abbcb4.tar.gz
CMake-80f0201b37576a4229ec9453a31d3be804abbcb4.tar.bz2
Rewrite FortranCInterface module
This is a new FortranCInterface.cmake module to replace the previous prototype. All module support files lie in a FortranCInterface directory next to it. This module uses a new approach to detect Fortran symbol mangling. We build a single test project which defines symbols in a Fortran library (one per object-file) and calls them from a Fortran executable. The executable links to a C library which defines symbols encoding all known manglings (one per object-file). The C library falls back to the Fortran library for symbols it cannot provide. Therefore the executable will always link, but prefers the C-implemented symbols when they match. These symbols store string literals of the form INFO:symbol[<name>] so we can parse them out of the executable. This module also provides a simpler interface. It always detects the mangling as soon as it is included. A single macro is provided to generate mangling macros and optionally pre-mangled symbols.
Diffstat (limited to 'Tests/Fortran')
-rw-r--r--Tests/Fortran/CMakeLists.txt72
-rw-r--r--Tests/Fortran/myc.c2
2 files changed, 38 insertions, 36 deletions
diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt
index c435faa..312b4d7 100644
--- a/Tests/Fortran/CMakeLists.txt
+++ b/Tests/Fortran/CMakeLists.txt
@@ -15,47 +15,48 @@ function(test_fortran_c_interface_module)
# test the C to Fortran interface module
include(FortranCInterface)
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
- if(FORTRAN_C_MODULE_MANGLING_FOUND)
+ if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "SunPro|MIPSpro")
+ set(module_expected 1)
+ endif()
+ if(FortranCInterface_MODULE_FOUND OR module_expected)
set(srcs foo.f)
set(FORTRAN_FUNCTIONS test_mod:sub)
- else(FORTRAN_C_MODULE_MANGLING_FOUND)
- if(CMAKE_Fortran_COMPILER_ID MATCHES "SunPro|MIPSpro")
- message("${CMAKE_Fortran_COMPILER_ID} compilers do not support"
- " linking Fortran module procedures from C")
- else()
- message("This will fail, but let the user see the error")
- set(srcs foo.f)
- set(FORTRAN_FUNCTIONS test_mod:sub)
- endif()
- endif(FORTRAN_C_MODULE_MANGLING_FOUND)
+ set(MYC_DEFS TEST_MOD)
+ else()
+ message("${CMAKE_Fortran_COMPILER_ID} compilers do not support"
+ " linking Fortran module procedures from C")
+ endif()
endif()
- set(FORTRAN_FUNCTIONS ${FORTRAN_FUNCTIONS} my_sub mysub )
- create_fortran_c_interface("F_" FORTRAN_FUNCTIONS
- "${testf_BINARY_DIR}/foo.h")
+ list(APPEND FORTRAN_FUNCTIONS my_sub mysub)
+ FortranCInterface_HEADER(foo.h
+ MACRO_NAMESPACE "FC_"
+ SYMBOL_NAMESPACE "F_"
+ SYMBOLS ${FORTRAN_FUNCTIONS}
+ )
include_directories("${testf_BINARY_DIR}")
-
+
# if the name mangling is not found for a F90 compiler
# print out some diagnostic stuff for the dashboard
- if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
- if(NOT FORTRAN_C_MODULE_MANGLING_FOUND)
- file(GLOB_RECURSE O_OBJFILES
- "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckFortranLink/*.o"
- "*.o" )
- file(GLOB_RECURSE OBJ_OBJFILES
- "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckFortranLink/*.obj")
- find_program(DUMPBIN dumpbin)
- find_program(NM nm)
- foreach(ofile ${O_OBJFILES} ${OBJ_OBJFILES})
- if(DEPENDS)
- execute_process(COMMAND ${DUMPBIN} /symbols "${ofile}"
- OUTPUT_VARIABLE out)
- message("symbols in ${ofile}:\n${out}")
- endif()
- if(NM)
- execute_process(COMMAND ${NM} "${ofile}" OUTPUT_VARIABLE out)
- message("symbols in ${ofile}:\n${out}")
- endif()
- endforeach()
+ if(NOT FortranCInterface_GLOBAL_FOUND OR
+ (NOT FortranCInterface_MODULE_FOUND AND module_expected) )
+ find_program(FortranCInterface_EXE
+ NAMES FortranCInterface
+ PATHS ${FortranCInterface_BINARY_DIR} ${FortranCInterface_BINARY_DIR}/Debug
+ NO_DEFAULT_PATH
+ )
+ find_program(DUMPBIN dumpbin)
+ find_program(NM nm)
+ if(FortranCInterface_EXE)
+ if(DEPENDS)
+ execute_process(COMMAND ${DUMPBIN} /symbols "${FortranCInterface_EXE}"
+ OUTPUT_VARIABLE out)
+ message("symbols in ${FortranCInterface_EXE}:\n${out}")
+ endif()
+ if(NM)
+ execute_process(COMMAND ${NM} "${FortranCInterface_EXE}"
+ OUTPUT_VARIABLE out)
+ message("symbols in ${FortranCInterface_EXE}:\n${out}")
+ endif()
endif()
endif()
message("Fortran = ${CMAKE_Fortran_COMPILER_ID}")
@@ -65,6 +66,7 @@ function(test_fortran_c_interface_module)
add_library(myc myc.c)
target_link_libraries(myc myfort)
+ set_property(TARGET myc PROPERTY COMPILE_DEFINITIONS ${MYC_DEFS})
add_library(mycxx mycxx.cxx)
target_link_libraries(mycxx myc)
diff --git a/Tests/Fortran/myc.c b/Tests/Fortran/myc.c
index b817dff..efd9b68 100644
--- a/Tests/Fortran/myc.c
+++ b/Tests/Fortran/myc.c
@@ -5,7 +5,7 @@ int myc(void)
{
F_mysub();
F_my_sub();
-#ifdef F_test_mod_sub
+#ifdef TEST_MOD
F_test_mod_sub();
#endif
return 0;