Is anyone aware of a clear recommendation for installing Fortran module files?
I usually avoid this issue by not installing mod files at all and just reuse Fortran dependencies within meson or fpm. This works fine when all dependencies are available in the respective build system, but CMake or make based Fortran projects would have a hard time to interface with the library. Here, one strategy is to install the project and find it by some means in the dependent project (pkg-config), for Fortran this requires of course to install the module files as well.
The mod files shouldnβt be installed in the top level include directory because of ABI compatibility issues in Fortran and because not all Fortran compilers handle the system include directories in the same way (this is important because the project could be potentially installed in the system prefix).
A notable reference here might be Python, since it has similar issues with ABI compatibility, therefore compiled extension modules include a lot of information like the Python implementation (CPython, PyPy, β¦), the version of the Python ABI (37, 38, 39, β¦), the architecture (x86_64, aarch64, β¦) and the platform (Linux, β¦). For an extension module compiled against CPython 3.9 and Linux x86_64 the shared object is suffixed with cpython-39-x86_64-linux-gnu
.
Since Fortran has similar ABI issues this seems like a viable strategy for installing mod files as well.
Iβm currently experimenting with the directory layout in meson (dftd4/dftd4#95), using the package name as well as the compiler identifier and version as subdirectory in the include directory (include/dftd4/gcc-10.2.0
here):
$PREFIX
βββ bin
β βββ dftd4
βββ include
β βββ dftd4
β β βββ gcc-10.2.0
β β βββ dftd4.mod
β β βββ ...
β β βββ dftd4_version.mod
β βββ dftd4.h
βββ lib
β βββ libdftd4.a
β βββ libdftd4.so -> libdftd4.so.3
β βββ libdftd4.so.3 -> libdftd4.so.3.1.0
β βββ libdftd4.so.3.1.0
β βββ pkgconfig
β β βββ dftd4.pc
β βββ python3.9
β βββ site-packages
β βββ dftd4
β βββ ...
β βββ _libdftd4.cpython-39-x86_64-linux-gnu.so
βββ share
βββ ...
The module directory is communicated via pkg-config to downstream projects:
prefix=/some/path/to/install
libdir=${prefix}/lib
includedir=${prefix}/include
Name: dftd4
Description: Generally Applicable Atomic-Charge Dependent London Dispersion Correction
Version: 3.1.0
Requires.private: lapack, blas
Libs: -L${libdir} -ldftd4
Libs.private: -fopenmp -fopenmp
Cflags: -I${includedir} -I${includedir}/dftd4/gcc-10.2.0