diff --git a/.gitignore b/.gitignore
index 10191e2890c8a29527457ab188a3ffee0aa515f2..d756843b3efeb1892a570843f8b783cd729df830 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 0000000000000000000000000000000000000000..653046b1a43ea8cd9045824d9c88b3996622e602
--- /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 4eed0f14a14a36659bbf942b61587ea2ae8fd2b7..0000000000000000000000000000000000000000
--- 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 0000000000000000000000000000000000000000..17bf6ff2e2205b2cb1ca0ac5084ae96fabb68a40
--- /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 0000000000000000000000000000000000000000..613dfb664b75999b008f0003a4d7c409cbf409ad
--- /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 0000000000000000000000000000000000000000..e83965c9c951f8a370c9054253043ecd902086c5
--- /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 0ff34a5477e8725a892f83f2efad9633f779b1ff..0000000000000000000000000000000000000000
--- 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 0000000000000000000000000000000000000000..be52cfccb403e159965b4f9c1a4bbe109a0462c1
--- /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 0000000000000000000000000000000000000000..f7b8ea5c993424d9524394428ec8f2ca9160b66a
--- /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 0000000000000000000000000000000000000000..c3b8df1ea5f3518c8ed8d86ed9f989aab5b096f0
--- /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 0000000000000000000000000000000000000000..0cb448ce33b710fa41b46f1fac477001a502c43e
--- /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 d0fcb5be242d45940fddac00613f223d03951cef..0000000000000000000000000000000000000000
--- 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 0000000000000000000000000000000000000000..3c522fe25fe8e01f95d01b18bc1f7a77f15e695b
--- /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 341b932b03f7479d3c8d6eb1cf43b77e9b43768d..0000000000000000000000000000000000000000
--- 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 885735f6417f9982b3e7d6a431db24ebc36d0e68..1f73c9517c05ac6536ca68cef9e7fc3175d036ea 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 ab20a410aa1b0f5723645f9c30519fc93c2a04e6..0000000000000000000000000000000000000000
--- 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 c8a3afe84ef8759a4c10a7f4e8177076cf89ace2..0000000000000000000000000000000000000000
--- 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 0000000000000000000000000000000000000000..3003c979d5dc5722c2b307b99a2016a55e88d179
--- /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 1bdf3d66be63a66e39d46187945b78b0bd35839f..0000000000000000000000000000000000000000
--- 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 2f01e5abc427bc75bf7bef892eab43c1802cd5dc..1dfa47e7b076bddc1f441776dafb4a4d862b86d5 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 01b17053a9d0de8319e452ecd44dbd7a95ce748b..e1b387f0027ceab585e13d16771c740db16735e3 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 c076d610057604d4d8074774035189a1eb6202c3..acedf87ed2781d1c7b3a233e01d22cd0d336e4bb 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 25099d52999065035ab468a2c8df7ec1cb655dd4..c3b7b9c51401fbf14415adb709439de54b9ccd67 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 a7e9ff717a4e35ae1cd9c797acc01f8eaa84f5ac..3c23e5d2a4fe4917df454a739807dc3ee7574231 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