From 8cd9cd774411b14ed845938d314aa54a3bfb0924 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Wed, 19 Sep 2018 17:15:48 +0200
Subject: [PATCH] Add simple CMake instructions for MPI configuration and
 compilation

---
 CMakeLists.txt | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c93aa25f4..1cbf56fa7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -73,6 +73,26 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
   set(PASTIS_CXX_FLAGS "${PASTIS_CXX_FLAGS} -Wsign-compare -Wunused -Wunused-member-function -Wunused-private-field")
 endif()
 
+#------------------------------------------------------
+# defaults use of MPI
+set(PASTIS_ENABLE_MPI AUTO CACHE STRING
+  "Choose one of: AUTO ON OFF")
+
+if (NOT PASTIS_ENABLE_MPI MATCHES "^(AUTO|ON|OFF)$")
+  message(FATAL_ERROR "PASTIS_ENABLE_MPI='${PASTIS_ENABLE_MPI}'. Must be set to one of AUTO, ON or OFF")
+endif()
+
+# checks for MPI
+if (PASTIS_ENABLE_MPI MATCHES "^(AUTO|ON)$")
+  find_package(MPI)
+endif()
+
+if (${MPI_FOUND})
+  set(PASTIS_CXX_FLAGS "${PASTIS_CXX_FLAGS} ${MPI_CXX_COMPILER_FLAGS}")
+  include_directories(${MPI_CXX_INCLUDE_DIRS})
+elseif(PASTIS_ENABLE_MPI STREQUAL "ON")
+  message(FATAL_ERROR "Could not find MPI library while requested")
+endif()
 
 #------------------------------------------------------
 
@@ -88,13 +108,13 @@ set(KOKKOS_ENABLE_EXPLICIT_INSTANTIATION OFF CACHE BOOL "")
 # do not use Kokkos deprecated code
 set(KOKKOS_ENABLE_DEPRECATED_CODE OFF CACHE BOOL "")
 
-# Kokkso compiler flags
+# Kokkos compiler flags
 add_subdirectory(${PASTIS_SOURCE_DIR}/packages/kokkos)
 include_directories(${Kokkos_INCLUDE_DIRS_RET})
 include(GetKokkosCompilerFlags)
 
 # sets Kokkos debug flags when non release build
-if (CMAKE_BUILD_TYPE MATCHES "Release")
+if (CMAKE_BUILD_TYPE MATCHES "^Release$")
   set (KOKKOS_ENABLE_DEBUG OFF)
 else()
   set (KOKKOS_ENABLE_DEBUG ON)
@@ -212,5 +232,6 @@ add_executable(
 target_link_libraries(
   pastis
   kokkos
+  ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES}
   PastisUtils
   PastisMesh)
-- 
GitLab