# Fpm: compiler flags and warnings

**URL:** <https://fortran-lang.discourse.group/t/fpm-compiler-flags-and-warnings/8952>\
**Category:** Uncategorized\
**Created:** [December 10, 2024, 2:57pm UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-and-warnings/8952 "2024-12-10T14:57:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwetaski](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@cwetaski](https://fortran-lang.discourse.group/u/cwetaski)\
**Post date:** [December 10, 2024, 2:57pm UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-and-warnings/8952/1 "2024-12-10T14:57:02Z")

</div>

Hi all,

I am now using fpm for a fortran project and I have two questions:

First: it doesn’t appear to be possible to change the default compiler flags corresponding to the `build` and `debug` profiles. When looking at the output from `fpm build --verbose’, I can see that the compiler flags are:

`-cpp -Wall -Wextra -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -fopenmp`

However, if, for example, I wanted to have `-fcheck=all` enabled, I could call `fpm build --flag -fcheck=all`, (and I would also have to manually add the other flags which I would like to keep). Ideally, I would like to be able to configure the default compiler flags corresponding to the `debug` and `release` profiles, so that I don’t have to remember or copy/paste the flags each time. Based on the manifest reference it doesn’t seem possible to do it within `fpm.toml`. Therefore, are my only options to:

a) Modify the environment variable FPM\_FFLAGS? When I do this I see that the flag is added to the default flags, but it doesn’t seem to allow differentiating between debug and release builds nor does it allow for removing any of the default flags.

b) Write a script which calls fpm? Therefore I can configure the script to always call fpm with whichever flags I like using --flag. Then I can have a different script (or define my own flags for the script) for debug vs release builds. Or

c) Use a makefile for complete build control? I would prefer not to do this since I’ve never used make and would rather avoid having to learn another new tool (also I’m on windows so it’s slightly more annoying).

I’m leaning toward option b) since it seems relatively simple, but I’m wondering if I’m missing something more straightforward. And is the lack of configuration available through the manifest intended or is this something which may be added in future releases?

Second: when I call fpm build, the warnings for each file (from `-Wall` and `-Wextra`) are written to log files in the build folder. However, I would like to see the warnings directly when I run fpm build. Is it possible to tell fpm to print the warnings directly to the terminal? Or to a single file. I don’t see such an option available in the documentation. The inconvenience here is that if I have several modules I have to manually check each log file in order to see any compiler warnings. Here I can also write script to automate this (e.g., to combine all the log files), but I was wondering if I can avoid this.

I am quite new to formal software development procedures, so feel free to correct me if I have some fundamental misunderstanding in terms of how I’m approaching fpm as a tool.

Thank you for any and all help with this!

---

<div class="post-metadata">

**Author:** ![hkvzjal](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/hkvzjal/32/3055_2.png) [@hkvzjal](https://fortran-lang.discourse.group/u/hkvzjal)\
**Post date:** [December 10, 2024, 6:10pm UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-and-warnings/8952/2 "2024-12-10T18:10:20Z")

</div>

Regarding your first problem, have you tried response files? You can create a `fpm.rsp` file and create several profiles to build/test/run your projects. I’ve found this very useful and easy to use.

Here a very simple example [fast\_math/fpm.rsp at main · jalvesz/fast\_math · GitHub](https://github.com/jalvesz/fast_math/blob/main/fpm.rsp)

Once you have a rsp in your project you can then do `fpm @your_profile`

Your option b) is also a very good one, you can find something like that for stdlib here [stdlib/config/fypp\_deployment.py at 38485d8eca7dfb726254a638265c790e858d7cea · fortran-lang/stdlib · GitHub](https://github.com/fortran-lang/stdlib/blob/38485d8eca7dfb726254a638265c790e858d7cea/config/fypp_deployment.py#L125) for inspiration

---

<div class="post-metadata">

**Author:** ![cwetaski](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@cwetaski](https://fortran-lang.discourse.group/u/cwetaski)\
**Post date:** [December 10, 2024, 7:12pm UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-and-warnings/8952/3 "2024-12-10T19:12:25Z")

</div>

Okay, yes the response file solution seems very simple. I saw it in fpm --help but it seems to not be super well documented and I didn’t really understand it. If I ever want to do more complicated stuff the python script looks like a good choice. Thank you!

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [December 10, 2024, 8:39pm UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-and-warnings/8952/4 "2024-12-10T20:39:21Z")

</div>

> [@cwetaski](#):
>
> is the lack of configuration available through the manifest intended or is this something which may be added in future releases?

We had the design for supporting this worked out and mostly implemented, but it didn’t quite get over the finish line.

> <https://github.com/fortran-lang/fpm/pull/498>
>
> \### This pull request contains all my contribution implemented during my \_\*\*GSoC… 2021 Handling compiler arguments project\*\*\_.
> I have implemented the following features:
> \- parsing of profiles table in toml syntax
> \- profiles representation in package
> \- scope of flags (project-wide profiles, package-wide profiles, files scope flags)
> \- organise compiled code into multiple build directories based on the flags of each source file
> \- handle compiler profiles hierarchy (user-specified \> parent user-specified \> built-in profiles)
> 
> \*\*Changes:\*\*
> \- Move the default compiler flags to \`profiles.f90\` to the function \`get\_default\_profiles\`, which returns an array of \`profile\_config\_t\`s
> \- Change \`'gfortran'\` in \`fpm.90/build\_model\` to \`DEFAULT\_COMPILER\` introduced in \`profiles.f90\`, for consistency
> \- Add \`proj\_dir\` argument to \`get\_package\_data\` and \`new\_package\` for file scope profiles
> \- Extend \`package\_t\` and \`package\_config\_t\` definitions with \`profile\_config\_t\`
> \- Create all \`include\_dirs\` at the beginning of \`build\_package\` subroutine
> \- Remove \`build\_name\` from \`fpm\_command\_line\` and simplify \`check\_build\_vals\` subroutine
> \- Modify \`fpm\_compiler/get\_module\_flags\` not to include any directories, but just handle module flags
> \- Add a conditional checking for allocation of fields in \`fpm\_model\` - Should fix issues with \`show\_model\`
> \- Replace \`model%output\_directory\` with function \`get\_output\_directory\`
> 
> \*\*New features:\*\*
> \- \`profile\_config\_t\` and \`profiles\` toml table parser in \`src/fpm/manifest/profiles.f90\`
> \- \`find\_profile\` subroutine which finds a profile with given parameters in an array of \`profile\_config\_t\`
> \- \`info\_profile\` function which returns representation of a profile as a string
> \- Add flags to targets in \`fpm\_targets/build\_target\_list\`
> \- Tests for profiles in \`test\_manifest.f90\`
> \- Example packages tested by \`ci/run\_tests.sh\`
> 
> \*\*My blog on Fortran-lang discourse\*\*
> \[\*link to Fortran-lang discourse\*\](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297)

If anyone has interest and time to update this and get it finished I’d be happy to provide guidance and support.

> [@cwetaski](#):
>
> Is it possible to tell fpm to print the warnings directly to the terminal?

Yes. Use the `--verbose` option. I.e. `fpm build --verbose`.

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [December 10, 2024, 11:43pm UTC](https://fortran-lang.discourse.group/t/fpm-compiler-flags-and-warnings/8952/5 "2024-12-10T23:43:24Z")

</div>

Response files were expected to be superseded by the manifest file (fpm.tom) options, as those would be part of the project and so portably  
would help set options needed by dependencies as well. They are a feature of the M\_CLI2 command line parser and documented in greater detail at

[https://urbanjost.github.io/M\_CLI2/set\_args.3m\_cli2.html](https://urbanjost.github.io/M_CLI2/set_args.3m_cli2.html)

They get a good deal of usage, so perhaps a more extensive description  
should be added that could be invoked via “fpm help response” somewhat like the extended description of the --runner option can be seen via “fpm help runner”.

Perhaps the highest risk using a script is whether it can run in both MSWindows and GNU/Linux and Unix if multiple environments are supported, particularly if the package will be shared with others. But by definition, a script is very flexible. One variant is instead of calling fpm from the script, the script can be written as an alternate “compiler” and then setting FPM\_COMPILER invokes that script.
