Generated sources and dependencies in Visual Studio

I have a Fortran project which I’m porting to Intel Visual Fortran (parallel studio) on Windows. CMake (in my case) generates the Visual Studio solution and project files.
A number of the source files are generated in pre build steps. Some of the generated files depend on non-generated files.

The problem I’m having is that the order of compilation of the source files is not correct which results in errors due to missing module (.mod) files. I assume that this is because the generated source files are not present at the start of the build, so the dependencies cannot be determined.

How can I fix this? I guess one option would be to create a separate target for generating the files, and another target for the actually building them. But I’m hoping there’s a more elegant solution.


Does it work with the Ninja generator? CMake does support generated source files, so dependency scanning shouldn’t be impossible, though I’m not familiar with the Visual Studio support. Could you provide a small case that demonstrates the problem? It could be that a dependency link just needs to be added somewhere.

@brad.king Is there something that needs to be done specially for VS/Fortran and generated sources?

I’m not familiar with Ninja. I can try but I’m not sure if it would be helpful. I’m guessing the VS plugin for IVF has its own dependency management system which scans the source files. I’m not sure dependencies can be manually specified.

Yes. If that plugin has any limitations then we are stuck with them too.

OK, thanks. I’ll post a question on the Intel forum. Maybe they have a suggestion.