From 83bb63477869c00850d45705aff943c2deebbb25 Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Fri, 27 Mar 2015 20:48:51 +0100
Subject: [PATCH] [Build  ] Migrate to CMake

---
 .gitignore                                   | 31 +----------
 CMakeLists.txt                               | 27 ++++++++++
 Makefile.am                                  |  7 ---
 cmake/modules/CMakeLists.txt                 |  3 ++
 cmake/modules/DuneTectonicMacros.cmake       |  1 +
 config.h.cmake                               | 45 ++++++++++++++++
 configure.ac                                 | 22 --------
 doc/CMakeLists.txt                           |  1 +
 doc/doxygen/CMakeLists.txt                   |  2 +
 doc/doxygen/Doxylocal                        | 30 +++++++++++
 dune/CMakeLists.txt                          |  1 +
 dune/Makefile.am                             |  3 --
 dune/tectonic/CMakeLists.txt                 | 16 ++++++
 dune/tectonic/Makefile.am                    |  4 --
 {src => dune/tectonic}/polyhedrondistance.hh |  4 +-
 m4/Makefile.am                               |  8 ---
 m4/dune-tectonic.m4                          | 19 -------
 src/CMakeLists.txt                           | 34 ++++++++++++
 src/Makefile.am                              | 54 --------------------
 src/distances.hh                             |  2 +-
 src/sand-wedge-data/mygrid.hh                |  2 +-
 src/sand-wedge-data/mygrid_tmpl.cc           |  4 +-
 src/sand-wedge-data/patchfunction.hh         |  2 +-
 src/sand-wedge.cc                            | 23 ++++++---
 src/.gitignore => stamp-regenerate-config-h  |  0
 25 files changed, 183 insertions(+), 162 deletions(-)
 create mode 100644 CMakeLists.txt
 delete mode 100644 Makefile.am
 create mode 100644 cmake/modules/CMakeLists.txt
 create mode 100644 cmake/modules/DuneTectonicMacros.cmake
 create mode 100644 config.h.cmake
 delete mode 100644 configure.ac
 create mode 100644 doc/CMakeLists.txt
 create mode 100644 doc/doxygen/CMakeLists.txt
 create mode 100644 doc/doxygen/Doxylocal
 create mode 100644 dune/CMakeLists.txt
 delete mode 100644 dune/Makefile.am
 create mode 100644 dune/tectonic/CMakeLists.txt
 delete mode 100644 dune/tectonic/Makefile.am
 rename {src => dune/tectonic}/polyhedrondistance.hh (98%)
 delete mode 100644 m4/Makefile.am
 delete mode 100644 m4/dune-tectonic.m4
 create mode 100644 src/CMakeLists.txt
 delete mode 100644 src/Makefile.am
 rename src/.gitignore => stamp-regenerate-config-h (100%)

diff --git a/.gitignore b/.gitignore
index 10191e28..d756843b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,30 +1 @@
-*.o
-*.pyc
-.clang-format
-.deps
-.libs
-/aclocal.m4
-/am
-/autom4te.cache
-/compile
-/config.guess
-/config.h
-/config.h.in
-/config.log
-/config.lt
-/config.status
-/config.sub
-/configure
-/depcomp
-/dependencies.m4
-/dune-tectonic.pc
-/install-sh
-/libtool
-/ltmain.sh
-/missing
-/stamp-h1
-/test-driver
-Makefile
-Makefile.in
-src/sand-wedge-?D
-src/sliding-block-?D
+build-cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 00000000..653046b1
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 2.8.6)
+project(dune-tectonic CXX)
+
+if(NOT (dune-common_DIR OR dune-common_ROOT OR
+      "${CMAKE_PREFIX_PATH}" MATCHES ".*dune-common.*"))
+    string(REPLACE  ${CMAKE_PROJECT_NAME} dune-common dune-common_DIR
+      ${PROJECT_BINARY_DIR})
+endif()
+
+#find dune-common and set the module path
+find_package(dune-common REQUIRED)
+list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules"
+  ${dune-common_MODULE_PATH})
+
+#include the dune macros
+include(DuneMacros)
+
+# start a dune project with information from dune.module
+dune_project()
+
+add_subdirectory("src")
+add_subdirectory("dune")
+add_subdirectory("doc")
+add_subdirectory("cmake/modules")
+
+# finalize the dune project, e.g. generating config.h etc.
+finalize_dune_project(GENERATE_CONFIG_H_CMAKE)
diff --git a/Makefile.am b/Makefile.am
deleted file mode 100644
index 4eed0f14..00000000
--- a/Makefile.am
+++ /dev/null
@@ -1,7 +0,0 @@
-EXTRA_DIST = dune.module
-
-SUBDIRS = src m4 dune
-
-include $(top_srcdir)/am/top-rules
-include $(top_srcdir)/am/global-rules
-
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
new file mode 100644
index 00000000..17bf6ff2
--- /dev/null
+++ b/cmake/modules/CMakeLists.txt
@@ -0,0 +1,3 @@
+set(modules "DuneTectonicMacros.cmake")
+
+install(FILES ${modules} DESTINATION ${DUNE_INSTALL_MODULEDIR})
diff --git a/cmake/modules/DuneTectonicMacros.cmake b/cmake/modules/DuneTectonicMacros.cmake
new file mode 100644
index 00000000..613dfb66
--- /dev/null
+++ b/cmake/modules/DuneTectonicMacros.cmake
@@ -0,0 +1 @@
+# File for module specific CMake tests.
diff --git a/config.h.cmake b/config.h.cmake
new file mode 100644
index 00000000..e83965c9
--- /dev/null
+++ b/config.h.cmake
@@ -0,0 +1,45 @@
+/* begin dune-tectonic
+   put the definitions for config.h specific to
+   your project here. Everything above will be
+   overwritten
+*/
+
+/* begin private */
+/* Name of package */
+#define PACKAGE "@DUNE_MOD_NAME@"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "@DUNE_MAINTAINER@"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "@DUNE_MOD_NAME@"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "@DUNE_MOD_NAME@ @DUNE_MOD_VERSION@"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "@DUNE_MOD_NAME@"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL "@DUNE_MOD_URL@"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "@DUNE_MOD_VERSION@"
+
+/* end private */
+
+/* Define to the version of dune-tectonic */
+#define DUNE_TECTONIC_VERSION "@DUNE_TECTONIC_VERSION@"
+
+/* Define to the major version of dune-tectonic */
+#define DUNE_TECTONIC_VERSION_MAJOR @DUNE_TECTONIC_VERSION_MAJOR@
+
+/* Define to the minor version of dune-tectonic */
+#define DUNE_TECTONIC_VERSION_MINOR @DUNE_TECTONIC_VERSION_MINOR@
+
+/* Define to the revision of dune-tectonic */
+#define DUNE_TECTONIC_VERSION_REVISION @DUNE_TECTONIC_VERSION_REVISION@
+
+/* end dune-tectonic
+   Everything below here will be overwritten
+*/
diff --git a/configure.ac b/configure.ac
deleted file mode 100644
index 0ff34a54..00000000
--- a/configure.ac
+++ /dev/null
@@ -1,22 +0,0 @@
-# -*- Autoconf -*-
-# Process this file with autoconf to produce a configure script.
-AC_PREREQ(2.50)
-DUNE_AC_INIT # gets module version from dune.module file
-AM_INIT_AUTOMAKE
-AM_SILENT_RULES
-AC_CONFIG_SRCDIR([dune-tectonic.pc.in])
-AC_CONFIG_HEADERS([config.h])
-
-DUNE_CHECK_ALL
-
-AC_CONFIG_FILES([
-  Makefile
-  src/Makefile
-  dune/Makefile
-  dune/tectonic/Makefile
-  m4/Makefile
-  dune-tectonic.pc
-])
-AC_OUTPUT
-# finally print the summary information
-DUNE_SUMMARY_ALL
diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
new file mode 100644
index 00000000..be52cfcc
--- /dev/null
+++ b/doc/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory("doxygen")
diff --git a/doc/doxygen/CMakeLists.txt b/doc/doxygen/CMakeLists.txt
new file mode 100644
index 00000000..f7b8ea5c
--- /dev/null
+++ b/doc/doxygen/CMakeLists.txt
@@ -0,0 +1,2 @@
+# shortcut for creating the Doxyfile.in and Doxyfile
+add_doxygen_target()
diff --git a/doc/doxygen/Doxylocal b/doc/doxygen/Doxylocal
new file mode 100644
index 00000000..c3b8df1e
--- /dev/null
+++ b/doc/doxygen/Doxylocal
@@ -0,0 +1,30 @@
+# This file contains local changes to the doxygen configuration
+# please us '+=' to add file/directories to the lists
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT                 += @top_srcdir@/dune/
+# see e.g. dune-grid for the examples of mainpage and modules
+# INPUT                 += @srcdir@/mainpage \
+#                          @srcdir@/modules
+
+# The EXCLUDE tag can be used to specify files and/or directories that should
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+# EXCLUDE               += @top_srcdir@/dune/tectonic/test
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+# EXAMPLE_PATH          += @top_srcdir@/src
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+# IMAGE_PATH            += @top_srcdir@/dune/tectonic/pics
diff --git a/dune/CMakeLists.txt b/dune/CMakeLists.txt
new file mode 100644
index 00000000..0cb448ce
--- /dev/null
+++ b/dune/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(tectonic)
diff --git a/dune/Makefile.am b/dune/Makefile.am
deleted file mode 100644
index d0fcb5be..00000000
--- a/dune/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-SUBDIRS = tectonic
-
-include $(top_srcdir)/am/global-rules
diff --git a/dune/tectonic/CMakeLists.txt b/dune/tectonic/CMakeLists.txt
new file mode 100644
index 00000000..3c522fe2
--- /dev/null
+++ b/dune/tectonic/CMakeLists.txt
@@ -0,0 +1,16 @@
+install(FILES
+  body.hh
+  frictiondata.hh
+  frictionpotential.hh
+  globalfrictiondata.hh
+  globalfriction.hh
+  globalratestatefriction.hh
+  gravity.hh
+  localfriction.hh
+  minimisation.hh
+  myblockproblem.hh
+  mydirectionalconvexfunction.hh
+  pointtractionboundaryassembler.hh
+  quadraticenergy.hh
+  tectonic.hh
+  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/tectonic)
diff --git a/dune/tectonic/Makefile.am b/dune/tectonic/Makefile.am
deleted file mode 100644
index 341b932b..00000000
--- a/dune/tectonic/Makefile.am
+++ /dev/null
@@ -1,4 +0,0 @@
-tectonicincludedir = $(includedir)/dune/tectonic
-tectonicinclude_HEADERS = tectonic.hh
-
-include $(top_srcdir)/am/global-rules
diff --git a/src/polyhedrondistance.hh b/dune/tectonic/polyhedrondistance.hh
similarity index 98%
rename from src/polyhedrondistance.hh
rename to dune/tectonic/polyhedrondistance.hh
index 885735f6..1f73c951 100644
--- a/src/polyhedrondistance.hh
+++ b/dune/tectonic/polyhedrondistance.hh
@@ -1,5 +1,5 @@
-#ifndef SRC_POLYHEDRONDISTANCE_HH
-#define SRC_POLYHEDRONDISTANCE_HH
+#ifndef DUNE_TECTONIC_POLYHEDRONDISTANCE_HH
+#define DUNE_TECTONIC_POLYHEDRONDISTANCE_HH
 
 // Based on the closest point projection from dune-contact
 
diff --git a/m4/Makefile.am b/m4/Makefile.am
deleted file mode 100644
index ab20a410..00000000
--- a/m4/Makefile.am
+++ /dev/null
@@ -1,8 +0,0 @@
-M4FILES = dune-tectonic.m4
-
-aclocaldir = $(datadir)/aclocal
-aclocal_DATA = $(M4FILES)
-
-EXTRA_DIST = $(M4FILES)
-
-include $(top_srcdir)/am/global-rules
diff --git a/m4/dune-tectonic.m4 b/m4/dune-tectonic.m4
deleted file mode 100644
index c8a3afe8..00000000
--- a/m4/dune-tectonic.m4
+++ /dev/null
@@ -1,19 +0,0 @@
-dnl -*- autoconf -*-
-# Macros needed to find dune-tectonic and dependent libraries.  They are called by
-# the macros in ${top_src_dir}/dependencies.m4, which is generated by
-# "dunecontrol autogen"
-
-# Additional checks needed to build dune-tectonic
-# This macro should be invoked by every module which depends on dune-tectonic, as
-# well as by dune-tectonic itself
-AC_DEFUN([DUNE_TECTONIC_CHECKS],[
-  AC_REQUIRE([AX_BOOST_BASE])
-])
-
-# Additional checks needed to find dune-tectonic
-# This macro should be invoked by every module which depends on dune-tectonic, but
-# not by dune-tectonic itself
-AC_DEFUN([DUNE_TECTONIC_CHECK_MODULE],
-[
-  DUNE_CHECK_MODULES([dune-tectonic],[tectonic/tectonic.hh])
-])
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 00000000..3003c979
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,34 @@
+set(SOURCE_FILES
+  assemblers.cc
+  boundary_writer.cc
+  coupledtimestepper.cc
+  enumparser.cc
+  fixedpointiterator.cc
+  friction_writer.cc
+  sand-wedge.cc
+  sand-wedge-data/mygeometry.cc
+  sand-wedge-data/mygrid.cc
+  solverfactory.cc
+  state.cc
+  timestepping.cc
+  vtk.cc
+)
+
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/sand-wedge-data")
+dune_symlink_to_source_files("sand-wedge-data/boundaryconditions.py")
+dune_symlink_to_source_files("sand-wedge-data/parset.cfg")
+
+find_package(Boost REQUIRED system filesystem)
+include_directories(${Boost_INCLUDE_DIR})
+
+foreach(_dim 2 3)
+  set(_target sand-wedge-${_dim}D)
+  add_executable(${_target} ${SOURCE_FILES})
+  add_dune_pythonlibs_flags(${_target})
+  add_dune_ug_flags(${_target})
+
+  target_link_libraries(${_target} ${Boost_FILESYSTEM_LIBRARY})
+  target_link_libraries(${_target} ${Boost_SYSTEM_LIBRARY})
+
+  set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS "MY_DIM=${_dim}")
+endforeach()
diff --git a/src/Makefile.am b/src/Makefile.am
deleted file mode 100644
index 1bdf3d66..00000000
--- a/src/Makefile.am
+++ /dev/null
@@ -1,54 +0,0 @@
-bin_PROGRAMS = sand-wedge-2D sand-wedge-3D
-
-common_sources = \
-	assemblers.cc \
-	boundary_writer.cc \
-	coupledtimestepper.cc \
-	enumparser.cc \
-	fixedpointiterator.cc \
-	friction_writer.cc \
-	sand-wedge-data/mygeometry.cc \
-	sand-wedge-data/mygrid.cc \
-	solverfactory.cc \
-	state.cc \
-	timestepping.cc \
-	vtk.cc
-
-sand_wedge_2D_SOURCES = $(common_sources) sand-wedge.cc
-sand_wedge_2D_CPPFLAGS = \
-	$(AM_CPPFLAGS) $(BOOST_CPPFLAGS) \
-	-Ddatadir=\"$(abs_srcdir)/sand-wedge-data/\" -DMY_DIM=2
-sand_wedge_3D_SOURCES = $(common_sources) sand-wedge.cc
-sand_wedge_3D_CPPFLAGS = \
-	$(AM_CPPFLAGS) $(BOOST_CPPFLAGS) \
-	-Ddatadir=\"$(abs_srcdir)/sand-wedge-data/\" -DMY_DIM=3
-
-# Some are for clang, others are for gcc
-AM_CXXFLAGS = \
-	-Wall \
-	-Wextra \
-	-Wno-unused-parameter \
-	-Wno-overloaded-virtual
-
-AM_CPPFLAGS = \
-	-DDUNE_FMatrix_WITH_CHECKING \
-	$(DUNE_CPPFLAGS) \
-	$(PYTHON_CPPFLAGS) \
-	$(ALUGRID_CPPFLAGS) \
-	$(UG_CPPFLAGS) \
-	-I$(top_srcdir)
-
-# The libraries have to be given in reverse order (most basic libraries
-# last).
-LDADD = \
-	$(DUNE_LDFLAGS) $(DUNE_LIBS) \
-	$(ALUGRID_LIBS) \
-	$(UG_LIBS) \
-	$(PYTHON_LIBS)
-AM_LDFLAGS = \
-	$(DUNE_LDFLAGS) \
-	$(ALUGRID_LDFLAGS) \
-	$(UG_LDFLAGS) \
-	$(PYTHON_LDFLAGS)
-
-include $(top_srcdir)/am/global-rules
diff --git a/src/distances.hh b/src/distances.hh
index 2f01e5ab..1dfa47e7 100644
--- a/src/distances.hh
+++ b/src/distances.hh
@@ -1,7 +1,7 @@
 #ifndef SRC_DISTANCES_HH
 #define SRC_DISTANCES_HH
 
-#include "polyhedrondistance.hh"
+#include <dune/tectonic/polyhedrondistance.hh>
 #include "sand-wedge-data/mygeometry.hh"
 
 template <class Geometry> double diameter(Geometry const &geometry) {
diff --git a/src/sand-wedge-data/mygrid.hh b/src/sand-wedge-data/mygrid.hh
index 01b17053..e1b387f0 100644
--- a/src/sand-wedge-data/mygrid.hh
+++ b/src/sand-wedge-data/mygrid.hh
@@ -11,7 +11,7 @@
 #include <dune/fufem/boundarypatch.hh>
 #pragma clang diagnostic pop
 
-#include "../polyhedrondistance.hh"
+#include <dune/tectonic/polyhedrondistance.hh>
 
 #include "mygeometry.hh"
 
diff --git a/src/sand-wedge-data/mygrid_tmpl.cc b/src/sand-wedge-data/mygrid_tmpl.cc
index c076d610..acedf87e 100644
--- a/src/sand-wedge-data/mygrid_tmpl.cc
+++ b/src/sand-wedge-data/mygrid_tmpl.cc
@@ -2,8 +2,8 @@
 #error MY_DIM unset
 #endif
 
-#include "explicitgrid.hh"
-#include "explicitvectors.hh"
+#include "../explicitgrid.hh"
+#include "../explicitvectors.hh"
 
 template class GridConstructor<Grid>;
 
diff --git a/src/sand-wedge-data/patchfunction.hh b/src/sand-wedge-data/patchfunction.hh
index 25099d52..c3b7b9c5 100644
--- a/src/sand-wedge-data/patchfunction.hh
+++ b/src/sand-wedge-data/patchfunction.hh
@@ -5,7 +5,7 @@
 #include <dune/common/fvector.hh>
 #include <dune/common/parametertree.hh>
 
-#include "../polyhedrondistance.hh"
+#include <dune/tectonic/polyhedrondistance.hh>
 
 class PatchFunction
     : public Dune::VirtualFunction<Dune::FieldVector<double, MY_DIM>,
diff --git a/src/sand-wedge.cc b/src/sand-wedge.cc
index a7e9ff71..3c23e5d2 100644
--- a/src/sand-wedge.cc
+++ b/src/sand-wedge.cc
@@ -12,16 +12,16 @@
 #undef HAVE_IPOPT
 #endif
 
-#ifndef datadir
-#error datadir unset
-#endif
-
 #include <cmath>
 #include <exception>
 #include <fstream>
 #include <iostream>
 #include <iomanip>
 
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/format.hpp>
+
 #include <dune/common/bitsetvector.hh>
 #include <dune/common/exceptions.hh>
 #include <dune/common/fmatrix.hh>
@@ -77,17 +77,24 @@
 
 size_t const dims = MY_DIM;
 
-void initPython() {
+void initPython(std::string dataDirectory) {
   Python::start();
 
   Python::run("import sys");
-  Python::run("sys.path.append('" datadir "')");
+  Python::run(str(boost::format("sys.path.append('%s')") % dataDirectory));
 }
 
 int main(int argc, char *argv[]) {
   try {
+    auto const dataDirectory =
+        boost::filesystem::system_complete(boost::filesystem::path(argv[0]))
+            .parent_path() /
+        boost::filesystem::path("sand-wedge-data");
+
     Dune::ParameterTree parset;
-    Dune::ParameterTreeParser::readINITree(datadir "/parset.cfg", parset);
+    Dune::ParameterTreeParser::readINITree(
+        (dataDirectory / boost::filesystem::path("parset.cfg")).string(),
+        parset);
     Dune::ParameterTreeParser::readOptions(argc, argv, parset);
 
     MyGeometry::render();
@@ -167,7 +174,7 @@ int main(int argc, char *argv[]) {
     using FunctionMap = SharedPointerMap<std::string, Function>;
     FunctionMap functions;
     {
-      initPython();
+      initPython(dataDirectory.string());
       Python::import("boundaryconditions")
           .get("Functions")
           .toC<typename FunctionMap::Base>(functions);
diff --git a/src/.gitignore b/stamp-regenerate-config-h
similarity index 100%
rename from src/.gitignore
rename to stamp-regenerate-config-h
-- 
GitLab