Fortran/Ninja: invoking CMake causes Ninja to delete `.mod` files
When rerunning CMake using the Ninja generator (specifically, when CMake is in the generating phase), it deletes all the generated Fortran module files. This forces the subsequent ninja
invocation to rerun the Fortran compiler on the preprocessed versions, which regenerates the object files, which causes all downstream libraries to be relinked.
This does not happen in the Makefile generator, where module files persist between CMake calls.
Locking one of the module files shows where the removal command actually happens:
-- Generating done
CMake Error:
Running
'/usr/local/bin/ninja' '-C' '/Users/s3j/cmake-fortran-module/build-ninja' '-t' 'cleandead'
failed with:
ninja: error: remove(module/bar.mod): Operation not permitted
CMake Generate step failed. Build files cannot be regenerated correctly.
This is using CMake 3.18.4 (and I replicated with the cmake master); and Ninja 1.10.1 (and I replicated with the features-for-fortran
kitware branch as well).