diff --git a/include/fmt/core.h b/include/fmt/core.h index f9e3b7d6dc163..788443786cc99 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -242,6 +242,20 @@ # endif #endif + +#if !defined(FMT_WINDOWS_NO_WCHAR) && defined(_WIN32) +#define XSTR(x) STR(x) +#define STR(x) #x +#pragma message "WINVER: " XSTR(WINVER) +#pragma message "_WIN32_WINNT: " XSTR(WINVER) +# if ((defined(__has_include) && !FMT_HAS_INCLUDE()) || \ + (defined(WINVER) && WINVER <= 0x0500 && + !(defined(_WIN32_WINNT) && _WIN32_WINNT > 0))) +// A legacy Windows platform without wide char APIs, e.g. Windows 98, original Xbox. +# define FMT_WINDOWS_NO_WCHAR +# endif +#endif + // Enable minimal optimizations for more compact code in debug mode. FMT_GCC_PRAGMA("GCC push_options") #if !defined(__OPTIMIZE__) && !defined(__NVCOMPILER) && !defined(__LCC__) && \ @@ -2675,7 +2689,7 @@ void vformat_to(buffer& buf, basic_string_view fmt, typename vformat_args::type args, locale_ref loc = {}); FMT_API void vprint_mojibake(std::FILE*, string_view, format_args); -#ifndef _WIN32 +#if !defined(_WIN32) || defined(FMT_WINDOWS_NO_WCHAR) inline void vprint_mojibake(std::FILE*, string_view, format_args) {} #endif } // namespace detail diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 553e7ce88d4b8..4c1fca20aead2 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -18,12 +18,12 @@ # include #endif -#ifdef _WIN32 +#include "format.h" + +#if defined(_WIN32) && !defined(FMT_WINDOWS_NO_WCHAR) # include // _isatty #endif -#include "format.h" - FMT_BEGIN_NAMESPACE namespace detail { @@ -1426,7 +1426,7 @@ FMT_FUNC std::string vformat(string_view fmt, format_args args) { } namespace detail { -#ifndef _WIN32 +#if !defined(_WIN32) || defined(FMT_WINDOWS_NO_WCHAR) FMT_FUNC bool write_console(std::FILE*, string_view) { return false; } #else using dword = conditional_t; diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 1c468b4388aa9..4d6198b68d9f8 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -351,7 +351,7 @@ TEST(format_impl_test, write_dragon_even) { if (!FMT_MSC_VERSION) EXPECT_EQ(s, "33554450"); } -#ifdef _WIN32 +#if defined(_WIN32) && !defined(FMT_WINDOWS_NO_WCHAR) # include TEST(format_impl_test, write_console_signature) {