[CMake] Fortran to C mapping module
Bill Hoffman
bill.hoffman at kitware.com
Mon Oct 27 21:46:08 EDT 2008
I have just checked in a module to help with the linking of Fortran from
C. I would appreciate some feedback, and perhaps some testing with
different Fortran compilers. Does anyone know of a web site that lists
different Fortran compiler name mangling schemes?
The module is here: Modules/FortranCInterface.cmake
You use it like this:
project(test C Fortran)
cmake_minimum_required(VERSION 2.7)
include(FortranCInterface)
# the : is used for subroutines that are in a Fortran module
set(FORTRAN_FUNCTIONS mysub test_mod:sub)
create_fortran_c_interface("F_" FORTRAN_FUNCTIONS
"${test_BINARY_DIR}/foo.h")
include_directories("${test_BINARY_DIR}")
add_executable(foo foo.c foo.f mysub.f)
-----foo.c------
#include "foo.h"
extern F_test_mod_sub();
extern F_mysub();
int main()
{
F_mysub();
F_test_mod_sub();
}
----mysub.f-----
subroutine mysub
end subroutine
---- foo.f -----
module test_mod
interface dummy
module procedure sub
end interface
contains
subroutine sub
end subroutine
end module test_mod
---- example generated foo.h for gcc/gfortran-----
#define F_mysub mysub_
#define F_test_mod_sub __test_mod_MOD_sub
Thanks.
-Bill
More information about the CMake
mailing list