[CMake] Mixing C++ and Fortran

Bill Hoffman bill.hoffman at kitware.com
Wed Jan 30 08:59:56 EST 2008


Honest Guvnor wrote:
> On Jan 29, 2008 6:21 PM, Bill Hoffman <bill.hoffman at kitware.com> wrote:
>> Good Fortran support is relatively new to CMake.  In fact, CVS CMake is
>> really the only version that handles all the Fortran depend stuff
>> reliably.  CMake relies on the compiler to provide the correct run time
>> libraries.  If you build with a C++ compiler, it will automatically link
>> in the run time libraries for C++ that go with that compiler.  If you
>> link with a fortran compiler, it will get the run time libraries for the
>> fortran compiler.  So, CMake has not had to "care" about system runtime
>> libraries.  It is easy to mix C with anything because both Fortran and
>> C++ always link in the C runtime libraries by default.    Anyway, it is
>> what it is.  If you figure something out, we could add it to the cmake
>> modules directory.
> 
> Thanks for making the current status clear. I had not anticipated
> working with cmake at this level but, then again, I am not sure the
> alternatives currently serve our needs any better. I will take a look
> at the CVS version next week.

My guess on the implementation for this would be creating a new variable 
in cmake CMAKE_Fortran_RUNTIME_LIBRARY.  It would be defined in the 
Platform/(FortranCompiler).cmake file.  If you do a google search on 
mixed link c++ fortran, you can see that each compiler vendor suggests 
the same sort of thing.  Of course the runtime library for fortran is 
called something else for each one...

So, for now, you could do this:

1. put all the fortran code into a shared library
2. put if stuff in your cmake files that create the 
CMAKE_Fortran_RUNTIME_LIBRARY variable for you.

If you create a list of values for CMAKE_Fortran_RUNTIME_LIBRARY, I 
would be happy to put them into CVS CMake's Platform files.

-Bill



More information about the CMake mailing list