Fortran: Misses dependency with preprocessor and line continuation
I am working with a climate model which originally uses configure & make but our colleagues developed CMake as an alternative.
It looks like CMake can't resolve the module dependency similar to the case mentioned in #18188.
Here is the problematic section:
MODULE mo_cuascent
USE mo_kind, ONLY : wp
USE mo_physical_constants, ONLY : grav, tmelt, vtmpc1, rv, rd, alv, als
#ifndef __ICON__
USE mo_echam_conv_constants, ONLY : lmfdudv, lmfmid, nmctop, cmfcmin, cmfcmax, &
#else
USE mo_echam_conv_constants, ONLY : lmfdudv, lmfmid, cmfcmin, cmfcmax, &
#endif
& cprcon, entrmid, cmfctop, centrmax, cbfac, &
& cminbuoy, cmaxbuoy
USE mo_cuadjust, ONLY : cuadjtq
#ifdef _PROFILE
USE mo_profile, ONLY : trace_start, trace_stop
#endif
During the build, this error occurs:
mo_cuascent.f90(56): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [MO_ECHAM_CONV_CONSTANTS]
USE mo_echam_conv_constants, ONLY : lmfdudv, lmfmid, nmctop, cmfcmin, cmfcmax, &
------^
make.depend
file has
mo_cuascent.f90.o: src/echam/CMakeFiles/echam6.dir/mo_cuadjust.mod.stamp
mo_cuascent.f90.o: src/echam/CMakeFiles/echam6.dir/mo_kind.mod.stamp
mo_cuascent.f90.o: src/echam/CMakeFiles/echam6.dir/mo_physical_constants.mod.stamp
mo_cuascent.f90.o.provides.build: src/echam/CMakeFiles/echam6.dir/mo_cuascent.mod.stamp
mo_cuascent.mod.stamp: src/echam/CMakeFiles/echam6.dir/mo_cuascent.f90.o
Unfortunately mo_echam_conv_constants.f90
is not built yet at that point. Interestingly, when I use parallel make (make -j
) the executable is built by luck.
If I move the trailing continuation lines into the preprocessor directive. Eg:
#ifndef __ICON__
USE mo_echam_conv_constants, ONLY : lmfdudv, lmfmid, nmctop, cmfcmin, cmfcmax, &
& cprcon, entrmid, cmfctop, centrmax, cbfac, &
& cminbuoy, cmaxbuoy
#else
USE mo_echam_conv_constants, ONLY : lmfdudv, lmfmid, cmfcmin, cmfcmax, &
& cprcon, entrmid, cmfctop, centrmax, cbfac, &
& cminbuoy, cmaxbuoy
#endif
USE mo_cuadjust, ONLY : cuadjtq
It works since CMake can now resolve the missing dependency mo_echam_conv_constants
.
mo_cuascent.f90.o: src/echam/CMakeFiles/echam6.dir/mo_cuadjust.mod.stamp
mo_cuascent.f90.o: src/echam/CMakeFiles/echam6.dir/mo_echam_conv_constants.mod.stamp
mo_cuascent.f90.o: src/echam/CMakeFiles/echam6.dir/mo_kind.mod.stamp
mo_cuascent.f90.o: src/echam/CMakeFiles/echam6.dir/mo_physical_constants.mod.stamp
mo_cuascent.f90.o.provides.build: src/echam/CMakeFiles/echam6.dir/mo_cuascent.mod.stamp
mo_cuascent.mod.stamp: src/echam/CMakeFiles/echam6.dir/mo_cuascent.f90.o
I tried this with many different versions of CMake including 3.19.3 but they don't work, unfortunately.
We are using Intel compilers & MPI (mpiifort, mpiicc). I made a workaround using regex to first parse this file before building with CMake since our automatization software depends on CMake.
Could you please have a look at this bug? Kind regards