Skip to content

Commit 757d458

Browse files
committed
Compatibility with fmtlib 10.1.x
1 parent ff9d180 commit 757d458

File tree

8 files changed

+39
-38
lines changed

8 files changed

+39
-38
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ find_package(ZLIB REQUIRED)
134134
find_package(zstd MODULE REQUIRED) # MODULE so that zstd::zstd is available
135135
find_package(OpenSSL COMPONENTS Crypto SSL REQUIRED)
136136
find_package(glm REQUIRED)
137-
find_package(fmt 9.1.0...<10 REQUIRED)
137+
find_package(fmt 9 REQUIRED)
138138
find_package(PNG REQUIRED)
139139

140140
# glslang versions older than 11.11.0 define targets without a namespace

src/Cafe/CafeSystem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void InfoLog_PrintActiveSettings()
251251
if(!GetConfig().vk_accurate_barriers.GetValue())
252252
cemuLog_log(LogType::Force, "Accurate barriers are disabled!");
253253
}
254-
cemuLog_log(LogType::Force, "Console language: {}", config.console_language);
254+
cemuLog_log(LogType::Force, "Console language: {}", stdx::to_underlying(config.console_language.GetValue()));
255255
}
256256

257257
struct SharedDataEntry

src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSL.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,11 @@ void _emitOperandInputCode(LatteDecompilerShaderContext* shaderContext, LatteDec
908908
{
909909
char floatAsStr[32];
910910
size_t floatAsStrLen = fmt::format_to_n(floatAsStr, 32, "{:#}", *(float*)&constVal).size;
911+
if(floatAsStrLen > 0 && floatAsStr[floatAsStrLen-1] == '.')
912+
{
913+
floatAsStr[floatAsStrLen] = '0';
914+
floatAsStrLen++;
915+
}
911916
cemu_assert_debug(floatAsStrLen >= 3); // shortest possible form is "0.0"
912917
src->add(std::string_view(floatAsStr, floatAsStrLen));
913918
}

src/Cemu/Logging/CemuLogging.h

+1-16
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,6 @@ bool cemuLog_log(LogType type, std::string_view text);
7070
bool cemuLog_log(LogType type, std::u8string_view text);
7171
void cemuLog_waitForFlush(); // wait until all log lines are written
7272

73-
template <typename T>
74-
auto ForwardEnum(T t)
75-
{
76-
if constexpr (std::is_enum_v<T>)
77-
return fmt::underlying(t);
78-
else
79-
return std::forward<T>(t);
80-
}
81-
82-
template <typename... TArgs>
83-
auto ForwardEnum(std::tuple<TArgs...> t)
84-
{
85-
return std::apply([](auto... x) { return std::make_tuple(ForwardEnum(x)...); }, t);
86-
}
87-
8873
template<typename T, typename ... TArgs>
8974
bool cemuLog_log(LogType type, std::basic_string<T> formatStr, TArgs&&... args)
9075
{
@@ -98,7 +83,7 @@ bool cemuLog_log(LogType type, std::basic_string<T> formatStr, TArgs&&... args)
9883
else
9984
{
10085
const auto format_view = fmt::basic_string_view<T>(formatStr);
101-
const auto text = fmt::vformat(format_view, fmt::make_format_args<fmt::buffer_context<T>>(ForwardEnum(args)...));
86+
const auto text = fmt::vformat(format_view, fmt::make_format_args<fmt::buffer_context<T>>(args...));
10287
cemuLog_log(type, std::basic_string_view(text.data(), text.size()));
10388
}
10489
return true;

src/Common/MemPtr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,5 @@ template <typename T>
159159
struct fmt::formatter<MEMPTR<T>> : formatter<string_view>
160160
{
161161
template <typename FormatContext>
162-
auto format(const MEMPTR<T>& v, FormatContext& ctx) { return formatter<string_view>::format(fmt::format("{:#x}", v.GetMPTR()), ctx); }
162+
auto format(const MEMPTR<T>& v, FormatContext& ctx) const -> format_context::iterator { return fmt::format_to(ctx.out(), "{:#x}", v.GetMPTR()); }
163163
};

src/Common/precompiled.h

+24-2
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,29 @@ inline uint32 GetTitleIdLow(uint64 titleId)
552552
#include "Cafe/HW/Espresso/PPCState.h"
553553
#include "Cafe/HW/Espresso/PPCCallback.h"
554554

555+
// generic formatter for enums (to underlying)
556+
template <typename Enum>
557+
requires std::is_enum_v<Enum>
558+
struct fmt::formatter<Enum> : fmt::formatter<underlying_t<Enum>>
559+
{
560+
auto format(const Enum& e, format_context& ctx) const
561+
{
562+
//return fmt::format_to(ctx.out(), "{}", fmt::underlying(e));
563+
564+
return formatter<underlying_t<Enum>>::format(fmt::underlying(e), ctx);
565+
}
566+
};
567+
568+
// formatter for betype<T>
569+
template <typename T>
570+
struct fmt::formatter<betype<T>> : fmt::formatter<T>
571+
{
572+
auto format(const betype<T>& e, format_context& ctx) const
573+
{
574+
return formatter<T>::format(static_cast<T>(e), ctx);
575+
}
576+
};
577+
555578
// useful C++23 stuff that isn't yet widely supported
556579

557580
// std::to_underlying
@@ -561,5 +584,4 @@ namespace stdx
561584
constexpr std::underlying_type_t<EnumT> to_underlying(EnumT e) noexcept {
562585
return static_cast<std::underlying_type_t<EnumT>>(e);
563586
};
564-
}
565-
587+
}

src/config/ConfigValue.h

-16
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,3 @@ class ConfigValueBounds : public ConfigValue<TType>
232232
const TType m_min_value;
233233
const TType m_max_value;
234234
};
235-
236-
template <typename TType>
237-
struct fmt::formatter< ConfigValue<TType> > : formatter<TType> {
238-
template <typename FormatContext>
239-
auto format(const ConfigValue<TType>& v, FormatContext& ctx) {
240-
return formatter<TType>::format(v.GetValue(), ctx);
241-
}
242-
};
243-
244-
template <typename TType>
245-
struct fmt::formatter< ConfigValueBounds<TType> > : formatter<TType> {
246-
template <typename FormatContext>
247-
auto format(const ConfigValueBounds<TType>& v, FormatContext& ctx) {
248-
return formatter<TType>::format(v.GetValue(), ctx);
249-
}
250-
};

src/config/XMLConfig.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ class XMLConfigParser
235235
set(name, value.load());
236236
}
237237

238+
template <typename T>
239+
void set(const char* name, const ConfigValue<T>& value)
240+
{
241+
set(name, value.GetValue());
242+
}
243+
238244
void set(const char* name, uint64 value)
239245
{
240246
set(name, (sint64)value);
@@ -462,4 +468,3 @@ class XMLDataConfig : public XMLConfig<T, L, S>
462468
private:
463469
T m_data;
464470
};
465-

0 commit comments

Comments
 (0)