diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 570dd57a1..e43c0da97 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,5 +1,5 @@ ## CMakeLists.txt -# +# # Author: Steffen Vogel # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University # SPDX-License-Identifier: Apache-2.0 @@ -42,13 +42,18 @@ endif() find_package(OpenSSL 1.0.0 REQUIRED) find_package(CURL 7.29 REQUIRED) find_package(spdlog 1.6.0 REQUIRED) -find_package(fmt 5.3.0 REQUIRED) +find_package(fmt 6.0.0 REQUIRED) find_package(Criterion) pkg_check_modules(JANSSON IMPORTED_TARGET REQUIRED jansson>=2.7) pkg_check_modules(LIBCONFIG IMPORTED_TARGET libconfig>=1.4.9) pkg_check_modules(UUID IMPORTED_TARGET REQUIRED uuid>=2.23) +if(fmt_VERSION VERSION_LESS "9.0.0") + message("Using legacy ostream formatting") + set(FMT_LEGACY_OSTREAM_FORMATTER 1) +endif() + add_subdirectory(lib) if(CRITERION_FOUND AND TOPLEVEL_PROJECT) add_subdirectory(tests) diff --git a/common/include/villas/config.hpp.in b/common/include/villas/config.hpp.in index 7d667bee3..63235af35 100644 --- a/common/include/villas/config.hpp.in +++ b/common/include/villas/config.hpp.in @@ -47,3 +47,6 @@ #define LOG_HEIGHT 25 #cmakedefine LOG_COLOR_DISABLE + +// Library Features +#cmakedefine FMT_LEGACY_OSTREAM_FORMATTER diff --git a/common/include/villas/exceptions.hpp b/common/include/villas/exceptions.hpp index 93677cdd2..e910dacd2 100644 --- a/common/include/villas/exceptions.hpp +++ b/common/include/villas/exceptions.hpp @@ -48,21 +48,17 @@ public: class JsonError : public std::runtime_error { protected: - const json_t *setting; json_error_t error; public: template JsonError(const json_t *s, const json_error_t &e, const std::string &what = std::string(), Args &&...args) - : std::runtime_error(fmt::format(what, std::forward(args)...)), - setting(s), error(e) {} - - virtual const char *what() const noexcept { - return fmt::format("{}: {} in {}:{}:{}", std::runtime_error::what(), - error.text, error.source, error.line, error.column) - .c_str(); - } + : std::runtime_error( + fmt::format("{}: {} in {}:{}:{}", + fmt::format(what, std::forward(args)...), + error.text, error.source, error.line, error.column)), + error(e) {} }; class ConfigError : public std::runtime_error { diff --git a/common/include/villas/graph/edge.hpp b/common/include/villas/graph/edge.hpp index 7b17a2f80..6beaf9137 100644 --- a/common/include/villas/graph/edge.hpp +++ b/common/include/villas/graph/edge.hpp @@ -7,6 +7,8 @@ #pragma once +#include +#include #include namespace villas { @@ -42,3 +44,9 @@ private: } // namespace graph } // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +#endif diff --git a/common/include/villas/graph/vertex.hpp b/common/include/villas/graph/vertex.hpp index ba65e2228..71a9f9c3d 100644 --- a/common/include/villas/graph/vertex.hpp +++ b/common/include/villas/graph/vertex.hpp @@ -7,6 +7,11 @@ #pragma once +#include +#include +#include +#include + namespace villas { namespace graph { @@ -40,3 +45,9 @@ private: } // namespace graph } // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +#endif diff --git a/common/include/villas/log.hpp b/common/include/villas/log.hpp index b61ec611a..0cc62775e 100644 --- a/common/include/villas/log.hpp +++ b/common/include/villas/log.hpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include diff --git a/common/include/villas/memory_manager.hpp b/common/include/villas/memory_manager.hpp index 381548e54..275d5a9fa 100644 --- a/common/include/villas/memory_manager.hpp +++ b/common/include/villas/memory_manager.hpp @@ -12,7 +12,8 @@ #include #include #include - +#include +#include #include #include @@ -222,3 +223,15 @@ private: }; } // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +#endif diff --git a/common/include/villas/plugin.hpp b/common/include/villas/plugin.hpp index 284853e3a..ea472d402 100644 --- a/common/include/villas/plugin.hpp +++ b/common/include/villas/plugin.hpp @@ -11,10 +11,10 @@ #include #include #include -#include #include - +#include #include +#include #include namespace villas { @@ -132,9 +132,7 @@ public: return logger; } - // Custom formatter for spdlog - template - friend OStream &operator<<(OStream &os, const class Plugin &p) { + friend std::ostream &operator<<(std::ostream &os, const class Plugin &p) { return os << p.getName(); } }; @@ -151,3 +149,9 @@ template void Registry::dump() { } // namespace plugin } // namespace villas + +#ifndef FMT_LEGACY_OSTREAM_FORMATTER +template <> +class fmt::formatter + : public fmt::ostream_formatter {}; +#endif