Use GmxManageMPI variables for gmxapi.
authorM. Eric Irrgang <ericirrgang@gmail.com>
Mon, 8 Feb 2021 15:55:14 +0000 (18:55 +0300)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 11 Feb 2021 10:57:18 +0000 (10:57 +0000)
For minimal disruption to the release-2021 infrastructure,
let the `gmxapi` CMake target (libgmxapi) use
`${MPI_COMPILE_FLAGS}` and `${MPI_C_LIBRARIES}`
instead of the `MPI::MPI_*` target(s).

Note: This will conflict with the resolution to #3672.
Conflicts arising in a merge from `release-2021` to `master`
should defer to `master`.

Fixes #3896

api/gmxapi/CMakeLists.txt

index 12b2fd4226304f7e2f841b7294aa3edb544dc618..7a5710a7a80ea508c9c6843e86fcc4ebe849d9d5 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+# Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -64,15 +64,12 @@ set_target_properties(gmxapi PROPERTIES
 
 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 C)
-    if (MPI_C_FOUND)
-        target_link_libraries(gmxapi PRIVATE MPI::MPI_C)
-    else()
-        message(FATAL_ERROR "Building gmxapi for MPI-enabled GROMACS, but no MPI toolchain found.")
-    endif ()
+    # TODO: Normative solution with #3672.
+    # Do not target_link_options(gmxapi PRIVATE ${MPI_LINKER_FLAGS})
+    # because the root CMakeLists.txt sets CMAKE_SHARED_LINKER_FLAGS.
+    target_compile_options(gmxapi PUBLIC ${MPI_COMPILE_FLAGS})
+    target_link_libraries(gmxapi PUBLIC ${MPI_C_LIBRARIES})
 elseif(GMX_THREAD_MPI)
     # GROMACS is built with its internal thread-MPI implementation.
     set(_gmx_mpi_type "tmpi")