I’m trying some conditional compilation with fpm. I tried this approach but it doesn’t seem to work:
I have the following tree:
.
├── app
│ └── main.f90
├── fpm.toml
├── README.md
└── src
├── iimas.f90
├── local.f90
└── submod.f90
Where the fpm.toml is:
name = "submod"
[features]
imas.preprocess.cpp.macros = "IMAS"
local.preprocess.cpp.macros = "LOCAL"
[profiles]
default = ["local"]
And these Fortran files:
module submod
implicit none
public
interface
module subroutine say_hello
end subroutine
end interface
end module submod
#ifdef IMAS
submodule (submod) iimas
implicit none
contains
subroutine say_hello
print *, "Hello, IMAS!"
end subroutine say_hello
end submodule
#endif
#ifdef LOCAL
submodule (submod) local
implicit none
contains
subroutine say_hello
print *, "Hello, LOCAL!"
end subroutine say_hello
end submodule
#endif
Now, if I do the following it looks as everything is working as expected:
> fpm run --profile imas
+ mkdir -p build/dependencies
submod.f90 done.
iimas.f90 done.
main.f90 done.
libsubmod.a done.
submod done.
[100%] Project compiled successfully.
Hello, IMAS!
> fpm clean
Delete build, excluding dependencies (y/n)? y
+ rm -rf build/gfortran_343106CD415EB0B2
+ rm -rf build/gfortran_DF0783F549429104
+ rm -rf build/gfortran_55E1FE181FD0F959
> fpm run --profile local
submod.f90 done.
local.f90 done.
main.f90 done.
libsubmod.a done.
submod done.
[100%] Project compiled successfully.
Hello, LOCAL!
But if I don’t clean it before running with a different profile I got the old result.
> fpm run --profile local
Project is up to date
Hello, LOCAL!
> fpm run --profile imas
submod.f90 done.
iimas.f90 done.
main.f90 done.
libsubmod.a done.
submod done.
[100%] Project compiled successfully.
Hello, LOCAL!
Just to be clear I’m using the latest release.
> fpm --version
Version: 0.13.0, alpha
Program: fpm(1)
Description: A Fortran package manager and build system
Home Page: https://github.com/fortran-lang/fpm
License: MIT
OS Type: Linux
Thanks in advance.