Newbie question: How did fpm figure the dependency graph?

Hi everyone! I am now mainly using fpm to compile my fortran project. Everytime I run fpm, it is just like a magic. I am wondering: How did fpm figure the dependency graph? Does it reply on the compiler or fpm will figure out how to compile on its own?

Thank you!



Hi @fish830911, welcome to the Discourse! :wave:I’m glad to hear you’re finding fpm useful!

When fpm runs, it reads all the source files in your project, and in any dependencies. Here it identifies which modules are in which files and which modules are used by them. From this information it is able to build a dependency graph on which it performs a topological sort to get the correct compilation order.

Finally, it calls the compiler on each source file, following the sorted order. If you have a version of fpm compiled with Openmp, then it will compile targets in parallel where possible while respecting the dependency graph.

Hope that makes sense! Happy to explain more if you’re interested or if you’re thinking of getting involved.


Hi @lkedward , thank you so much for your response!

I am asking this because I want to convince my professor to use fpm…which requires me to really understand what’s the magic behind it.

After some quick search, I am guessing that dependency.f90 in the fpm project might be the file that is mostly related to the dependency graph? Or am I wrong and it is the other file that is generating the dependency graph?

Thank you!


Convincing other people from a tool works best by showing them.

I added it for most projects I have been developing in my PhD fpm support beside the usual build system, it is a single manifest file and doesn’t add as much noise as a full CMake build system. I used fpm’s capabilities for testing and prototyping this way quite extensively and when I was done with a development cycle and ready to commit my changes I updated and checked the other build systems.

While more work for you, it gives everybody the choice and they can make a comparison from what they are used to and what fpm offers them. Having some solid evidence that fpm is capable of handling your projects and it already in use might be the easiest way to convince somebody of its usefulness.


You are looking for the source parsing module in fpm/fpm_source_parsing.f90 at main · fortran-lang/fpm · GitHub. The dependency graph in fpm/dependency.f90 at main · fortran-lang/fpm · GitHub is only for fetching full projects not for resolving their module dependencies.

1 Like

Just out of interest, what does fpm do if it is confronted by modules with arbitrarily complex circular dependency?

The topological sort occurs by a depth first recursion into the dependency graph; a circular module dependency is detected in fpm when a node is visited twice, in this case it will exit with a message indicating a circular dependency was found.

1 Like

Now that is cool! I have had real trouble in the past with Intel / Visual Studio not correctly identifying that I have been daft! Just another reason for me to get started on fpm!

1 Like

Follow up question: does fpm display a list of modules that it has detected to be in the circular dependency?

Sadly not at the moment. Currently it will just display the source file at which the cycle was first detected.
Displaying the full list of modules in the cycle is a good idea :+1:

1 Like