Skip to content

7. An fpm project ​

A colleague writes a report generator with fpm. The lab's index serves them too: fobis add, run in a project with an fpm.toml and no fobos, writes into fpm.toml, and fpm fetches and builds the package.

toml
# a colleague's report generator, built with fpm
name    = "report"
version = "0.1.0"

[build]
auto-tests = false
fortran
program report
!< A heading in upper case, with the lab's strings package.
use strings, only : upper
implicit none
print '(A)', upper('annual report')
end program report

What fpm can use ​

fpm builds only packages that have an fpm.toml. The index says which ones do:

console
$ fobis search --build fpm
lab:strings                  file://~/remotes/strings.git
    Case conversion of strings

Add, build, remove ​

console
$ cd ~/report && fobis add strings
Added strings = { git = "file://~/remotes/strings.git", tag = "v1.0.0" } in fpm.toml [dependencies]
fpm fetches it at the next fpm build.
console
$ cat ~/report/fpm.toml
# a colleague's report generator, built with fpm
name    = "report"
version = "0.1.0"

[build]
auto-tests = false

[dependencies]
# added by fobis add from index lab
strings = { git = "file://~/remotes/strings.git", tag = "v1.0.0" }
console
$ cd ~/report && fpm run 2>/dev/null
ANNUAL REPORT

A package without an fpm.toml at that version is refused, with the build systems it has:

console
$ cd ~/report && fobis add lab:kinds
Error: file://~/remotes/kinds.git has no fpm.toml at v2.0.0 (built with fobis): fpm cannot use it
[exit status 1]
console
$ cd ~/report && fobis add cmath
Error: file://~/remotes/cmath.git has no fpm.toml at v1.0.0 (built with cmake): fpm cannot use it
[exit status 1]
console
$ cd ~/report && fobis remove strings && cat fpm.toml
Removed strings = { git = "file://~/remotes/strings.git", tag = "v1.0.0" } from fpm.toml [dependencies]
# a colleague's report generator, built with fpm
name    = "report"
version = "0.1.0"

[build]
auto-tests = false

[dependencies]
  • The newest tag is pinned exactly: fpm takes a tag, a rev or a branch, not a range. fobis add NAME --force moves to a newer one, --tag chooses another, --dev writes into [dev-dependencies].
  • The name is the package's own: fpm requires the dependency's key to be the name of the package's fpm.toml, so add reads it there and refuses --as.
  • fpm does the rest: the package's own dependencies, its build and its lock are fpm's. transitive, fetch, fobos.lock, mirrors and audit are FoBiS's and do not apply.
  • A project with both a fobos and an fpm.toml gets its fobos edited; --fpm chooses fpm.toml.

This chapter needs fpm; its outputs are recorded where fpm is installed.

What you learned

fobis search --build fpm, fobis add and remove in an fpm project, why a package needs an fpm.toml for fpm. Reference: fpm projects.

This is the end of the packages track. The tutorials list the other tracks; the cookbook has a recipe for every package task.