From 6e763d277639fd967aea7756071761920df2c568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Bodor?= Date: Tue, 25 Feb 2020 13:51:43 +0100 Subject: [PATCH 1/2] only include windows.h when it's unavoidable --- include/spdlog/common.h | 12 ------------ include/spdlog/sinks/msvc_sink.h | 9 +++++++++ include/spdlog/sinks/win_eventlog_sink.h | 9 +++++++++ include/spdlog/sinks/wincolor_sink.h | 10 ++++++++++ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index e1108a0a..cb6355cf 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -15,18 +15,6 @@ #include #include -#ifdef _WIN32 -#ifndef NOMINMAX -#define NOMINMAX // prevent windows redefining min/max -#endif - -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#include -#endif //_WIN32 - #ifdef SPDLOG_COMPILED_LIB #undef SPDLOG_HEADER_ONLY #define SPDLOG_INLINE diff --git a/include/spdlog/sinks/msvc_sink.h b/include/spdlog/sinks/msvc_sink.h index 6db10bc9..b3887ac7 100644 --- a/include/spdlog/sinks/msvc_sink.h +++ b/include/spdlog/sinks/msvc_sink.h @@ -8,6 +8,15 @@ #include #include +#ifndef NOMINMAX +#define NOMINMAX // prevent windows redefining min/max +#endif + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include #include #include diff --git a/include/spdlog/sinks/win_eventlog_sink.h b/include/spdlog/sinks/win_eventlog_sink.h index 83835743..e3d4e3a6 100644 --- a/include/spdlog/sinks/win_eventlog_sink.h +++ b/include/spdlog/sinks/win_eventlog_sink.h @@ -30,6 +30,15 @@ Windows Registry Editor Version 5.00 #pragma once +#ifndef NOMINMAX +#define NOMINMAX // prevent windows redefining min/max +#endif + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include #include #include diff --git a/include/spdlog/sinks/wincolor_sink.h b/include/spdlog/sinks/wincolor_sink.h index a051a1df..9feab90d 100644 --- a/include/spdlog/sinks/wincolor_sink.h +++ b/include/spdlog/sinks/wincolor_sink.h @@ -12,6 +12,16 @@ #include #include #include + +#ifndef NOMINMAX +#define NOMINMAX // prevent windows redefining min/max +#endif + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include #include namespace spdlog { From fab33dd2306b929cdbe549ae3a80770add66580b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Bodor?= Date: Wed, 26 Feb 2020 08:54:56 +0100 Subject: [PATCH 2/2] refactor: extract windows.h include to details/windows_include.h --- include/spdlog/details/windows_include.h | 11 +++++++++++ include/spdlog/sinks/msvc_sink.h | 10 +--------- include/spdlog/sinks/win_eventlog_sink.h | 14 +++----------- include/spdlog/sinks/wincolor_sink.h | 10 +--------- 4 files changed, 16 insertions(+), 29 deletions(-) create mode 100644 include/spdlog/details/windows_include.h diff --git a/include/spdlog/details/windows_include.h b/include/spdlog/details/windows_include.h new file mode 100644 index 00000000..6a2f14f9 --- /dev/null +++ b/include/spdlog/details/windows_include.h @@ -0,0 +1,11 @@ +#pragma once + +#ifndef NOMINMAX +#define NOMINMAX // prevent windows redefining min/max +#endif + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include diff --git a/include/spdlog/sinks/msvc_sink.h b/include/spdlog/sinks/msvc_sink.h index b3887ac7..f6c25acb 100644 --- a/include/spdlog/sinks/msvc_sink.h +++ b/include/spdlog/sinks/msvc_sink.h @@ -8,15 +8,7 @@ #include #include -#ifndef NOMINMAX -#define NOMINMAX // prevent windows redefining min/max -#endif - -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#include +#include #include #include diff --git a/include/spdlog/sinks/win_eventlog_sink.h b/include/spdlog/sinks/win_eventlog_sink.h index e3d4e3a6..d9839110 100644 --- a/include/spdlog/sinks/win_eventlog_sink.h +++ b/include/spdlog/sinks/win_eventlog_sink.h @@ -30,20 +30,12 @@ Windows Registry Editor Version 5.00 #pragma once -#ifndef NOMINMAX -#define NOMINMAX // prevent windows redefining min/max -#endif - -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#include -#include - #include #include +#include +#include + #include #include #include diff --git a/include/spdlog/sinks/wincolor_sink.h b/include/spdlog/sinks/wincolor_sink.h index 9feab90d..8ac63d3d 100644 --- a/include/spdlog/sinks/wincolor_sink.h +++ b/include/spdlog/sinks/wincolor_sink.h @@ -13,15 +13,7 @@ #include #include -#ifndef NOMINMAX -#define NOMINMAX // prevent windows redefining min/max -#endif - -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#include +#include #include namespace spdlog {