From 2d45bc23746653f9fa178a9f5b6a179aca631804 Mon Sep 17 00:00:00 2001
From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de>
Date: Tue, 2 Oct 2018 14:18:43 +0200
Subject: [PATCH] Correctly fiddle around with paths when not building from
 perftool

---
 python/dune/perftool/sumfact/autotune.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/python/dune/perftool/sumfact/autotune.py b/python/dune/perftool/sumfact/autotune.py
index 1b48dffc..af324722 100644
--- a/python/dune/perftool/sumfact/autotune.py
+++ b/python/dune/perftool/sumfact/autotune.py
@@ -15,11 +15,18 @@ import subprocess
 
 def get_cmake_cache_entry(entry):
     for line in open(os.path.join(get_option("project_basedir"), "CMakeCache.txt"), "r"):
-        match = re.match("{}:[INTERNAL|FILEPATH|BOOL|STRING|PATH|UNINITIALIZED]+=(.*)".format(entry), line)
+        match = re.match("{}:[INTERNAL|FILEPATH|BOOL|STRING|PATH|UNINITIALIZED|STATIC]+=(.*)".format(entry), line)
         if match:
             return match.groups()[0]
 
 
+def get_perftool_dir():
+    if get_cmake_cache_entry("CMAKE_PROJECT_NAME") == "dune-perftool":
+        return get_option("project_basedir")
+    else:
+        return get_cmake_cache_entry("dune-perftool_DIR")
+
+
 def compiler_invocation(name, filename):
     # Determine the CMake Generator in use
     gen = get_cmake_cache_entry("CMAKE_GENERATOR")
@@ -30,7 +37,7 @@ def compiler_invocation(name, filename):
     compile_flags = [compiler]
 
     # Parse compiler flags
-    for line in open(os.path.join(get_option("project_basedir"), "python", "CMakeFiles", "_autotune_target.dir", "flags.make"), "r"):
+    for line in open(os.path.join(get_perftool_dir(), "python", "CMakeFiles", "_autotune_target.dir", "flags.make"), "r"):
         match = re.match("([^=]*)=(.*)", line)
         if match:
             compile_flags.extend(match.groups()[1].split())
@@ -39,14 +46,14 @@ def compiler_invocation(name, filename):
     compile_flags.append(filename)
 
     # Parse linker flags
-    for line in open(os.path.join(get_option("project_basedir"), "python", "CMakeFiles", "_autotune_target.dir", "link.txt"), "r"):
+    for line in open(os.path.join(get_perftool_dir(), "python", "CMakeFiles", "_autotune_target.dir", "link.txt"), "r"):
         match = re.match(".*_autotune_target (.*)", line)
         if match:
             for flag in match.groups()[0].split():
                 if flag.startswith("-") or os.path.isabs(flag):
                     compile_flags.append(flag)
                 else:
-                    compile_flags.append(os.path.join(get_option("project_basedir"), "python", flag))
+                    compile_flags.append(os.path.join(get_perftool_dir(), "python", flag))
 
     # Set an output name
     compile_flags.append("-o")
-- 
GitLab