[Cmake-commits] [cmake-commits] king committed CMakeLists.txt 1.28 1.29 myc.c 1.1 1.2
cmake-commits at cmake.org
cmake-commits at cmake.org
Wed Aug 5 13:40:31 EDT 2009
Update of /cvsroot/CMake/CMake/Tests/Fortran
In directory public:/mounts/ram/cvs-serv17401/Tests/Fortran
Modified Files:
CMakeLists.txt myc.c
Log Message:
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.
Index: myc.c
===================================================================
RCS file: /cvsroot/CMake/CMake/Tests/Fortran/myc.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C 2 -d -r1.1 -r1.2
*** myc.c 4 Aug 2009 18:06:45 -0000 1.1
--- myc.c 5 Aug 2009 17:40:29 -0000 1.2
***************
*** 6,10 ****
F_mysub();
F_my_sub();
! #ifdef F_test_mod_sub
F_test_mod_sub();
#endif
--- 6,10 ----
F_mysub();
F_my_sub();
! #ifdef TEST_MOD
F_test_mod_sub();
#endif
Index: CMakeLists.txt
===================================================================
RCS file: /cvsroot/CMake/CMake/Tests/Fortran/CMakeLists.txt,v
retrieving revision 1.28
retrieving revision 1.29
diff -C 2 -d -r1.28 -r1.29
*** CMakeLists.txt 4 Aug 2009 18:06:45 -0000 1.28
--- CMakeLists.txt 5 Aug 2009 17:40:29 -0000 1.29
***************
*** 16,60 ****
include(FortranCInterface)
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
! if(FORTRAN_C_MODULE_MANGLING_FOUND)
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)
endif()
! set(FORTRAN_FUNCTIONS ${FORTRAN_FUNCTIONS} my_sub mysub )
! create_fortran_c_interface("F_" FORTRAN_FUNCTIONS
! "${testf_BINARY_DIR}/foo.h")
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()
endif()
endif()
--- 16,61 ----
include(FortranCInterface)
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
! 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)
! set(MYC_DEFS TEST_MOD)
! else()
! message("${CMAKE_Fortran_COMPILER_ID} compilers do not support"
! " linking Fortran module procedures from C")
! endif()
endif()
! 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(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()
***************
*** 66,69 ****
--- 67,71 ----
add_library(myc myc.c)
target_link_libraries(myc myfort)
+ set_property(TARGET myc PROPERTY COMPILE_DEFINITIONS ${MYC_DEFS})
add_library(mycxx mycxx.cxx)
More information about the Cmake-commits
mailing list