diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 1778c7b7f2..e2f7d8c90c 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -276,6 +276,8 @@ else() option(BUILD_MPI "Build MPI version" OFF) endif() +# configure MPI related settings and define an MPI::ANY_CXX alias target +# which will point to either the imported MPI library or the STUBS lib if(BUILD_MPI) # do not include the (obsolete) MPI C++ bindings which makes # for leaner object files and avoids namespace conflicts @@ -290,6 +292,9 @@ if(BUILD_MPI) target_compile_definitions(lammps PRIVATE -DLAMMPS_LONGLONG_TO_LONG) endif() endif() + if(CMAKE_VERSION VERSION_GREATER 3.11) + set_property(TARGET MPI::MPI_CXX PROPERTY IMPORTED_GOBAL TRUE) + endif() add_library(MPI::ANY_CXX ALIAS MPI::MPI_CXX) else() target_sources(lammps PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp)