Skip to content

6. Packages built with fpm and CMake ​

Not every library of the lab is a FoBiS project. strings is built with fpm (an fpm.toml, no fobos), cmath with CMake. Both can be listed, found and added like the others, and solver uses all of them: each package is built by its own build system, with the compiler of solver.

List them ​

fobis publish --index, run in a package's working copy, adds its entry to an index:

console
$ cd ~/src/strings && fobis publish --index ~/lab-index/index.toml --source file://$HOME/remotes/strings.git
Added strings in ~/lab-index/index.toml (1 module(s))
console
$ cd ~/src/cmath && fobis publish --index ~/lab-index/index.toml --source file://$HOME/remotes/cmath.git
Added cmath in ~/lab-index/index.toml (1 module(s))

FoBiS reads no manifest of a CMake project, so the lab gives cmath a recipe, kept next to the index:

toml
# Build cmath with CMake: the release configuration, its module files collected by FoBiS
schema     = 1
backend    = "cmake"
cmake-args = ["-DCMAKE_BUILD_TYPE=Release"]
console
$ sed -n -e "/^\[package.cmath\]/,/^\$/p" -e "/^\[package.strings\]/,/^\$/p" ~/lab-index/index.toml
[package.cmath]
source = "file://~/remotes/cmath.git"
recipe = "recipes/cmath.toml"
description = "A clamp for Fortran, built with CMake."
provides = ["cmath"]
builds = ["cmake"]

[package.strings]
source = "file://~/remotes/strings.git"
description = "Case conversion of strings"
license = "MIT"
provides = ["strings"]
builds = ["fpm"]

builds tells what each one needs: fobis search --build fpm lists the packages an fpm project can use (the next chapter).

Use them ​

add copies the index's recipe into the project, so that building never depends on the index:

console
$ fobis add strings && fobis add cmath
Added strings = file://~/remotes/strings.git :: semver=^1.0.0
Run 'fobis fetch' to fetch it.
Added cmath = file://~/remotes/cmath.git :: semver=^1.0.0 :: recipe=recipes/cmath.toml
Run 'fobis fetch' to fetch it.
ini
[dependencies]
# added by fobis add from index lab
kinds = file://~/remotes/kinds.git :: semver=^1.1.1 :: mirror=file://~/mirror/kinds.git
# added by fobis add from index lab
vectors = file://~/remotes/vectors.git :: semver=^0.2.0
transitive = true
# added by fobis add from index lab
strings = file://~/remotes/strings.git :: semver=^1.0.0
# added by fobis add from index lab
cmath = file://~/remotes/cmath.git :: semver=^1.0.0 :: recipe=recipes/cmath.toml

fetch builds strings with fpm and cmath with CMake, each with the compiler of solver's default mode, and installs them into .fobis_deps/.prefix:

console
$ fobis fetch
Dependency kinds already fetched (use --update to refresh)
Checking out v1.1.1 for kinds
Dependency vectors already fetched (use --update to refresh)
Checking out v0.2.0 for vectors
Cloning strings from file://~/remotes/strings.git
Checking out v1.0.0 for strings
Cloning cmath from file://~/remotes/cmath.git
Checking out v1.0.0 for cmath
Dependency kinds already fetched (use --update to refresh)
Checking out v1.1.1 for kinds
Dependency vectors already fetched (use --update to refresh)
Checking out v0.2.0 for vectors
Building strings with fpm and gfortran into .fobis_deps/.prefix/strings
Building cmath with cmake and gfortran into .fobis_deps/.prefix/cmath
Saved deps config to .fobis_deps/.deps_config.ini
Saved lock file to .fobis_deps/fobos.lock
console
$ find .fobis_deps/.prefix -type f | sort
.fobis_deps/.prefix/cmath/include/cmath.mod
.fobis_deps/.prefix/cmath/lib/libcmath.a
.fobis_deps/.prefix/cmath/lib/pkgconfig/cmath.pc
.fobis_deps/.prefix/strings/include/strings.mod
.fobis_deps/.prefix/strings/lib/libstrings.a
.fobis_deps/.prefix/strings/lib/pkgconfig/strings.pc

build compiles solver and its FoBiS packages, and links the libraries fpm and CMake made:

fortran
program solver
!< The length of a vector, clamped, and its unit in upper case: packages built by FoBiS, fpm and CMake.
use kinds,   only : R8P
use vectors, only : norm
use strings, only : upper
use cmath,   only : clamp
implicit none
print '(F6.3,1X,A)', clamp(norm([3._R8P, 4._R8P]), 0._R8P, 4._R8P), upper('metres')
end program solver
console
$ fobis build --quiet && ./build/solver

Building src/solver.f90
Compiling .fobis_deps/kinds/src/kinds.f90 serially
Compiling .fobis_deps/vectors/src/vectors.f90 serially
Compiling src/solver.f90 serially
Linking build/solver
Target src/solver.f90 has been successfully built
 4.000 METRES
  • fpm is required for a package that has an fpm.toml and no fobos: FoBiS never compiles an fpm package itself. fpm fetches the package's own fpm dependencies.
  • CMake installs no module file by default: FoBiS collects the ones the build made.
  • Only the compiler reaches them, not the mode's other flags: a flag that changes the binary interface (-fdefault-real-8) does not reach a package built by fpm or CMake.

This chapter needs fpm and CMake; its outputs are recorded where both are installed.

What you learned

fobis publish --index, recipes in an index, packages built by fpm and CMake in a FoBiS project, the .fobis_deps/.prefix they are installed into. Reference: how a dependency is built, CMake, make and other packages.

Next: an fpm project.