[CMake] Fortran 90 Module Issues in CMake

Matthew Schuchard ms503 at gtri.gatech.edu
Thu Mar 1 11:21:33 EST 2012


Hi, back converting another software distribution to a CMake-based build 
system.  This one has a heavy reliance on Fortran 90 modules, and I 
noticed CMake has some issues with Fortran 90 modules.

In particular, I have noticed that CMake cannot do module dependency 
scanning outside of the current directory/subdirectories.

For example, if /topdir/dir1/src/ has a Fortran file with a dependency 
on a module built in /topdir/dir2/mod/, CMake will not instruct the 
module in /dir2/mod/ to be built before the Fortran file in /dir1/src/.  
This is not necessarily an issue as I can simply instruct CMake to build 
the /dir2/mod directory before the /dir1/src/ directory via 
add_subdirectory ordering.

According to previous mailing list entries found via Google, CMake does 
have functioning dependency scanning within the same directory or 
subdirectories.

However, when attempting to build Fortran 90 files in a directory, I 
have encountered the following error:

*** No rule to make target `dir/CMakeFiles/target.a.dir/foo2.mod.stamp', 
needed by `dir/foo.tmp.f'.  Stop.

where both foo and foo2 are Fortran 90 files and independently 
preprocessed by /lib/cpp in a custom_command (hence the extension 
renamed to .tmp.f).  It appears CMake recognizes that the module built 
from foo2.f90 is needed for foo.f90 (.mod.stamp file), but instead of 
then building the dependent module, gnumake fails.

It seems that maybe a solution here would be for CMake to place its 
.mod.stamp files in the /CMakefiles directories during configuration 
time.  This method would allow the dependency scanning to find necessary 
modules in other directories because of the already present .mod.stamp 
files and build their Fortran 90 files first.  Also, it would hopefully 
avoid the error I have found where a Fortran 90 file is dependent upon a 
module built from another Fortran 90 file in the same directory.

Another potentially great feature which I had requested earlier (but 
hopefully mentioning again helps) is to separate the include_directories 
function from the module paths, since non-GNUFortran compilers (e.g. 
ABSoft) may have different flags for module paths and CMake currently 
doubles all includes and module paths as each other.

Thanks for any feedback and/or assistance.  Using CMake 2.8.6.


More information about the CMake mailing list