diff --git a/src/pystencils_autodiff/CMakeLists.tmpl.txt b/src/pystencils_autodiff/CMakeLists.tmpl.txt
new file mode 100644
index 0000000000000000000000000000000000000000..6f9bcf59ed79ecf85e5cd6ca5073ff68f0f82a94
--- /dev/null
+++ b/src/pystencils_autodiff/CMakeLists.tmpl.txt
@@ -0,0 +1,6 @@
+waLBerla_link_files_to_builddir( *.prm )
+waLBerla_add_executable ( NAME autogen
+                          FILES {%- for f in files_to_compile %}
+                                {{ f }} 
+                                {%- endfor %}
+                          DEPENDS blockforest core cuda field lbm geometry timeloop gui )
diff --git a/src/pystencils_autodiff/walberla.py b/src/pystencils_autodiff/walberla.py
index 8271a294622cb2b8c8d30ee16b87c1ff675e7f5a..b45ffcdf8b45593f742f1155a507f818051c5c80 100644
--- a/src/pystencils_autodiff/walberla.py
+++ b/src/pystencils_autodiff/walberla.py
@@ -53,6 +53,14 @@ class WalberlaModule(JinjaCppFile):
         JinjaCppFile.__init__(self, ast_dict)
 
 
+class CMakeLists(JinjaCppFile):
+    TEMPLATE = read_template_from_file(join(dirname(__file__), 'CMakeLists.tmpl.txt'))
+
+    def __init__(self, files_to_compile):
+        ast_dict = {'files_to_compile': files_to_compile} # we try to avoid evil globbing
+        JinjaCppFile.__init__(self, ast_dict)
+
+
 class WalberlaMain(JinjaCppFile):
 
     TEMPLATE = jinja2.Template("""
diff --git a/src/pystencils_autodiff/wald_und_wiesen_simulation.py b/src/pystencils_autodiff/wald_und_wiesen_simulation.py
index ee142fafe3af703777b17323d7e9998901c5dd98..0223c348b12c438fba44fd656c4b01899ac7ffab 100644
--- a/src/pystencils_autodiff/wald_und_wiesen_simulation.py
+++ b/src/pystencils_autodiff/wald_und_wiesen_simulation.py
@@ -17,7 +17,7 @@ import pystencils
 import pystencils_walberla.codegen
 from pystencils.astnodes import Block, EmptyLine
 from pystencils_autodiff.walberla import (
-    AllocateAllFields, DefinitionsHeader, InitBoundaryHandling, LbCommunicationSetup,
+    AllocateAllFields, CMakeLists, DefinitionsHeader, InitBoundaryHandling, LbCommunicationSetup,
     ResolveUndefinedSymbols, RunTimeLoop, SweepCreation, SweepOverAllBlocks, TimeLoop,
     UniformBlockforestFromConfig, WalberlaMain, WalberlaModule)
 
@@ -104,10 +104,21 @@ class WaldUndWiesenSimulation():
         self._codegen_context.write_file("UserDefinitions.h",
                                          str(DefinitionsHeader(self._lb_model_name, self._flag_field_dtype)))
 
+    def _create_cmake_file(self):
+        try:
+            self._codegen_context.write_file("CMakeLists.txt",
+                                             str(CMakeLists([f for f in self._codegen_context.files_written()
+                                                             if f.endswith('.cpp') or f.endswith('.cu')])))
+        except AttributeError:
+            self._codegen_context.write_file("CMakeLists.txt",
+                                             str(CMakeLists([f for f in self._codegen_context.files.keys()
+                                                             if f.endswith('.cpp') or f.endswith('.cu')])))
+
     def write_files(self):
         self._create_helper_files()
         self._create_module()
         self._create_defintions_header()
+        self._create_cmake_file()  # has to be called last
 
     @property
     def boundary_conditions(self):