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 1/2] 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 From afe46ff27014d0324c76ca57c03f1a64632c3fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 16 Jan 2017 16:52:44 +0100 Subject: [PATCH 2/2] Extracted NOMINMAX and WIN32_LEAN_AND_MEAN guards into a proxy header --- .../internal/catch_console_colour_impl.hpp | 20 +----------- include/internal/catch_timer.hpp | 14 +------- include/internal/catch_windows_h_proxy.h | 32 +++++++++++++++++++ 3 files changed, 34 insertions(+), 32 deletions(-) create mode 100644 include/internal/catch_windows_h_proxy.h diff --git a/include/internal/catch_console_colour_impl.hpp b/include/internal/catch_console_colour_impl.hpp index 686fd710..ba2a9d1c 100644 --- a/include/internal/catch_console_colour_impl.hpp +++ b/include/internal/catch_console_colour_impl.hpp @@ -41,25 +41,7 @@ namespace Catch { #if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// -# ifdef CATCH_DEFINES_NOMINMAX -# define NOMINMAX -# endif -# ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif - -#ifdef __AFXDLL -#include -#else -#include -#endif - -# ifdef CATCH_DEFINES_NOMINMAX -# undef NOMINMAX -# endif -# ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN -# undef WIN32_LEAN_AND_MEAN -# endif +#include "catch_windows_h_proxy.h" namespace Catch { namespace { diff --git a/include/internal/catch_timer.hpp b/include/internal/catch_timer.hpp index ee14867f..00adfc3b 100644 --- a/include/internal/catch_timer.hpp +++ b/include/internal/catch_timer.hpp @@ -15,19 +15,7 @@ #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 +#include "catch_windows_h_proxy.h" #else #include #endif diff --git a/include/internal/catch_windows_h_proxy.h b/include/internal/catch_windows_h_proxy.h new file mode 100644 index 00000000..4f059b4a --- /dev/null +++ b/include/internal/catch_windows_h_proxy.h @@ -0,0 +1,32 @@ +/* + * Created by Martin on 16/01/2017. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef TWOBLUECUBES_CATCH_WINDOWS_H_PROXY_H_INCLUDED +#define TWOBLUECUBES_CATCH_WINDOWS_H_PROXY_H_INCLUDED + +#ifdef CATCH_DEFINES_NOMINMAX +# define NOMINMAX +#endif +#ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif + +#ifdef __AFXDLL +#include +#else +#include +#endif + +#ifdef CATCH_DEFINES_NOMINMAX +# undef NOMINMAX +#endif +#ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# undef WIN32_LEAN_AND_MEAN +#endif + + +#endif // TWOBLUECUBES_CATCH_WINDOWS_H_PROXY_H_INCLUDED