From da64ef5f806dfbd9dfad15bc0507c5d07c2e7ca7 Mon Sep 17 00:00:00 2001
From: Steffen Vogel <post@steffenvogel.de>
Date: Sat, 6 Apr 2019 18:21:47 +0200
Subject: [PATCH] cmake: support build without libconfig

---
 common/CMakeLists.txt             | 2 ++
 common/include/villas/compat.h    | 2 +-
 common/include/villas/config.h.in | 3 ---
 common/lib/CMakeLists.txt         | 7 ++++++-
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index 0b3a62d3f..5ace434a3 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -83,4 +83,6 @@ if(TOPLEVEL_PROJECT)
     message(STATUS "  VARIANT:         ${CMAKE_PROJECT_VARIANT}")
     message(STATUS "  BUILD_ID:        ${CMAKE_PROJECT_BUILD_ID}")
     message(STATUS "  BUILD_DATE:      ${CMAKE_PROJECT_BUILD_DATE}")
+    message(STATUS "  ARCH:            ${CMAKE_SYSTEM_PROCESSOR}")
+    message(STATUS "  OS:              ${CMAKE_SYSTEM_NAME}")
 endif()
diff --git a/common/include/villas/compat.h b/common/include/villas/compat.h
index bd907be9a..65cef210a 100644
--- a/common/include/villas/compat.h
+++ b/common/include/villas/compat.h
@@ -37,7 +37,7 @@ int json_dumpfd(const json_t *json, int output, size_t flags);
 json_t *json_loadfd(int input, size_t flags, json_error_t *error);
 #endif
 
-#if defined(LIBCONFIG_FOUND) && (LIBCONFIG_VER_MAJOR <= 1) && (LIBCONFIG_VER_MINOR < 5)
+#if defined(WITH_CONFIG) && (LIBCONFIG_VER_MAJOR <= 1) && (LIBCONFIG_VER_MINOR < 5)
   #include <libconfig.h>
 
   #define config_setting_lookup config_lookup_from
diff --git a/common/include/villas/config.h.in b/common/include/villas/config.h.in
index 5661c3e88..08e60d71d 100644
--- a/common/include/villas/config.h.in
+++ b/common/include/villas/config.h.in
@@ -44,9 +44,6 @@
 #define PROJECT_NAME		"@CMAKE_PROJECT_DESCRIPTION@"
 #define USER_AGENT		"@CMAKE_PROJECT_DESCRIPTION@ (@CMAKE_PROJECT_BUILD_ID@)"
 
-/* Available Libraries */
-#cmakedefine LIBCONFIG_FOUND
-
 /* Paths */
 #define PREFIX			"@CMAKE_INSTALL_PREFIX@"
 #define PLUGIN_PATH		"@CMAKE_INSTALL_PREFIX@/share/villas/node/plugins"
diff --git a/common/lib/CMakeLists.txt b/common/lib/CMakeLists.txt
index 4f9ecdb6c..a69215d3f 100644
--- a/common/lib/CMakeLists.txt
+++ b/common/lib/CMakeLists.txt
@@ -77,7 +77,6 @@ target_include_directories(villas-common PUBLIC
 
 target_link_libraries(villas-common PUBLIC
 	PkgConfig::JANSSON
-	PkgConfig::LIBCONFIG
 	${OPENSSL_LIBRARIES}
 	${CURL_LIBRARIES}
 	${CMAKE_DL_LIBS}
@@ -86,6 +85,12 @@ target_link_libraries(villas-common PUBLIC
 	stdc++
 )
 
+if(WITH_CONFIG)
+	target_link_libraries(villas-common PUBLIC
+		PkgConfig::LIBCONFIG
+	)
+endif()
+
 target_compile_definitions(villas-common PUBLIC
 	-D__STDC_FORMAT_MACROS -D_GNU_SOURCE
 )