fpm icon indicating copy to clipboard operation
fpm copied to clipboard

Allow optional features in projects

Open awvwgk opened this issue 3 years ago • 4 comments

Motivation

Not all parts of a project are always needed. Many Fortran projects can be build with and without MPI support for example. Currently there is no mechanism to express such features in the package manifest. An option is to rely on preprocessor and set reasonable default using constructs like shown below:

#ifndef WITH_FEATURE
#define WITH_FEATURE 0
#endif

Since preprocessor might be the easiest way to express project local optional features, we could include such mechanism in fpm.

Specification

A project could declare a features table and export this to the project via a preprocessor variable:

[features]
qp.preprocessor = "WITH_QP"

When used as a dependency the feature could be toggled using

[dependencies]
test-drive = {git="https://github.com/fortran-lang/test-drive", features=["qp"]}

Prior Art

Cargo has features: https://doc.rust-lang.org/cargo/reference/features.html

Additional Information

A use case would be https://github.com/fortran-lang/test-drive/issues/7 The mechanism required in fpm is similar to the one described in https://github.com/fortran-lang/fpm/issues/577#issuecomment-926196637

awvwgk avatar Nov 14 '21 11:11 awvwgk

Features would be a great to have in fpm! In my opinion there's two crucial features in Cargo's feature functionality that would be great to see in fpm too:

Optional dependencies: When a dependency is marked as optional in Cargo this creates an implicit feature with the same name. In an ecosystem with lot's of packages available eliminating the need to build unused dependencies are just as important as conditionally building parts of the project source code itself.

Feature dependencies: For a project with many optional features it might be necessary to specify that one feature requires other features to be enabled.

plevold avatar Nov 19 '21 08:11 plevold