[Cmake] Re: How to support FORTRAN ?

Andy Cedilnik andy . cedilnik at kitware . com
21 Aug 2003 10:54:55 -0400


Hi Fang,

There is a plan for adding fortran support in CMake, but until that is
not done, you can always use custom commands to do it. This is all well
documented in Mastering CMake on pages 80 - 87.

It works something like this:

1. Compile fortan file foo.f and bar.f to foo.o and bar.o
2. Link foo.o and bar.o to libFooBar.a
3. Link libFooBar.a to your executable

So, #1:

ADD_CUSTOM_COMMAND(
  OUTPUT ${CURRENT_BINARY_DIR}/foo.o
  DEPENDS ${CURRENT_SOURCE_DIR}/foo.f
  COMMAND ${FORTRAN_COMPILE}
  ARGS -o ${CURRENT_BINARY_DIR}/foo.o ${CURRENT_SOURCE_DIR}/foo.f)

same for bar.f

#2:

ADD_CUSTOM_COMMAND(
  OUTPUT ${CURRENT_BINARY_DIR}/libFooBar.a
  DEPENDS ${CURRENT_BINARY_DIR}/foo.o ${CURRENT_BINARY_DIR}/bar.o
  COMMAND ${CMAKE_AR}
  ARGS cr ${CURRENT_BINARY_DIR}/libFooBar.a ${CURRENT_BINARY_DIR}/foo.o
${CURRENT_BINARY_DIR}/bar.o)

And then #3:

ADD_CUSTOM_TARGET(
  Fortranlibrary
  DEPENDS ${CURRENT_BINARY_DIR}/libFooBar.a)

Now, when you use FooBar, you do something like:

TARGET_LINK_LIBRARY(MyExec ${CURRENT_BINARY_DIR}/libFooBar.a)

Make sure MyExec and Fortranlibrary are in the same directory.

			Andy





On Thu, 2003-08-21 at 10:41, Shunming Fang wrote:
> In our projects, We had to include some programs written by FORTRAN, I
> know in current version, there is no definate way to support it, do you
> think which way I can get around it?