From d75fd2c7f9320b53b6ba6d47831031c73676fed1 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 26 Jun 2021 19:43:37 +0300 Subject: [PATCH] Fixed wchar support under msvc --- include/spdlog/common.h | 4 ++++ include/spdlog/fmt/xchar.h | 20 ++++++++++++++++++++ include/spdlog/sinks/daily_file_sink.h | 4 ++++ 3 files changed, 28 insertions(+) create mode 100644 include/spdlog/fmt/xchar.h diff --git a/include/spdlog/common.h b/include/spdlog/common.h index f56c38bd..1f289da9 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -35,6 +35,10 @@ #include +#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) +# include +#endif + // visual studio upto 2013 does not support noexcept nor constexpr #if defined(_MSC_VER) && (_MSC_VER < 1900) # define SPDLOG_NOEXCEPT _NOEXCEPT diff --git a/include/spdlog/fmt/xchar.h b/include/spdlog/fmt/xchar.h new file mode 100644 index 00000000..e75f32f2 --- /dev/null +++ b/include/spdlog/fmt/xchar.h @@ -0,0 +1,20 @@ +// +// Copyright(c) 2016 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once +// +// include bundled or external copy of fmtlib's ostream support +// + +#if !defined(SPDLOG_FMT_EXTERNAL) +#ifdef SPDLOG_HEADER_ONLY +#ifndef FMT_HEADER_ONLY +#define FMT_HEADER_ONLY +#endif +#endif +#include +#else +#include +#endif diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index 00b2fb5d..4b9062d5 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -50,7 +50,11 @@ struct daily_filename_format_calculator { // generate fmt datetime format string, e.g. {:%Y-%m-%d}. filename_t fmt_filename = fmt::format(SPDLOG_FILENAME_T("{{:{}}}"), filename); +#if defined(_MSC_VER) && defined(SPDLOG_WCHAR_FILENAMES) // for some reason msvc doesnt allow fmt::runtime(..) with wchar here + return fmt::format(fmt_filename, now_tm); +#else return fmt::format(fmt::runtime(fmt_filename), now_tm); +#endif } };