I’m trying to set up an FPM build for something I’m been working on for a couple of months. I’m currently using Makefiles and they are mostly bullet proof. However there are a couple of things I’ve encountered with FPM that I have questions about.
1 - Is there a way to define an alternate directory to hold module files instead of include. If not why isn’t there. All Fortran compilers have an option to define a path where modules are both written to and read from (usually a -module /path/to/modules). I know I’m in the minority but I only like to put things in include that are actual include type files. Besides an include directory is just SO C/C++ Something I try desperately to avoid
2 - Is there a way to stop FPM from trying to run tests and just make the executables for the tests
Here is what my FPM manifest looks like. I’m compiling with gfortran-13
name = "myProject"
version = "0.1"
author = "me"
maintainer = "me"
copyright = "Copyright (c) 2024, me"
license = "BSD-3"
description = "Testing fpm build"
[library]
source-dir = "src"
[install]
library = true
[build]
auto-tests = true
[[test]]
name = "test1"
source-dir = "test"
main = "test1.F90"
[[test]]
name = "test2"
source-dir = "test"
main = test2.F90
[[test]]
name = "test3"
source-dir = "test"
main = "test3.F90"
[[test]]
name = "test4"
source-dir = "test"
main = "test4.F90"
[[test]]
name = "test5"
source-dir = "test"
main = "test5.F90"
[[test]]
name = "test6"
source-dir = "test"
main = "test6.F90"
you can specify multiple include directories via the manifest file fpm.toml
Projects which use the Fortran include statement or C preprocessor
#include statement, can use the include-dir key to specify search
directories for the included files. include-dir can contain one or more
directories, where multiple directories are specified using a list of
strings. Include directories from all project dependencies are passed
to the compiler using the appropriate compiler flag.
Example:
[library]
include-dir = ["include", "third_party/include"]
files are also searched for in the src directories and can also be specified using options on the fpm command or using FPM-specific environment variables but also via compiler-specific methods as well.
The command options are available via “fpm manual >manual.txt” , the manifest file is available
on-line. If you have commands like lynx, links, or w3m or any other terminal-based browsers an easy way to convert it to text is something like
or go to that URL to see the section on include directories.
So the fpm.toml file can be used to list any directories in the project you want to search for include files… For directories outside of the project (unless you want to create links to them) I generally use one of the other options or response files. The pathnames to other URLs of interest are in the output of the help commands or the text file generated via “fpm manual” as described above. If you have grep you
want to visit most of the sites listed by entering “fpm manual|grep -i http”. at some point or another and read the associated documents.
Thanks but I don’t think the include-dir is a solution to my problem. Mainly, I don’t want any .mod files wrtten to include. I want them written to a modules directory in the project root directory. That is unless
include-dir = [“./modules”, “include”]
will cause FPM to search modules first and write things there before include. I can force the compile to write to a module directory by adding a -module ./modules to FPM_FFLAGS. But I’m not sure how FPM will handle .mod files that are not in include.
Also, another question. On Linux why is FPM writing stuff to my home dir hidden .local file. I don’t want anything written there without at least some warning. Can that be turned off.
Of no use if you do not have Unix or GNU/Linux but if you do this is a bash shell script that will create a test fpm project and edit it to create an example project that uses multiple include directores
inc_test.sh
#!/bin/bash
(
set -v -x
exec 2>&1
fpm manual >manual.txt
: fpm manual is on manual.txt
command -v lynx && lynx -dump Manifest reference — Fortran Package Manager manifest.txt >manifest.txt
: if lynx is installed text version of manifest document is on manifest.txt
fpm new inc_test
: create test project
cd inc_test
: add lines to include from many directories to fpm.toml
: create include directories with minimal include files
: change application program to have INCLUDE directives
echo ‘[library]’ >>fpm.toml
printf ‘include-dir=[’ >>fpm.toml
for NAME in add amalgamate assemble blend combine couple embed enfold
fuse incorporate integrate interfuse join meld unite weld
do
mkdir -p $NAME
cat >$NAME/$NAME.inc <<EOF
write(,)‘hello from $NAME!’
EOF
sed -i -e ‘/say_hello()/iinclude "’$NAME’.inc"’ app/main.f90
printf ‘“%s”, ’ NAME >>fpm.toml
done
sed -i -e 's/, //’ fpm.toml
echo ‘]’ >>fpm.toml
: show file structure created if tree is installed
command -v tree && tree
: show changed fpm.toml manifest
cat fpm.toml
: show changed default project program
cat app/main.f90
: run it and show included files from many directories
fpm run
)|tee record-$(uuidgen).log
exit
I figured out two of my problems. FPM was putting stuff into .local when I didn’t specify a prefix on fpm install. Also, trying to force FPM to copy .mod files over to a modules subdirectory at compile time won’t work. IE adding -J./modules to FPM_FFLAGS causes gfortran to gripe about -J being defined more than once so I guess FPM is also setting this option. However, the next best thing is to use the --includedir options when installing. ie