From 3d88c5b67dd23c2c8f23f3f6eb72bd116b4a9926 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Thu, 23 Aug 2018 16:03:34 +0200
Subject: [PATCH] add libconfig to dependencies

---
 common/CMakeLists.txt          | 1 +
 common/Dockerfile              | 1 +
 common/include/villas/compat.h | 8 +++++---
 common/lib/CMakeLists.txt      | 1 +
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index 112c6454d..bc0057768 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -59,6 +59,7 @@ find_package(Criterion)
 
 
 pkg_check_modules(JANSSON IMPORTED_TARGET REQUIRED jansson>=2.7)
+pkg_check_modules(LIBCONFIG IMPORTED_TARGET libconfig>=1.4.9)
 
 add_subdirectory(lib)
 if(CRITERION_FOUND)
diff --git a/common/Dockerfile b/common/Dockerfile
index 7283a89b8..7f121d1ba 100644
--- a/common/Dockerfile
+++ b/common/Dockerfile
@@ -60,6 +60,7 @@ ADD https://villas.fein-aachen.org/packages/villas.repo /etc/yum.repos.d/
 RUN dnf -y install \
 	jansson-devel \
 	libcurl-devel \
+	libconfig-devel \
 	openssl-devel openssl
 
 # Build & Install Criterion
diff --git a/common/include/villas/compat.h b/common/include/villas/compat.h
index 1f3b71ab3..4c6e5d29a 100644
--- a/common/include/villas/compat.h
+++ b/common/include/villas/compat.h
@@ -22,9 +22,10 @@
 
 #pragma once
 
-#include <libconfig.h>
 #include <jansson.h>
 
+#include <villas/config.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -33,11 +34,12 @@ extern "C" {
 size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags);
 #endif
 
-#if (LIBCONFIG_VER_MAJOR <= 1) && (LIBCONFIG_VER_MINOR < 5)
+#if defined(LIBCONFIG_FOUND) && (LIBCONFIG_VER_MAJOR <= 1) && (LIBCONFIG_VER_MINOR < 5)
+  #include <libconfig.h>
+
   #define config_setting_lookup config_lookup_from
 #endif
 
-
 #ifdef __MACH__
   #include <libkern/OSByteOrder.h>
 
diff --git a/common/lib/CMakeLists.txt b/common/lib/CMakeLists.txt
index ae498c38b..8cbbb2539 100644
--- a/common/lib/CMakeLists.txt
+++ b/common/lib/CMakeLists.txt
@@ -62,6 +62,7 @@ target_include_directories(villas-common PUBLIC
 
 target_link_libraries(villas-common PUBLIC
 	PkgConfig::JANSSON
+	PkgConfig::LIBCONFIG
 	${OPENSSL_LIBRARIES}
 	${CURL_LIBRARIES}
 	${CMAKE_DL_LIBS}