Skip to content

Commit

Permalink
Add an option to avoid wchar APIs on Windows
Browse files Browse the repository at this point in the history
With this, fmt can be used on Windows 98 and the Original Xbox with:

    set(FMT_OS OFF)
    set(FMT_WINDOWS_NO_WCHAR ON)

Fixes fmtlib#3631
  • Loading branch information
glebm committed Sep 12, 2023
1 parent d498754 commit 033c0b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ option(FMT_TEST "Generate the test target." ${FMT_MASTER_PROJECT})
option(FMT_FUZZ "Generate the fuzz target." OFF)
option(FMT_CUDA_TEST "Generate the cuda-test target." OFF)
option(FMT_OS "Include core requiring OS (Windows/Posix) " ON)
option(FMT_WINDOWS_NO_WCHAR "Do not use wide-char APIs, such as WriteConsoleW, on Windows" OFF)
option(FMT_MODULE "Build a module instead of a traditional library." OFF)
option(FMT_SYSTEM_HEADERS "Expose headers with marking them as system." OFF)

Expand Down Expand Up @@ -290,6 +291,10 @@ if (FMT_MODULE)
enable_module(fmt)
endif ()

if (FMT_WINDOWS_NO_WCHAR)
target_compile_definitions(fmt PUBLIC FMT_WINDOWS_NO_WCHAR)
endif ()

if (FMT_WERROR)
target_compile_options(fmt PRIVATE ${WERROR_FLAG})
endif ()
Expand Down
4 changes: 2 additions & 2 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# include <locale>
#endif

#ifdef _WIN32
#if defined(_WIN32) && !defined(FMT_WINDOWS_NO_WCHAR)
# include <io.h> // _isatty
#endif

Expand Down Expand Up @@ -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<sizeof(long) == 4, unsigned long, unsigned>;
Expand Down

0 comments on commit 033c0b2

Please sign in to comment.