Fortran 95 with ninja

309 views
Skip to first unread message

Bill Hoffman

unread,
Jul 2, 2012, 12:09:01 PM7/2/12
to ninja...@googlegroups.com
Hi,

I am wondering if this would be possible with ninja. CMake has support
for Fortran 95. However, it requires a Fortran parser that is part of
CMake. Fortran 95 has a module system which is essentially a header
file generation system. So, in C/C++ you create a foo.h to go along
with foo.c and if bar.c wants to use functions from foo.c, it does a
#include "foo.h". ninja uses gcc -M to create the depend tree for this
case.

However, with Fortran95, there is no foo.h. Instead bar.f95 simply
states "use foo", and foo just declares a module to be used. The
compiler will then generate a .mod file which is sort of like foo.h.
The trouble is you have to know the order of depends BEFORE you can even
invoke the compiler, so there is no -M option that can be used during
compile time. This is because compile time is too late. If the .mod
file is not found the compile will fail. So, you have to compile foo.f95
before bar.f95.

CMake parses all the fortran files first, then invokes the compiler in
the correct order based on which files use each other.

How could this be done in ninja?

Thanks.

-Bill

Maxim Kalaev

unread,
Jul 3, 2012, 2:00:57 AM7/3/12
to ninja...@googlegroups.com
Can't the solution be as for this one: https://groups.google.com/forum/#!topic/ninja-build/Zqygj8hQbdI?

Bill Hoffman

unread,
Jul 5, 2012, 5:39:03 PM7/5/12
to ninja...@googlegroups.com
On 7/3/2012 2:00 AM, Maxim Kalaev wrote:
> Can't the solution be as for this one:
> https://groups.google.com/forum/#!topic/ninja-build/Zqygj8hQbdI
> <https://groups.google.com/forum/#%21topic/ninja-build/Zqygj8hQbdI>?
>

No that does not help. Fortran source files contain implicit
dependencies that affect the order of build required. They must
be scanned before even one source can be compiled. Is there a way to do
a scan of a file before it is compile, and then have ninja load the dep
file? I already have the fortran scanner, just need a way to hook it
into ninja.

Something like this:

- scan all fortran files and compute .dep files
- do the build of the fortran files in the order dictated by the scan
--
Bill Hoffman
Kitware, Inc.
28 Corporate Drive
Clifton Park, NY 12065
bill.h...@kitware.com
http://www.kitware.com
518 881-4905 (Direct)
518 371-3971 x105
Fax (518) 371-4573


Maxim Kalaev

unread,
Jul 8, 2012, 11:36:24 AM7/8/12
to ninja...@googlegroups.com


On Thursday, July 5, 2012 11:39:03 PM UTC+2, Bill Hoffman wrote:
On 7/3/2012 2:00 AM, Maxim Kalaev wrote:
> Can't the solution be as for this one:
> https://groups.google.com/forum/#!topic/ninja-build/Zqygj8hQbdI
> <https://groups.google.com/forum/#%21topic/ninja-build/Zqygj8hQbdI>?
>

No that does not help. Fortran source files contain implicit
dependencies that affect the order of build required.  They must
be scanned before even one source can be compiled.  Is there a way to do
a scan of a file before it is compile, and then have ninja load the dep
file?  I already have the fortran scanner, just need a way to hook it
into ninja.

Something like this:

- scan all fortran files and compute .dep files
- do the build of the fortran files in the order dictated by the scan
I am not sure where the problem is. Here is what I had in mind:
1. Use CMake to create ninja rules with order constraints.
2. Make fortran .o files depending on .o.dep files
3. Create .o.dep rules invoking your parser and writing updated dependencies. Patch which I referred you to reloads dep file before making a target, which gives you a chance to invoke your parser to create a proper dep file and to enforce building order.

Reply all
Reply to author
Forward
0 new messages