MPI with C bindings and the MPI_FOUND variable
In the current dune-common cmake configuration there is a macro DuneMPI
to find the package MPI and to provide a function to set flags.
There is a comment in the header: "The DUNE way to compile MPI applications is to use the CXX compiler with MPI flags usually used for C. CXX bindings are deactivated to prevent ABI problems.". Is this necessary any more? What is the actual problem with just linking against the MPI cxx target?
Why not just writing:
find_package(MPI)
if (TARGET MPI::MPI_CXX)
target_link_libraries(dune-common PUBLIC MPI::MPI_CXX)
endif ()
Maybe there was a change in the meaning of MPI_CXX
in cmake. The CXX version of MPI does not mean the MPI C++ API (removed in MPI-3), but refers to the MPI C API being usable from C++. So, why do we use MPI_C
currently in dune-common, then?
This is discussed in https://gitlab.dune-project.org/simon.praetorius/dune-cmake/issues/1 and a related question regarding the cmake and compile flags for MPI is discussed in !804 (merged)
Proposal
- Switch to the
MPI::MPI_CXX
target - use
MPI_FOUND
as a test that MPI is correctly found and working for all enabled languages in cmake (note, if we just enable CXX, only the MPI_CXX target will be search for) or for all searched components - Maybe explicitly search only for the CXX component to improve configuration time.