GSoC 22: fpm-ize the Fortran Ecosystem || Blog Post by Arteev Raina || #7

Good Day Everyone,

My first PR for adding preprocessor support in fpm has finally been merged. The code can be checked here. So, this PR enables the fpm to do the following things :

  • Define the preprocessor configuration in the manifest (fpm.toml) file.
suffixes = ["F90", "f90"]
directories = ["src/feature1", "src/models"]
macros = ["FOO", "BAR"]
  • If cpp preprocessor configuration is detected in fpm.toml file, then fpm will under the hood add the -cpp flag to the default flags so that users will not have to write it manually every time they build the project using fpm.

  • The tests for this feature and example project to test out this feature have also been added.

Last week, I spent my time improving this pull request so that the supported compilers should be able to identify the cpp flag when added to default flags. This is because gfortran compiler understands c preprocessor flag as -cpp and on the other hand in lfortran the syntax to define this flag is like --cpp and I accidentally implicitly assumed that all the compilers provider -cpp flags. Thanks to @jeremie.vandenplas for pointing this out and @zoziha for reviewing the logic for updating the c preprocessor flag depending on the compiler.

Also, I have added the documentation for the preprocessor configuration in fpm-docs repo here.

In this week, I am planning to add the functionality to parse and read the macros that are defined in the fpm.toml file without having the need for the user to write them explicitly in the command. But, if there are any other tasks that mentors and community members want to prioritize before this, feel free to comment below. We will be also discussing about this in detail in our next GSoC Meeting on Thrusday July 14, 2022.

cc: @milancurcic @awvwgk

Thanks & Regards
Arteev Raina


It seems you assume the preprocessor is built in to the compiler, which is at most generally true only for cpp(1) or fpp(1). If called as a separate process intermediate files are often required. WIll they be in a build/ directory or the directory where the input file resides, or will an output directory name be specified?


Hi @urbanjost,

Yes, we have made fpm to support the inbuilt preprocessors in the compiler. But, we will also be working on supporting the third-party preprocessors like fypp.

In ideal case, these files should be in build directory, but if we want to have an output directory I think we will have to add the syntax for that in manifest file to specify the directory (as of now support for this is not there) and then we should also be able to do that.

Arteev Raina