[CMake] Fortran-C mixed code
Radu Serban
radu at llnl.gov
Fri Jan 12 15:42:28 EST 2007
I'm attempting to use cmake to configure a package containing both Fortran (F77)
and C source code (as an alternative to the current build system which uses
autoconf+libtool) but I couldn't figure out how to properly do that. Below are
some of the things I have trouble with (I also mention our current solution in
the hope that someone can suggest a cmake equivalent)
1) Determine the F77 intrinsic and run-time libraries
These are needed if CC is in fact a C++ compiler, in which case it must be used
for linking instead of the Fortran compiler (see also 3 below)
With autoconf, we use the AC_F77_LIBRARY_LDFLAGS which sets FLIBS to the
appropriate linker flags.
2) Determine the Fortran name-mangling scheme
With autoconf, one can use the AC_F77_WRAPPERS. An alternative (which we
currently use) is to compile a simple Fortran source:
SUBROUTINE foo
RETURN
END
and then try to link various C sources (which call one of the following: foo,
foo_, foo__, FOO, FOO_, FOO__) to the resulting object file. Depending on which
link attempt succeeds, we can infer the name-mangling scheme.
I was not successful in implementing the above configuration-time test with cmake...
3) Use CC to link the final executable (from some Fortran sources and previously
created libraries from C sources)
Again, we need this only if the CC compiler used in building the required
libraries is a C++ compiler.
3.1) Is there a cmake variable that specifies whether CC is a C++ compiler? If
not, I suspect this can be checked with TRY_COMPILE on the following source:
#ifdef __cplusplus
#define RET 0
#endif
int main()
{
return(RET);
}
3.2) Assuming CC is a C++ compiler, my understanding is that
ADD_EXECUTABLE(foo foo.f)
TARGET_LINK_LIBRARIES(foo my_c_library)
will not work since the Fortran compiler will be used both for compiling foo.f
and for linking foo, correct?
I suspect that this can be done with ADD_CUSTOM_COMMAND.
I'd appreciate any suggestions/pointers/comments. Finally, I should mention that
I do not have the cmake book. Please let me know if the answers to my questions
are already in there and I'll get the book.
Thanks,
--Radu
More information about the CMake
mailing list