From 1acb0a1701c4ff881b47094f6dfb0c48e7cb4386 Mon Sep 17 00:00:00 2001
From: Stephan Seitz <stephan.seitz@fau.de>
Date: Wed, 29 Jan 2020 20:24:58 +0100
Subject: [PATCH] Also generate CMakeLists.txt

---
 src/pystencils_autodiff/CMakeLists.tmpl.txt         |  6 ++++++
 src/pystencils_autodiff/walberla.py                 |  8 ++++++++
 .../wald_und_wiesen_simulation.py                   | 13 ++++++++++++-
 3 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 src/pystencils_autodiff/CMakeLists.tmpl.txt

diff --git a/src/pystencils_autodiff/CMakeLists.tmpl.txt b/src/pystencils_autodiff/CMakeLists.tmpl.txt
new file mode 100644
index 0000000..6f9bcf5
--- /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 8271a29..b45ffcd 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 ee142fa..0223c34 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):
-- 
GitLab