From 2b0152252ac761b4bcc163729fe2d629a19e72e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20Gr=C3=BCninger?= <gruenich@dune-project.org>
Date: Wed, 14 Mar 2012 20:26:37 +0000
Subject: [PATCH] [CMake] Exclude linking to MPI_CXX_LIBRARIES if MPI not
 found.

[[Imported from SVN: r6590]]
---
 dune/common/parallel/test/CMakeLists.txt | 14 ++++++++++----
 dune/common/test/CMakeLists.txt          | 16 ++++++++++++----
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/dune/common/parallel/test/CMakeLists.txt b/dune/common/parallel/test/CMakeLists.txt
index 7dfcf36ea..cabeea99f 100644
--- a/dune/common/parallel/test/CMakeLists.txt
+++ b/dune/common/parallel/test/CMakeLists.txt
@@ -3,11 +3,17 @@ target_link_libraries("indexsettest" "dunecommon")
 
 add_executable("indicestest" indicestest.cc)
 target_link_libraries("indicestest" "dunecommon")
-target_link_libraries(indicestest ${MPI_CXX_LIBRARIES})
+if(MPI_FOUND)
+  target_link_libraries(indicestest ${MPI_CXX_LIBRARIES})
+endif(MPI_FOUND)
 
 add_executable("selectiontest" selectiontest.cc)
 target_link_libraries("selectiontest" "dunecommon")
-target_link_libraries(selectiontest ${MPI_CXX_LIBRARIES})
+if(MPI_FOUND)
+  target_link_libraries(selectiontest ${MPI_CXX_LIBRARIES})
+endif(MPI_FOUND)
 
-#add_executable("syncertest" syncertest.cc)
-#target_link_libraries(syncertest ${MPI_CXX_LIBRARIES})
+add_executable("syncertest" syncertest.cc)
+if(MPI_FOUND)
+  target_link_libraries(syncertest ${MPI_CXX_LIBRARIES})
+endif(MPI_FOUND)
diff --git a/dune/common/test/CMakeLists.txt b/dune/common/test/CMakeLists.txt
index 4f7c4306c..fd4bb8033 100644
--- a/dune/common/test/CMakeLists.txt
+++ b/dune/common/test/CMakeLists.txt
@@ -33,16 +33,24 @@ add_executable("iteratorfacadetest" iteratorfacadetest.cc)
 add_executable("lrutest" lrutest.cc)
 add_executable("mpiguardtest" mpiguardtest.cc)
 target_link_libraries("mpiguardtest" "dunecommon")
-target_link_libraries(mpiguardtest ${MPI_CXX_LIBRARIES})
+if(MPI_FOUND)
+  target_link_libraries(mpiguardtest ${MPI_CXX_LIBRARIES})
+endif(MPI_FOUND)
 add_executable("mpicollectivecommunication" mpicollectivecommunication.cc)
 target_link_libraries(mpicollectivecommunication "dunecommon")
-target_link_libraries(mpicollectivecommunication ${MPI_CXX_LIBRARIES})
+if(MPI_FOUND)
+  target_link_libraries(mpicollectivecommunication ${MPI_CXX_LIBRARIES})
+endif(MPI_FOUND)
 add_executable("mpihelpertest" mpihelpertest.cc)
 target_link_libraries(mpihelpertest "dunecommon")
-target_link_libraries(mpihelpertest ${MPI_CXX_LIBRARIES})
+if(MPI_FOUND)
+  target_link_libraries(mpihelpertest ${MPI_CXX_LIBRARIES})
+endif(MPI_FOUND)
 add_executable("mpihelpertest2" mpihelpertest.cc)
 target_link_libraries(mpihelpertest2 "dunecommon")
-target_link_libraries(mpihelpertest2 ${MPI_CXX_LIBRARIES})
+if(MPI_FOUND)
+  target_link_libraries(mpihelpertest2 ${MPI_CXX_LIBRARIES})
+endif(MPI_FOUND)
 set_target_properties(mpihelpertest2 PROPERTIES COMPILE_FLAGS "-DMPIHELPER_PREINITIALIZE")
 add_executable("nullptr_test" nullptr-test.cc nullptr-test2.cc)
 target_link_libraries(nullptr_test "dunecommon")
-- 
GitLab