From e62254069686f5a39ddaf68acee595cbe704dc74 Mon Sep 17 00:00:00 2001
From: Tomas Pecka <peckato1@fit.cvut.cz>
Date: Sun, 18 Nov 2018 10:49:07 +0100
Subject: [PATCH] CMake: Configure SystemDeps also inside local project.conf

---
 CMake/generate.py     | 31 +++++++++++++++++++++++--------
 alib2cli/project.conf |  3 +++
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/CMake/generate.py b/CMake/generate.py
index f5c62520b7..8da61bfb02 100755
--- a/CMake/generate.py
+++ b/CMake/generate.py
@@ -199,8 +199,8 @@ class Generator:
 
     @classmethod
     def generate_library(cls, project, dry_run):
-        sys_includes, sys_libs, finds = cls._handle_system_deps(project.system_deps)
-        test_sys_includes, test_sys_libs, test_finds = cls._handle_system_deps(project.system_deps_test)
+        sys_includes, sys_libs, finds = cls._handle_system_deps(project, project.system_deps)
+        test_sys_includes, test_sys_libs, test_finds = cls._handle_system_deps(project, project.system_deps_test)
 
         with SmartOpen("CMakeLists.txt", 'w', directory=project.path, dry_run=dry_run) as f:
             f.write(CATEGORIES[project.category].format(
@@ -219,7 +219,7 @@ class Generator:
 
     @classmethod
     def generate_executable(cls, project, dry_run):
-        sys_includes, sys_libs, finds = cls._handle_system_deps(project.system_deps)
+        sys_includes, sys_libs, finds = cls._handle_system_deps(project, project.system_deps)
 
         with SmartOpen("CMakeLists.txt", 'w', directory=project.path, dry_run=dry_run) as f:
             f.write(CATEGORIES[project.category].format(
@@ -232,15 +232,30 @@ class Generator:
             ))
 
     @staticmethod
-    def _handle_system_deps(system_deps):
+    def _handle_system_deps(project, system_deps):
         libs, incl, find = [], [], []
+
+        def update(cfg, dep, incl, libs, find):
+            # try access the section, raises ConfigException if not present
+            Config.get_section(cfg, 'CMake:Deps:{}'.format(dep))
+
+            incl += Config.get_array(cfg, 'CMake:Deps:{}'.format(dep), 'include', fallback=[])
+            libs += Config.get_array(cfg, 'CMake:Deps:{}'.format(dep), 'link', fallback=[])
+            f = Config.get(CONFIG, 'CMake:Deps:{}'.format(dep), 'find', fallback="")
+            if f is not "":
+                find.append(f)
+
         for dep in system_deps:
-            incl = incl + Config.get_array(CONFIG, 'CMake:Deps:{}'.format(dep), 'include', fallback=[])
-            libs = libs + Config.get_array(CONFIG, 'CMake:Deps:{}'.format(dep), 'link', fallback=[])
             try:
-                find.append(Config.get(CONFIG, 'CMake:Deps:{}'.format(dep), 'find'))
+                # first, try to find CMake:Deps:{} section in projects's conf
+                update(project._config, dep, incl, libs, find)
             except ConfigException:
-                pass
+                try:
+                    # then in main conf
+                    update(CONFIG, dep, incl, libs, find)
+                except ConfigException:
+                    # warning!
+                    print("Warning: System dependency '{}' is not configured".format(dep), file=sys.stderr)
 
         return incl, libs, find
 
diff --git a/alib2cli/project.conf b/alib2cli/project.conf
index 596faa3f5f..b796599c0a 100644
--- a/alib2cli/project.conf
+++ b/alib2cli/project.conf
@@ -4,3 +4,6 @@ category: library
 [Dependencies]
 project: alib2xml alib2common alib2abstraction alib2measure alib2std
 system: xml2 stdc++fs
+
+[CMake:Deps:stdc++fs]
+link: stdc++fs
-- 
GitLab