From fc7ce71d7907db703150536bcd59f6d66c7290b0 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Mon, 24 Sep 2018 19:03:13 +0200
Subject: [PATCH] Add initial ParMETIS CMake configuration

Would probably require efforts for user defined location of libraries
---
 CMakeLists.txt | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 01b131228..efae19025 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -220,6 +220,34 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Coverage")
 
 endif()
 
+#------------------------------------------------------
+# Search for ParMETIS
+
+if(${MPI_FOUND})
+  find_path(PARMETIS_INCLUDE_DIR parmetis.h
+    PATH_SUFFIX include parmetis
+    NO_DEFAULT_PATH
+    DOC "Custom include directory for parmetis.h")
+  find_path(PARMETIS_INCLUDE_DIR parmetis.h
+    PATH_SUFFIX include parmetis)
+
+  if (EXISTS "${PARMETIS_INCLUDE_DIR}/parmetis.h")
+    message("-- Found parmetis.h in ${PARMETIS_INCLUDE_DIR}")
+    find_library(LIB_PARMETIS parmetis)
+    if("${LIB_PARMETIS}" STREQUAL "LIB_PARMETIS-NOTFOUND")
+      message(FATAL_ERROR "Could not find parmetis library")
+    endif()
+    find_library(LIB_METIS metis)
+    if("${LIB_PARMETIS}" STREQUAL "LIB_METIS-NOTFOUND")
+      message(FATAL_ERROR "Could not find metis library")
+    endif()
+    set(PARMETIS_LIBRARIES ${LIB_PARMETIS} ${LIB_METIS})
+    message("-- Found parmetis/metis libraries ${PARMETIS_LIBRARIES}")
+  else()
+    message(FATAL_ERROR "Could not find parmetis.h")
+  endif()
+endif()
+
 # -----------------------------------------------------
 
 link_libraries("-rdynamic")
@@ -234,6 +262,7 @@ add_executable(
 target_link_libraries(
   pastis
   kokkos
+  ${PARMETIS_LIBRARIES}
   ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES}
   PastisUtils
   PastisMesh)
-- 
GitLab