# Handling compiler arguments in fpm project - Blog by Jakub Jelinek

**URL:** <https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297>\
**Category:** GSoC-2021\
**Created:** [May 24, 2021, 5:14pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297 "2021-05-24T17:14:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kubajj](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kubajj/32/400_2.png) [@kubajj](https://fortran-lang.discourse.group/u/kubajj)\
**Post date:** [May 24, 2021, 5:14pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/1 "2021-05-24T17:14:57Z")

</div>

Hello everyone,

my name is Jakub and this summer I am working on compiler arguments support for fpm.  
If you have any suggestions or ideas for this topic, please join the call mentioned in the post below:  
[https://fortran-lang.discourse.group/t/gsoc-project-meeting-fpm-compiler-flags/1265](https://fortran-lang.discourse.group/t/gsoc-project-meeting-fpm-compiler-flags/1265)  
I will try to update you about my progress at least once a week so that I can receive feedback and suggestions from the community.  
I am looking forward to contributing to this awesome project and I want to thank you for giving me this opportunity.

---

<div class="post-metadata">

**Author:** ![kubajj](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kubajj/32/400_2.png) [@kubajj](https://fortran-lang.discourse.group/u/kubajj)\
**Post date:** [May 24, 2021, 5:28pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/2 "2021-05-24T17:28:00Z")

</div>

_ **Progress status - #1** _  
I have spent most of last week and today reading fpm documentation. I have to say that it is quite neat. I like that the [documentation](https://fpm.fortran-lang.org/) allows the user to see both the subroutines and procedure specification and it code itself.  
Today I’ve had a brief chat with Laurence and Brad which helped me to understand the most important parts of the fpm build process.  
For the rest of the week, I plan to research the documentation more in-depth and focus on studying how to write tests in Fortran well. At the end of the week, I also want to have a clear idea of what I need to do for this project and what I should start with.

---

<div class="post-metadata">

**Author:** ![kubajj](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kubajj/32/400_2.png) [@kubajj](https://fortran-lang.discourse.group/u/kubajj)\
**Post date:** [May 28, 2021, 5:37pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/3 "2021-05-28T17:37:00Z")

</div>

_ **Progress status - #2** _  
As mentioned in the previous post this week was about planning for me. After Tuesday’s meeting with @certik, @lkedward, @everythingfunctional, and @awvwgk I summarised the next week’s plan in these points:

1. Create a test package with compiler profiles specified in the toml. This will allow me to test out the features introduced in the steps below.
2. Modify the new\_package subroutine in [`fpm_manifest_package`](https://fpm.fortran-lang.org/module/fpm_manifest_package.html) to accept a new table in the toml file called `profiles`. I have researched the documentation of the fpm modules in depth during the week, but I still need to research more on the [toml-f](https://toml-f.github.io/toml-f/index.html) ones (most likely just the `get_value` methods).  
Then I need to create a new derived type `profile_config_t`, representing each of the profiles parsed out of the toml table. There is going to be an allocatable list of the in `package_config_t`. Profiles need to be handled in `info` and `check` subroutines too, but only `check` is required for basic functionality, therefore I will probably include it in `check` first and in `info` later.
3. I have not researched all the functionalities in the `build_model` subroutine of the `fpm.f90` yet, therefore if I have time when done with steps 1 and 2, I will look into it as the next step is going to be including profiles in `model`.

For anybody interested in this project, please share your suggestions or comments with me or visit one of the weekly mentor chats happening every Thursday at 14.00 UTC at this [link](https://bristol-ac-uk.zoom.us/j/92046613468).

---

<div class="post-metadata">

**Author:** ![kubajj](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kubajj/32/400_2.png) [@kubajj](https://fortran-lang.discourse.group/u/kubajj)\
**Post date:** [June 4, 2021, 2:11pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/4 "2021-06-04T14:11:45Z")

</div>

_ **Progress status - #3** _  
I have started coding on Monday by creating the new source file `fpm_manifest_profiles.f90`. This includes the `profile_config_t` type, all subroutines necessary for parsing toml profiles table and a subroutine `find_profile` which finds the best matching profile based on given arguments.  
The parsing of the toml should follow the following rules:

1. Default behaviour is the creation of a profile with the full specification, e.g.

```auto
[profiles.debug.gfortran.linux]
flags="-g -Wall"

```

1. If a user does not specify the name of the profile flag (`debug` in the last example), add the flags to all profiles that match the other two fields (compiler and OS).
2. If a user does not specify the name of the compiler, use the default compiler name (currently set to `gfortran`).
3. If a user does not specify the operating system, use these flags if no profile matches OS exactly. Example:

```auto
[profiles.debug.gfortran]
flags="-g -Wall"

[profiles.debug.gfortran.windows]
flags="/g /Wall"

```

Assuming we are on Unix based system, the first profile is going to be used. On Windows device, the second profile has priority.  
The built-in profiles from fpm\_compiler are loaded now to the profiles and if a user does not specify a better matching profile, they can be used. If anybody knows, what the `id_f95` stands for, please let me know. I also assumed that `id_nvhpc` should use `nvfortran` as a compiler.

The user’s profile has to be specified from the command line with the `--profile` flag. If this flag is not present, `build_model` checks whether the `settings%flag` field is not empty and in case it is, `debug` profile is used. If both `settings%flag` and `settings%profile` are present, the flags are appended together.

All my commits are in my [Load\_compiler\_arguments](https://github.com/kubajj/fpm/tree/Load_compiler_profiles) branch. If you have any suggestions or comments on my code, please do not hesitate to tell me.

Next steps:

1. Error handling
2. Testing
3. Implementation of `c_flags` and `link_time_flags`
4. Research on dependencies in build\_model and discussion about the flag scope implementation

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [June 5, 2021, 8:28am UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/5 "2021-06-05T08:28:48Z")

</div>

Hey Jakub, great work!

> [@kubajj](#):
>
> The built-in profiles from fpm\_compiler are loaded now to the profiles and if a user does not specify a better matching profile, they can be used. If anybody knows, what the `id_f95` stands for, please let me know. I also assumed that `id_nvhpc` should use `nvfortran` as a compiler.

By the looks of things it is just an alias for the gfortran compiler enumeration which is used commonly on Linux systems (defining code is here: [https://github.com/fortran-lang/fpm/blob/6d9004d93460dc15b99051c90d1b58d724b010e6/src/fpm\_compiler.f90#L47](https://github.com/fortran-lang/fpm/blob/6d9004d93460dc15b99051c90d1b58d724b010e6/src/fpm_compiler.f90#L47)).

Historically on Unix systems the Fortran compiler was named `f77`. Before gfortran became the primary open-source compiler, there were compilers [`g77`](https://gcc.gnu.org/fortran/) and [`g95`](http://g95.sourceforge.net/). Before these there was [`f2c`](https://en.wikipedia.org/wiki/F2c), so `f77` might have been a driver which first translated the Fortran sources to C using `f2c` and then invoked a C compiler. At some point the OS developers probably introduced `f95` as an alias for an open-source f95 compiler (meaning it supported free form syntax and other novelties introduced with the F90 and F95 language standards). If anyone is more familiar with Fortran compiler history please correct me.

Maybe @awvwgk can comment more on the compiler enumerations (@kubajj, you can use the [Blame](https://docs.github.com/en/github/managing-files-in-a-repository/managing-files-on-github/tracking-changes-in-a-file) button in the GitHub UI to find out who contributed each part of the code and ping them).

---

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [June 5, 2021, 9:01am UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/6 "2021-06-05T09:01:06Z")

</div>

I might have posted this already somewhere in a GitHub issue.

I took most of the identifiers either from meson’s reference tables ([Reference tables](https://mesonbuild.com/Reference-tables.html)) or CMake’s compiler identifiers ([CMAKE\_\<LANG\>\_COMPILER\_ID — CMake 3.20.3 Documentation](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html)). There is also an incredible detailed compendium of compiler macros for compiler, platform and architecture identification at [Pre-defined Compiler Macros / Wiki / Compilers](https://sourceforge.net/p/predef/wiki/Compilers/), which is comping in quite handy ever so often.

The reason to not use the Fortran compiler name is that it is potentially inaccurate, when dealing with _e.g._ the flang compiler which can either be the classic one, or the rebranded f18 frontend, or AMDs patched AOCC variant. The `f95` compiler on most systems is a symlink to `gfortran`, but there is also [Oracle’s Fortran compiler](https://docs.oracle.com/cd/E77782_01/html/E77786/gkofr.html#scrolltoc), which still goes under the name `f95`. An accurate compiler identification still requires us to parse the version output of the compilers or check the defined macros, which we are currently not doing but probably have to do at some point.

---

<div class="post-metadata">

**Author:** ![kubajj](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kubajj/32/400_2.png) [@kubajj](https://fortran-lang.discourse.group/u/kubajj)\
**Post date:** [June 11, 2021, 3:56pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/7 "2021-06-11T15:56:31Z")

</div>

_ **Progress status - #4** _  
This week I started by implementing basic error handling for compiler profiles and added two tests (one testing the various valid combinations and one for one invalid case). Then I added the `c_flags` and `link_time_flags` fields to the `profile_config_t` type and tried to make the logic handling the parsing of toml easier to understand.  
On Thursday, I have merged all the PRs from master to avoid merge conflicts further in the development.  
The rest of the week, I was researching the future implementation of the scope of profiles (global, package-wide, source-file-local) and after discussion with Brad and Laurence during yesterday’s meeting, I think that I have a well-formed idea about how to approach it. During the loop over dependencies in `build_model`, I store the profiles from the dependency manifest in the newly added profiles field in `package_t`. The logic handling the flags is moved to the end of `build_model` to account for future features with scope. Flags will be added as strings to the `src_file_t` in the `get_object_name` function, which will be slightly modified to account for the hash of flags being created in a different subroutine passed to the `join_path` instead of `model%output_directory`. Brad and Laurence both agreed that we should not store all the builds in one archive but rather more.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [June 14, 2021, 1:52am UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/8 "2021-06-14T01:52:11Z")

</div>

Thank you @kubajj for the updates! Good job.

---

<div class="post-metadata">

**Author:** ![gak](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/gak/32/146_2.png) [@gak](https://fortran-lang.discourse.group/u/gak)\
**Post date:** [June 14, 2021, 6:01pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/10 "2021-06-14T18:01:10Z")

</div>

I don’t know if this has been mentioned before, but the Flang developers put together a list of compiler options and how they compare across different compilers.

> <https://github.com/llvm/llvm-project/blob/main/flang/docs/OptionComparison.md>

This hasn’t been updated since November 2020, but it would be great if we can extend it, or use it as the seed for a more comprehensive list that is used in your project, @kubajj.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [June 14, 2021, 6:54pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/11 "2021-06-14T18:54:54Z")

</div>

@gak, very cool, thanks for posting the link. And welcome to the Fortran Discourse!

A document like that is something we should even maintain at [fortran-lang.org](http://fortran-lang.org) as a community. This is related to the discussion at: [Should fpm be compiler independent as much as possible with regards to flags? · Discussion #443 · fortran-lang/fpm · GitHub](https://github.com/fortran-lang/fpm/discussions/443) where we brainstormed (and mostly agreed) to make `fpm` eventually support the most commonly used options.

---

<div class="post-metadata">

**Author:** ![kubajj](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kubajj/32/400_2.png) [@kubajj](https://fortran-lang.discourse.group/u/kubajj)\
**Post date:** [June 18, 2021, 3:29pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/12 "2021-06-18T15:29:06Z")

</div>

_ **Progress status - #5** _  
This week, I have worked on the package and file scope of flags and moved the hashing of flags from `fpm_command_line`'s `check_build_vals` to `fpm_targets` to a new function that operates on a per-file basis.  
After yesterday’s discussion with Brad, I have created a draft of a [PR](https://github.com/fortran-lang/fpm/pull/498). Please have a look at my progress if you’ve got a minute and let me know what I should improve/add/change/…  
I have tried to comment on the important parts concerning syntax of the toml both in `manifest_reference.md` and `src/fpm/manifest/profiles.f90`. Please let me know if my explanation makes sense.

For the next steps, I am hoping to implement changes suggested from my PR and then look into the list of compiler options suggested by @gak. The plan is to try to find options that are similar to fast math and try to decide what to do with them. Initial ideas were to create a field for forbidden flags that would make listed flags forbidden from inclusion in the whole project and the packages using this package as a dependency. Is this something that would fit the needs of @certik?

If you have additional/better ideas of what to work on, please let me know as it helps me focus on the development itself rather than coming up with what should be done next.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [June 18, 2021, 4:21pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/13 "2021-06-18T16:21:21Z")

</div>

Thanks for the update. Great work. The PR is getting big, thus harder to review. It’s a good idea to keep sending smaller PRs, get them reviewed and merged on a quicker basis. Just something to keep in mind for your future patches.

I would have to see the details of the “forbidden flags”. When is your meeting next week? I’ll try to attend and we can discuss it.

---

<div class="post-metadata">

**Author:** ![kubajj](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kubajj/32/400_2.png) [@kubajj](https://fortran-lang.discourse.group/u/kubajj)\
**Post date:** [June 18, 2021, 9:23pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/14 "2021-06-18T21:23:14Z")

</div>

> [@certik](#):
>
> I would have to see the details of the “forbidden flags”. When is your meeting next week? I’ll try to attend and we can discuss it.

It is probably on Thursday at 2 pm UTC if @lkedward is free this time as Brad is not.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [June 18, 2021, 10:07pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/15 "2021-06-18T22:07:40Z")

</div>

> [@kubajj](#):
>
> It is probably on Thursday at 2 pm UTC if @lkedward is free this time as Brad is not.

That’s 7am my time, which is too early. If you can postpone by 2h, then I can attend.

---

<div class="post-metadata">

**Author:** ![lkedward](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/lkedward/32/72_2.png) [@lkedward](https://fortran-lang.discourse.group/u/lkedward)\
**Post date:** [June 19, 2021, 9:06am UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/16 "2021-06-19T09:06:59Z")

</div>

No problem, 4pm UTC works for me. How is that for you @kubajj and @everythingfunctional?

---

<div class="post-metadata">

**Author:** ![kubajj](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kubajj/32/400_2.png) [@kubajj](https://fortran-lang.discourse.group/u/kubajj)\
**Post date:** [June 19, 2021, 9:48am UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/17 "2021-06-19T09:48:54Z")

</div>

I am free at that time.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [June 19, 2021, 5:37pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/18 "2021-06-19T17:37:38Z")

</div>

Ok, let’s do it. @kubajj would you mind sending a calendar invite please?

---

<div class="post-metadata">

**Author:** ![kubajj](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kubajj/32/400_2.png) [@kubajj](https://fortran-lang.discourse.group/u/kubajj)\
**Post date:** [June 19, 2021, 6:28pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/19 "2021-06-19T18:28:18Z")

</div>

I think I did, let me know if it worked.

Can we use the usual link @lkedward?

---

<div class="post-metadata">

**Author:** ![lkedward](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/lkedward/32/72_2.png) [@lkedward](https://fortran-lang.discourse.group/u/lkedward)\
**Post date:** [June 20, 2021, 8:26am UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/20 "2021-06-20T08:26:58Z")

</div>

Yes @kubajj and @certik we can use the same Zoom link, see here: [GSoC project meeting - fpm compiler flags - #10 by lkedward](https://fortran-lang.discourse.group/t/gsoc-project-meeting-fpm-compiler-flags/1265/10)

I’ve changed the time for this occurence to **16:00 UTC 24th June 2021**.

A reminder that this meeting is open to everyone who is interested in the project.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [June 20, 2021, 3:22pm UTC](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297/21 "2021-06-20T15:22:18Z")

</div>

Thank you. I got the invite! I’ll be there.

[Next page](https://fortran-lang.discourse.group/t/handling-compiler-arguments-in-fpm-project-blog-by-jakub-jelinek/1297.md?page=2)
