From cefcd843fc92db64b8adaba139143f2938162c14 Mon Sep 17 00:00:00 2001 From: JordanTheToaster Date: Tue, 28 Nov 2023 10:19:22 +0000 Subject: [PATCH] Misc: Fix fmt errors --- cmake/SearchForStuff.cmake | 3 +++ common/SmallString.h | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/cmake/SearchForStuff.cmake b/cmake/SearchForStuff.cmake index 9683626f3d..f605185b9e 100644 --- a/cmake/SearchForStuff.cmake +++ b/cmake/SearchForStuff.cmake @@ -114,6 +114,9 @@ if(GCC_VERSION VERSION_GREATER_EQUAL "9.0" AND GCC_VERSION VERSION_LESS "9.2") This text being in a compile log in an open issue may cause it to be closed.") endif() +# Prevent fmt from being built with exceptions, or being thrown at call sites. +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFMT_EXCEPTIONS=0") + add_subdirectory(3rdparty/fmt/fmt EXCLUDE_FROM_ALL) add_subdirectory(3rdparty/rapidyaml/rapidyaml EXCLUDE_FROM_ALL) add_subdirectory(3rdparty/lzma EXCLUDE_FROM_ALL) diff --git a/common/SmallString.h b/common/SmallString.h index 1366ed8c25..5b3d2adcc1 100644 --- a/common/SmallString.h +++ b/common/SmallString.h @@ -321,3 +321,25 @@ __fi void SmallStringBase::fmt(fmt::format_string fmt, T&&... args) clear(); fmt::vformat_to(std::back_inserter(*this), fmt, fmt::make_format_args(args...)); } + +#define MAKE_FORMATTER(type) \ + template <> \ + struct fmt::formatter \ + { \ + template \ + constexpr auto parse(ParseContext& ctx) \ + { \ + return ctx.begin(); \ + } \ +\ + template \ + auto format(const type& str, FormatContext& ctx) \ + { \ + return fmt::format_to(ctx.out(), "{}", str.view()); \ + } \ + }; + +MAKE_FORMATTER(TinyString); +MAKE_FORMATTER(SmallString); + +#undef MAKE_FORMATTER \ No newline at end of file