Cyclical Fortran module dependencies are not supported by CMake or Meson. The code should be restructured to avoid cyclical module dependencies.
This does work:
gfortran mod_b.f90 mod_a.f90 main.f90
cmake -Bbuild
cmake --build build
ninja: build stopped: dependency cycle: mod_a.mod -> mod_b.mod -> mod_a.mod.
also fails with Make
make[2]: Circular CMakeFiles/main.dir/mod_b.f90.o <- CMakeFiles/main.dir/mod_a.mod.stamp dependency dropped.
[ 25%] Building Fortran object CMakeFiles/main.dir/mod_b.f90.o
f951: Fatal Error: Module file 'mod_a.mod' has not been generated, either because the module does not contain a MODULE PROCEDURE or there is an error in the module.
compilation terminated.
meson setup build
meson compile -C build
[1/5] Module scanner.
ninja: build stopped: dependency cycle: main.p/mod_a@impl.smod -> main.p/mod_b@impl.smod -> main.p/mod_a@impl.smod.