From c92679d89f835868d7a6a6f4ea3ba524d0ae0c58 Mon Sep 17 00:00:00 2001
From: Dominic Kempf <dominic.r.kempf@gmail.com>
Date: Mon, 2 Feb 2015 19:51:59 +0100
Subject: [PATCH] [Cmake][Bugfix] Fix FindMETIS by adding -lm to the link flags

It needs to be linked in some cases. The way of checking whether
it is needed is taken from Find{BLAS,LAPACK}.cmake . This fix was
needed as part of a larger fix for the test of parallel alugrid.
---
 cmake/modules/FindMETIS.cmake | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/cmake/modules/FindMETIS.cmake b/cmake/modules/FindMETIS.cmake
index 471e3e9f6..fd8029674 100644
--- a/cmake/modules/FindMETIS.cmake
+++ b/cmake/modules/FindMETIS.cmake
@@ -47,10 +47,14 @@ find_library(METIS_LIBRARY ${METIS_LIB_NAME}
   PATH_SUFFIXES lib
 )
 
+# we need to check whether we need to link m, copy the lazy solution from FindBLAS and FindLAPACK here.
+if(NOT WIN32)
+  list(APPEND METIS_LIBRARY "-lm")
+endif()
+
 # check metis library
 if(METIS_LIBRARY)
   list(APPEND CMAKE_REQUIRED_LIBRARIES ${METIS_LIBRARY})
-  set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${METIS_LIBRARY})
   include(CheckFunctionExists)
   check_function_exists(METIS_PartGraphKway HAVE_METIS_PARTGRAPHKWAY)
 endif(METIS_LIBRARY)
-- 
GitLab