Skip to content

A Possible Solution for Compiler Flags #350

@everythingfunctional

Description

@everythingfunctional

I have a proposed solution to the issue of how we deal with compiler flags.

I propose adding a section to the fpm.toml file where compiler flags can be specified, with the following schema.

  1. The top level table is named "compiler-flags" (I'm open to suggestions for a better name)
  2. There is a table for each compiler. If a table is not specified for a compiler, then only the default/built-in profiles are available
  3. There may be multiple tables for each compiler, whose name specifies the name of an available "profile"
  4. A profile table specifies a list of flags, as an array of strings
  5. A profile table may optionally specify a list of pairs of file and flags to be used for that file
  6. A profile only applies to a dependency if it does not explicitly override that profile
  7. Specifying a profile with the same name as one of the default profiles overrides the default flags for that profile, including for dependencies, unless they also explicitly override that profile

For example:

[compiler-flags]
[compiler-flags.gfortran]
[compiler-flags.gfortran.only_debug_symbols]
flags = ["-g"]
files = { "src/special.f90" = ["-Wall", "-Werror"] }

One can then use a specified profile like fpm build --profile only_debug_symbols. The default/built-in profiles would correspond to our existing modes, and the existing modes would be equivalent to specifying the profile explicitly. I.e. fpm build is equivalent to/implies fpm build --profile debug and fpm build --release is equivalent to/implies fpm build --profile release.

This has the following benefits:

  • A library can override the default flags if they are not appropriate, and have its users respect that
  • A project can specify some special profile in a convenient place for frequently used sets of flags
  • A project/library need not override compiler flags for every file if only one file needs something special
  • We don't need to come up with and support a coherent set of "features" supported by every compiler

I admit that the table structure seems somewhat deeply nested, so I'm open to suggestions of other schemas, but I think this covers everything that needs to be included.

P.S. If this works out I'd like to suggest an additional built-in profile - strict - that includes all possible compile and run time checking, with all warnings treated as errors. I think this is a very useful option to have, even if not utilized very often.

Metadata

Metadata

Assignees

No one assigned

    Labels

    specificationIssue regarding fpm manifest and model

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions