# Fpm conditional compilation

**URL:** <https://fortran-lang.discourse.group/t/fpm-conditional-compilation/10925>\
**Category:** Help\
**Created:** [May 23, 2026, 1:44pm UTC](https://fortran-lang.discourse.group/t/fpm-conditional-compilation/10925 "2026-05-23T13:44:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![egio](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@egio](https://fortran-lang.discourse.group/u/egio)\
**Post date:** [May 23, 2026, 1:44pm UTC](https://fortran-lang.discourse.group/t/fpm-conditional-compilation/10925/1 "2026-05-23T13:44:27Z")

</div>

I’m trying some conditional compilation with fpm. I tried this approach but it doesn’t seem to work:  
I have the following tree:

```auto
.
├── app
│ └── main.f90
├── fpm.toml
├── README.md
└── src
    ├── iimas.f90
    ├── local.f90
    └── submod.f90

```

Where the fpm.toml is:

```auto
name = "submod"

[features]
imas.preprocess.cpp.macros = "IMAS"
local.preprocess.cpp.macros = "LOCAL"

[profiles]
default = ["local"]

```

And these Fortran files:

```fortran
module submod 
  implicit none
  public

  interface
    module subroutine say_hello
    end subroutine
  end interface

end module submod

```

```fortran
#ifdef IMAS
submodule (submod) iimas
implicit none
contains

subroutine say_hello
    print *, "Hello, IMAS!"
end subroutine say_hello

end submodule
#endif

```

```fortran
#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:

```auto
> 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.

```auto
> 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.

```auto
> 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.

---

<div class="post-metadata">

**Author:** ![NormanKirkby](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/normankirkby/32/1091_2.png) [@NormanKirkby](https://fortran-lang.discourse.group/u/NormanKirkby)\
**Post date:** [May 23, 2026, 7:38pm UTC](https://fortran-lang.discourse.group/t/fpm-conditional-compilation/10925/2 "2026-05-23T19:38:19Z")

</div>

I am no expert, but was playing with something similar yesterday and discovered that I needed

preprocess

And then the preprocessor can be specified. without this all preprocessor macros are ignored, I think.

---

<div class="post-metadata">

**Author:** ![NormanKirkby](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/normankirkby/32/1091_2.png) [@NormanKirkby](https://fortran-lang.discourse.group/u/NormanKirkby)\
**Post date:** [May 23, 2026, 7:39pm UTC](https://fortran-lang.discourse.group/t/fpm-conditional-compilation/10925/3 "2026-05-23T19:39:45Z")

</div>

Ah, bitten by markdown, try again

In the fpm.toml, I needed the  
[preprocess]  
clause

---

<div class="post-metadata">

**Author:** ![NormanKirkby](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/normankirkby/32/1091_2.png) [@NormanKirkby](https://fortran-lang.discourse.group/u/NormanKirkby)\
**Post date:** [May 23, 2026, 7:40pm UTC](https://fortran-lang.discourse.group/t/fpm-conditional-compilation/10925/4 "2026-05-23T19:40:40Z")

</div>

Sorry, Android phone & finger trouble, how do I delete this?

---

<div class="post-metadata">

**Author:** ![FedericoPerini](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/federicoperini/32/1750_2.png) [@FedericoPerini](https://fortran-lang.discourse.group/u/FedericoPerini)\
**Post date:** [May 24, 2026, 2:21pm UTC](https://fortran-lang.discourse.group/t/fpm-conditional-compilation/10925/5 "2026-05-24T14:21:33Z")

</div>

Thanks for pointing this out - your analysis is correct.

Seems like the `ar` archiver (used in Unix/macOS and Windows - minGW) will not update the archive when linking the new/changed `.o` files, because it only looks at their base name (not the folder they come from). I am less certain about the Windows archiver (`lib.exe`).

`fpm clean` is the obvious solution (`0.13.0` allows selective per-target cleaning). I will propose to always delete any stale/old archive files before the archiver is called.

---

<div class="post-metadata">

**Author:** ![egio](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@egio](https://fortran-lang.discourse.group/u/egio)\
**Post date:** [May 24, 2026, 3:47pm UTC](https://fortran-lang.discourse.group/t/fpm-conditional-compilation/10925/6 "2026-05-24T15:47:04Z")

</div>

Thanks for developing fpm!
