I want to use fpm with a complex program/library structure and I have an issue setting up a path in a fpm library (dependency) with a cpp.macros.
In some libraries, I need an internal directory to store some data to be read at the initialization. Furthermore, to make sure those data can be read, the absolute path of the library directory is stored in a module.
With a makefile, I’m using a shell command: $(shell pwd)
to get this path and c-preprocessing to set up the path in the fortran file at compile time.
This way, the data path is always correct, even if the library is linked to another program/library.
With fpm, it does not work as expected:
- If the library is just compiled (not linked to another program), it is easy:
I can set up the cpp.macros with the absolute path as:
cpp.macros = [" __PHYSCTEPATH=\"'
pwd'\""]
I’m using `pwd` to get the path.
By the possibility to use `linux command` in fpm is great!
- If the library is linked to another program, it does not work:
The structure of the program is the following:
Prog
|
|_____app
| |___main.f90
|
|_____fpm.toml
|
|____Ext_Lib
|_______ConstPhys
|__Internal_data ...
|__SRC ...
|__fpm.toml
|__other files/directories
and cpp.macros (cpp.macros = [“__PHYSCTEPATH="‘pwd
’"”]) is set in the fpm.toml of the ConstPhys directory.
If, I’m running from the Prog directory, the compilation is performed without problem.
However, the path (__PHYSCTEPATH
) is the one from Prog directory and not from ConstPhys directory. More precisely:
- I’ve got:
__PHYSCTEPATH=" …/Prog"
- I want:
__PHYSCTEPATH=" …/Prog/Ext_lib/ConstPhys"
Remarks:
-
I want to keep this structure so that the program is self-contained.
-
If I change the cpp.macros by adding
/Ext_lib/ConstPhys
after `pwd` (see below), then it works with this program structure but anymore for the library by itself.`cpp.macros = ["__PHYSCTEPATH=\"'`pwd`/Ext_lib/ConstPhys'/\""]`
So do you know a way to have the right path in both situations, either with fpm or by another mean?
The Prog/fpm.toml is:
Summary
name = "ConstPhys_test"
[[executable]]
name="Test_CP"
source-dir="app"
main="main.f90"
[dependencies]
QDUtilLib = { path = "Ext_lib/QDUtilLib" }
ConstPhys = { path = "Ext_lib/ConstPhys" }
openmp = "*"
The Prog/Ext_Lib/ConstPhys/fpm.toml is:
Summary
name = "ConstPhys"
[library]
source-dir="SRC"
[install]
library = true
[[test]]
name="TestCP"
source-dir="TESTS"
main="PhysicalConstants_Main.f90"
[build]
auto-executables = false
auto-examples = false
auto-tests = false
[fortran]
implicit-external = true
[preprocess]
cpp.macros = ["__PHYSCTEPATH=\"'`pwd`'\""]
#cpp.macros = ["__PHYSCTEPATH=\"'`pwd`/Ext_lib/ConstPhys'\""]
[dependencies]
QDUtilLib = { path = "Ext_lib/QDUtilLib" }