Tell gmxapi to look for MPI, when appropriate.
authorM. Eric Irrgang <ericirrgang@gmail.com>
Mon, 26 Oct 2020 14:07:21 +0000 (15:07 +0100)
committerAndrey Alekseenko <al42and@gmail.com>
Mon, 26 Oct 2020 15:39:17 +0000 (15:39 +0000)
The recommended CMake configuration for MPI-enabled GROMACS does not
provide MPI compiler wrappers for regular compiler variables. However,
the MPI toolchain details do not get conveyed transitively through the
libgromacs target. This should be easily resolved by checking whether
libgromacs is built with MPI library support and, if so, using the
CMake FindMPI module.

This may not be robust and should be revisited in the context of issue
#3672.

Meanwhile, this change should reduce errors for users following the
documentation updated under #3671.

api/gmxapi/CMakeLists.txt

index 81823a89c1c6ebd13e345af0ee8b0b17d581777c..e287816034cea6a983d500728abc24e3bca1c917 100644 (file)
@@ -66,6 +66,13 @@ if (GMX_LIB_MPI)
     # GROMACS is built against an MPI library.
     # Clarification should be possible with resolution of #3672.
     set(_gmx_mpi_type "library")
+    # Ref https://cmake.org/cmake/help/v3.13/module/FindMPI.html#variables-for-using-mpi
+    find_package(MPI COMPONENTS CXX)
+    if (MPI_CXX_FOUND)
+        target_link_libraries(gmxapi PUBLIC MPI::MPI_CXX)
+    else()
+        message(FATAL_ERROR "Building gmxapi for MPI-enabled GROMACS, but no MPI toolchain found.")
+    endif ()
 elseif(GMX_THREAD_MPI)
     # GROMACS is built with its internal thread-MPI implementation.
     set(_gmx_mpi_type "tmpi")