diff --git a/CMakeLists.txt b/CMakeLists.txt index 6da964fe1..8bc01987f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,7 +117,7 @@ endif() option(WITH_HOOKS "Build with support for processing hook plugins" ON) option(WITH_WEB "Build with internal webserver" ON) option(WITH_API "Build with remote control API" ON) -option(WITH_CONFIG "Build with support for libconfig configuration syntax" ON) +option(WITH_CONFIG "Build with support for libconfig configuration syntax" ${LIBCONFIG_FOUND}) option(WITH_SRC "Build villas-* executables" ${TOPLEVEL_PROJECT}) option(WITH_TOOLS "Build auxilary tools" ${TOPLEVEL_PROJECT}) option(WITH_TESTS "Run tests" ${TOPLEVEL_PROJECT}) diff --git a/include/villas/config.hpp b/include/villas/config.hpp index deea164e0..3780dd7b5 100644 --- a/include/villas/config.hpp +++ b/include/villas/config.hpp @@ -50,10 +50,10 @@ protected: /** Decode configuration file. */ void decode(); -#ifdef LIBCONFIG_FOUND +#ifdef WITH_CONFIG /** Convert libconfig .conf file to libjansson .json file. */ void libconfigDecode(); -#endif /* LIBCONFIG_FOUND */ +#endif /* WITH_CONFIG */ /** Load configuration from standard input (stdim). */ void loadFromStdio(); diff --git a/include/villas/config_helper.hpp b/include/villas/config_helper.hpp index 23ae8cb5d..31fb6e368 100644 --- a/include/villas/config_helper.hpp +++ b/include/villas/config_helper.hpp @@ -24,19 +24,19 @@ #include -#ifdef LIBCONFIG_FOUND -#include -#endif /* LIBCONFIG_FOUND */ +#ifdef WITH_CONFIG + #include +#endif /* WITH_CONFIG */ #include -#ifdef LIBCONFIG_FOUND +#ifdef WITH_CONFIG /** Convert a libconfig object to a jansson object */ json_t *config_to_json(config_setting_t *cfg); /** Convert a jansson object into a libconfig object. */ int json_to_config(json_t *json, config_setting_t *parent); -#endif /* LIBCONFIG_FOUND */ +#endif /* WITH_CONFIG */ int json_object_extend_str(json_t *orig, const char *str); diff --git a/include/villas/node/config.h.in b/include/villas/node/config.h.in index f191420a2..c66c0a3fc 100644 --- a/include/villas/node/config.h.in +++ b/include/villas/node/config.h.in @@ -51,6 +51,7 @@ #cmakedefine WITH_WEB #cmakedefine WITH_API #cmakedefine WITH_HOOKS +#cmakedefine WITH_CONFIG /* OS Headers */ #cmakedefine HAS_EVENTFD diff --git a/include/villas/node/exceptions.hpp b/include/villas/node/exceptions.hpp index fcfe11880..55e41838f 100644 --- a/include/villas/node/exceptions.hpp +++ b/include/villas/node/exceptions.hpp @@ -46,7 +46,7 @@ public: { } }; -#ifdef LIBCONFIG_FOUND +#ifdef WITH_CONFIG class LibconfigParseError : public ParseError { protected: @@ -62,7 +62,7 @@ public: config(c) { } }; -#endif /* LIBCONFIG_FOUND */ +#endif /* WITH_CONFIG */ class JanssonParseError : public ParseError { diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 744188399..d2a2f2ab0 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -78,7 +78,7 @@ list(APPEND WHOLE_ARCHIVES nodes) add_subdirectory(formats) list(APPEND WHOLE_ARCHIVES formats) -if(LIBCONFIG_FOUND) +if(WITH_CONFIG) list(APPEND INCLUDE_DIRS ${LIBCONFIG_INCLUDE_DIRS}) list(APPEND LIBRARIES PkgConfig::LIBCONFIG) endif() diff --git a/lib/config.cpp b/lib/config.cpp index ec614f4b1..f8f96fa1b 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -113,15 +113,16 @@ void Config::decode() root = json_loadf(local_file, 0, &err); if (root == nullptr) { -#ifdef LIBCONFIG_FOUND +#ifdef WITH_CONFIG /* We try again to parse the config in the legacy format */ libconfigDecode(); #else throw JanssonParseError(err); -#endif /* LIBCONFIG_FOUND */ +#endif /* WITH_CONFIG */ } } +#ifdef WITH_CONFIG void Config::libconfigDecode() { int ret; @@ -158,6 +159,7 @@ void Config::libconfigDecode() config_destroy(&cfg); } +#endif /* WITH_CONFIG */ void Config::prettyPrintError(json_error_t err) { diff --git a/lib/config_helper.cpp b/lib/config_helper.cpp index 945c72640..9a4a8bc79 100644 --- a/lib/config_helper.cpp +++ b/lib/config_helper.cpp @@ -29,7 +29,7 @@ #include #include -#ifdef LIBCONFIG_FOUND +#ifdef WITH_CONFIG static int json_to_config_type(int type) { @@ -166,7 +166,7 @@ int json_to_config(json_t *json, config_setting_t *parent) return 0; } -#endif /* LIBCONFIG_FOUND */ +#endif /* WITH_CONFIG */ void json_object_extend_key_value_token(json_t *obj, const char *key, const char *value) { diff --git a/tests/unit/config_json.cpp b/tests/unit/config_json.cpp index 7e9150343..42881615d 100644 --- a/tests/unit/config_json.cpp +++ b/tests/unit/config_json.cpp @@ -22,7 +22,7 @@ #include -#ifdef LIBCONFIG_FOUND +#ifdef WITH_CONFIG #include #include @@ -117,4 +117,4 @@ Test(utils, json_to_config) json_decref(json); } -#endif /* LIBCONFIG_FOUND */ +#endif /* WITH_CONFIG */ diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index e5450ba4e..6f918e026 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -20,7 +20,7 @@ # along with this program. If not, see . ################################################################################### -if(LIBCONFIG_FOUND) +if(WITH_CONFIG) add_executable(conf2json conf2json.cpp) target_link_libraries(conf2json PUBLIC villas)