fortran-lang / fpm

Fortran Package Manager (fpm)
https://fpm.fortran-lang.org
MIT License
876 stars 99 forks source link

DRAFT: Build with MPI wrappers only when --compiler is mpifort, mpif90, or mpif77 #1042

Open rouson opened 4 months ago

rouson commented 4 months ago

When complete, this Pull Request (PR) will address #929 by making it possible for a project to build alternatively with or without the Message Passing Interface ([MPI]) wrappers.

To Do

Change fpm' behavior so that when the manifest [dependencies] block contains mpi = "*", fpm builds with the MPI wrappers and links to the MPI bindings only when the --compiler argument is mpifort, mpif90, or mpif77.

The first commit in this PR accomplishes the first checked item above. To see this capability in action, one can start a new fpm project via fpm new optional-mpi and then adding the following lines to the manifest optional-mpi/fpm.toml:

[dependencies]
mpi = "*"

At the time of creating this daft PR, when the use of MPI is removed by a C-preprocessor macro such as in

#ifndef NO_MPI
use mpi_f08
#endif

building with the mpi = '*" terminates with an error

<ERROR> *cmd_run* Targets error: Unable to find source for module dependency: "mpi_f08" used by "././src/optional.F90"
STOP 1

because fpm parses files for internal dependencies before running the preprocessor.