MPI

To add MPI, like OpenMP, you’ll be best off with CMake 3.9+.

  1. find_package(MPI REQUIRED)
  2. message(STATUS "Run: ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS")
  3. target_link_libraries(MyTarget PUBLIC MPI::MPI_CXX)

However, you can imitate this on CMake 3.1+ with:

  1. find_package(MPI REQUIRED)
  2. # For supporting CMake < 3.9:
  3. if(NOT TARGET MPI::MPI_CXX)
  4. add_library(MPI::MPI_CXX IMPORTED INTERFACE)
  5. set_property(TARGET MPI::MPI_CXX
  6. PROPERTY INTERFACE_COMPILE_OPTIONS ${MPI_CXX_COMPILE_FLAGS})
  7. set_property(TARGET MPI::MPI_CXX
  8. PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${MPI_CXX_INCLUDE_PATH}")
  9. set_property(TARGET MPI::MPI_CXX
  10. PROPERTY INTERFACE_LINK_LIBRARIES ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES})
  11. endif()
  12. message(STATUS "Run: ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS")
  13. target_link_libraries(MyTarget PUBLIC MPI::MPI_CXX)