RFE/bug: Fortran Submodule build time dependency resolution problem (GFortran)
Hi Kitware!
Bug/RFE
This may be a feature request, since submodule support is relatively new... I'm not 100% sure how to best characterize it. At any rate, I would like to report a "bug": Fortran submodules are not compiled in the correct order when parallel builds are used with the makefile generator. The problem is that the submodule needs the parent (sub)module to have been parsed and processed by the compiler before the submodule can be compiled. On my hexa-core MacBook Pro with gfortran
8.2.0 installed via Mac Homebrew, the generated (Unix) Makefile is trying to build the submodule before the parent module. With sufficient free cores and experimentation this should be easy to reproduce. Here is a relatively small library for interfacing VTK from Modern Fortran that can reproduce this problem: https://github.com/porteri/vtkmofo
How to reproduce:
On macOS:
git clone https://github.com/porteri/vtkmofo
mkdir vtkmofo/build
cd vtkmofo/build
export FC=gfortran-8
export CC=gcc-8
cmake ..
make -j # throw everything you've got at it; sometimes builds will happen in the correct order by chance
This results in the following output:
$ make -j
Scanning dependencies of target VTKmofoPassFail
Scanning dependencies of target vtkmofo
[ 3%] Building Fortran object tests/unit/CMakeFiles/VTKmofoPassFail.dir/VTKmofoAnalyze.f90.o
[ 9%] Building Fortran object CMakeFiles/vtkmofo.dir/src/Misc_implementation.f90.o
[ 9%] Building Fortran object CMakeFiles/vtkmofo.dir/src/Precision.f90.o
f951: Fatal Error: Module file 'misc.smod' has not been generated, either because the module does not contain a MODULE PROCEDURE or there is an error in the module.
compilation terminated.
make[2]: *** [CMakeFiles/vtkmofo.dir/src/Misc_implementation.f90.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/vtkmofo.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 9%] Built target VTKmofoPassFail
make: *** [all] Error 2
Similar steps can be taken to reproduce on Linux, with the caveat that you need a very recent GFortran. 7.3 mnight work, but the project we're working on is using 8.2.
Other notes
@robertmaynard mentioned (at the Kitware booth during SC18) that CMake 3.13 has improved submodule support. I have tested with cmake version 3.13.0-rc3
and this problem has not been resolved in this RC. As far as I know it's still present on master
Contract resolution
Would it be possible to get a quote for the timely resolution of this issue? The project this is for has a support contract already. I'm not 100% sure who I should contact about this. I'll dig up an email chain from when the contract was setup and reference this issue.
Thanks!