From b3907a78e1bc7df62f6cca0c6e8c5d46abd0c917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Fri, 16 Dec 2016 14:46:26 +0100 Subject: [PATCH] Added NOMINMAX and WIN32_LEAN_AND_MEAN defines before including windows.h This stops the `windows.h` header from defining `min` and `max` macros and including lot of Windows APIs that are not needed by Catch. --- docs/configuration.md | 9 ++++++++- include/internal/catch_console_colour_impl.hpp | 16 +++++++++++++--- include/internal/catch_platform.h | 14 +++++++++++--- include/internal/catch_timer.hpp | 12 ++++++++++++ 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 33052190..1070f699 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -68,6 +68,13 @@ You may also suppress any of these features by using the `_NO_` form, e.g. `CATC All C++11 support can be disabled with `CATCH_CONFIG_NO_CPP11` +# Windows header clutter + +On Windows Catch includes `windows.h`. To minimize global namespace clutter in the implementation file, it defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including it. You can control this behaviour via two macros: + + CATCH_CONFIG_NO_NOMINMAX // Stops Catch from using NOMINMAX macro + CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN // Stops Catch from using WIN32_LEAN_AND_MEAN macro + --- -[Home](Readme.md) \ No newline at end of file +[Home](Readme.md) diff --git a/include/internal/catch_console_colour_impl.hpp b/include/internal/catch_console_colour_impl.hpp index e3cb9538..686fd710 100644 --- a/include/internal/catch_console_colour_impl.hpp +++ b/include/internal/catch_console_colour_impl.hpp @@ -41,9 +41,12 @@ namespace Catch { #if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// -#ifndef NOMINMAX -#define NOMINMAX -#endif +# ifdef CATCH_DEFINES_NOMINMAX +# define NOMINMAX +# endif +# ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif #ifdef __AFXDLL #include @@ -51,6 +54,13 @@ namespace Catch { #include #endif +# ifdef CATCH_DEFINES_NOMINMAX +# undef NOMINMAX +# endif +# ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# undef WIN32_LEAN_AND_MEAN +# endif + namespace Catch { namespace { diff --git a/include/internal/catch_platform.h b/include/internal/catch_platform.h index 0142dc14..2db972e8 100644 --- a/include/internal/catch_platform.h +++ b/include/internal/catch_platform.h @@ -10,11 +10,19 @@ #define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) -#define CATCH_PLATFORM_MAC +# define CATCH_PLATFORM_MAC #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED) -#define CATCH_PLATFORM_IPHONE +# define CATCH_PLATFORM_IPHONE #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) -#define CATCH_PLATFORM_WINDOWS +# define CATCH_PLATFORM_WINDOWS + +# if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX) +# define CATCH_DEFINES_NOMINMAX +# endif +# if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN) +# define CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# endif + #endif #endif // TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED diff --git a/include/internal/catch_timer.hpp b/include/internal/catch_timer.hpp index 2ba709e3..ee14867f 100644 --- a/include/internal/catch_timer.hpp +++ b/include/internal/catch_timer.hpp @@ -15,7 +15,19 @@ #endif #ifdef CATCH_PLATFORM_WINDOWS +# ifdef CATCH_DEFINES_NOMINMAX +# define NOMINMAX +# endif +# ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif #include +# ifdef CATCH_DEFINES_NOMINMAX +# undef NOMINMAX +# endif +# ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# undef WIN32_LEAN_AND_MEAN +# endif #else #include #endif