From f2f529b1294dc3dbd73cdaf1ac970513ec37043e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20Gr=C3=BCninger?= <gruenich@dune-project.org>
Date: Wed, 14 Mar 2012 18:27:25 +0000
Subject: [PATCH] [CMake] Added support for MPI. Write module version
 information to config.h.

[[Imported from SVN: r6588]]
---
 CMakeLists.txt                           | 20 +++++++++++++-------
 cmake/modules/DuneMacros.cmake           |  4 ++--
 config.h.cmake                           | 12 ++++++++++++
 dune/common/parallel/test/CMakeLists.txt |  5 ++++-
 dune/common/test/CMakeLists.txt          | 11 +++++++----
 5 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 22591a1ce..e7da9b605 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,10 +6,15 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
 
 include(DuneMacros)
 dune_module_information(${CMAKE_SOURCE_DIR})
+
 set(ProjectName            "${DUNE_MODULE_NAME}")
 set(ProjectVersion         "${DUNE_VERSION_STRING}")
 set(ProjectMaintainerEmail "${DUNE_MAINTAINER}")
 project(${ProjectName} C CXX)
+set(DUNE_COMMON_VERSION          "${DUNE_VERSION_STRING}")
+set(DUNE_COMMON_VERSION_MAJOR    "${DUNE_VERSION_MAJOR}")
+set(DUNE_COMMON_VERSION_MINOR    "${DUNE_VERSION_MINOR}")
+set(DUNE_COMMON_VERSION_REVISION "${DUNE_VERSION_REVISION}")
 
 # include dune-common to include pathtest
 include_directories("${CMAKE_SOURCE_DIR}")
@@ -29,12 +34,13 @@ check_include_file_cxx("memory" HAVE_MEMORY)
 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -DHAVE_MEMORY=${HAVE_MEMORY}")
 
 # search for packages
-#find_package(MPI)
-#set(HAVE_MPI MPI_CXX_FOUND)
-#include_directories(${MPI_CXX_INCLUDE_PATH})
-#set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_CXX_COMPILE_FLAGS})
-#set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_CXX_LINK_FLAGS})
-#include_directories(${MPI_CXX_INCLUDE_PATH})
+find_package(MPI)
+if(MPI_FOUND)
+set(HAVE_MPI MPI_CXX_FOUND)
+add_definitions("${MPI_CXX_COMPILE_FLAGS}")
+ #add_definitions("-DENABLE_MPI=1")
+include_directories(${MPI_CXX_INCLUDE_PATH})
+endif(MPI_FOUND)
 
 find_package(Boost)
 set(HAVE_BOOST BOOST_FOUND)
@@ -142,5 +148,5 @@ add_test(indexsettest			dune/common/parallel/test/indexsettest)
 add_test(selectiontest			dune/common/parallel/test/selectiontest)
 if(MPI_CXX_FOUND)
   add_test(indicestest			dune/common/parallel/test/indicestest)
-  add_test(syncertest			dune/common/parallel/test/syncertest)
+  #add_test(syncertest			dune/common/parallel/test/syncertest)
 endif(MPI_CXX_FOUND)
diff --git a/cmake/modules/DuneMacros.cmake b/cmake/modules/DuneMacros.cmake
index ad257a57e..b457a141e 100644
--- a/cmake/modules/DuneMacros.cmake
+++ b/cmake/modules/DuneMacros.cmake
@@ -11,11 +11,11 @@ macro(dune_module_information MODULE_DIR)
   # remove false matches in version string
   string(REGEX MATCH "[^0-9]" NON_NUMBER_CHARACTER "${DUNE_VERSION_MINOR}")
   if(NON_NUMBER_CHARACTER)
-    set(DUNE_COMMON_VERSION_MINOR "0")
+    set(DUNE_VERSION_MINOR "0")
   endif(NON_NUMBER_CHARACTER)
   string(REGEX MATCH "[^0-9]" NON_NUMBER_CHARACTER "${DUNE_VERSION_REVISION}")
   if(NON_NUMBER_CHARACTER)
-    set(DUNE_COMMON_VERSION_REVISION "0")
+    set(DUNE_VERSION_REVISION "0")
   endif(NON_NUMBER_CHARACTER)
 
   # find strings for module name, maintainer
diff --git a/config.h.cmake b/config.h.cmake
index 9bc9c8313..ef3e448ad 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -1,5 +1,17 @@
 #define DUNE_COMMON_FIELDVECTOR_SIZE_IS_METHOD 1
 
+/* Define to the version of dune-common */
+#define DUNE_COMMON_VERSION ${DUNE_COMMON_VERSION}
+
+/* Define to the major version of dune-common */
+#define DUNE_COMMON_VERSION_MAJOR ${DUNE_COMMON_VERSION_MAJOR}
+
+/* Define to the minor version of dune-common */
+#define DUNE_COMMON_VERSION_MINOR ${DUNE_COMMON_VERSION_MINOR}
+
+/* Define to the revision of dune-common */
+#define DUNE_COMMON_VERSION_REVISION ${DUNE_COMMON_VERSION_REVISION}
+
 #cmakedefine01 HAVE_MPI
 #cmakedefine01 HAVE_MALLOC_H
 #cmakedefine01 HAVE_BOOST
diff --git a/dune/common/parallel/test/CMakeLists.txt b/dune/common/parallel/test/CMakeLists.txt
index e5d4914cd..7dfcf36ea 100644
--- a/dune/common/parallel/test/CMakeLists.txt
+++ b/dune/common/parallel/test/CMakeLists.txt
@@ -3,8 +3,11 @@ target_link_libraries("indexsettest" "dunecommon")
 
 add_executable("indicestest" indicestest.cc)
 target_link_libraries("indicestest" "dunecommon")
+target_link_libraries(indicestest ${MPI_CXX_LIBRARIES})
 
 add_executable("selectiontest" selectiontest.cc)
 target_link_libraries("selectiontest" "dunecommon")
+target_link_libraries(selectiontest ${MPI_CXX_LIBRARIES})
 
-add_executable("syncertest" syncertest.cc)
+#add_executable("syncertest" syncertest.cc)
+#target_link_libraries(syncertest ${MPI_CXX_LIBRARIES})
diff --git a/dune/common/test/CMakeLists.txt b/dune/common/test/CMakeLists.txt
index baa6be480..4f7c4306c 100644
--- a/dune/common/test/CMakeLists.txt
+++ b/dune/common/test/CMakeLists.txt
@@ -33,13 +33,16 @@ 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})
+target_link_libraries(mpiguardtest ${MPI_CXX_LIBRARIES})
 add_executable("mpicollectivecommunication" mpicollectivecommunication.cc)
-#target_link_libraries(mpicollectivecommunication ${MPI_CXX_LIBRARIES})
+target_link_libraries(mpicollectivecommunication "dunecommon")
+target_link_libraries(mpicollectivecommunication ${MPI_CXX_LIBRARIES})
 add_executable("mpihelpertest" mpihelpertest.cc)
-#target_link_libraries(mpihelpertest ${MPI_CXX_LIBRARIES})
+target_link_libraries(mpihelpertest "dunecommon")
+target_link_libraries(mpihelpertest ${MPI_CXX_LIBRARIES})
 add_executable("mpihelpertest2" mpihelpertest.cc)
-#target_link_libraries(mpihelpertest2 ${MPI_CXX_LIBRARIES})
+target_link_libraries(mpihelpertest2 "dunecommon")
+target_link_libraries(mpihelpertest2 ${MPI_CXX_LIBRARIES})
 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