From ce59ed0ba23cdbaf730d583564ce03357953b0ff Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Mon, 18 Jun 2018 18:46:49 +0200 Subject: [PATCH] Fix include order and defines for Windows builds --- src/openrct2-dll/openrct2-dll.cpp | 9 +++++---- src/openrct2-ui/UiContext.Win32.cpp | 9 ++++++--- .../drawing/engines/opengl/OpenGLAPI.h | 2 ++ src/openrct2/core/Guard.cpp | 15 +++++++-------- src/openrct2/platform/Platform.Win32.cpp | 5 ++++- src/openrct2/platform/Windows.cpp | 6 +++--- src/openrct2/thirdparty/linenoise.hpp | 2 ++ 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/openrct2-dll/openrct2-dll.cpp b/src/openrct2-dll/openrct2-dll.cpp index d06f9de08d..8d2068a0e6 100644 --- a/src/openrct2-dll/openrct2-dll.cpp +++ b/src/openrct2-dll/openrct2-dll.cpp @@ -7,15 +7,16 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +// Windows.h needs to be included first #define WIN32_LEAN_AND_MEAN +#include +#undef CreateWindow +// Then the rest +#include #include #include -#include -#include -#undef CreateWindow - #include #include #include diff --git a/src/openrct2-ui/UiContext.Win32.cpp b/src/openrct2-ui/UiContext.Win32.cpp index 2e6524bf32..dee114d6e7 100644 --- a/src/openrct2-ui/UiContext.Win32.cpp +++ b/src/openrct2-ui/UiContext.Win32.cpp @@ -15,7 +15,11 @@ #define _WIN32_WINNT 0x0600 #endif // __MINGW32__ -#include +// Windows.h needs to be included first +#include +#undef CreateWindow + +// Then the rest #include #include #include @@ -23,8 +27,7 @@ #include #include "UiContext.h" -#undef interface -#include +#include #include #include #include diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.h b/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.h index 428aec8665..f71aae537c 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.h +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.h @@ -42,6 +42,8 @@ #endif #include +// OpenRCT2: SDL_opengl.h includes windows.h, which defines the CreateWindow macro and causes conflicts +#undef CreateWindow #ifdef OPENGL_NO_LINK diff --git a/src/openrct2/core/Guard.cpp b/src/openrct2/core/Guard.cpp index 71e733d0b3..e047d91d9a 100644 --- a/src/openrct2/core/Guard.cpp +++ b/src/openrct2/core/Guard.cpp @@ -7,25 +7,24 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include -#include -#include -#include - -#include "../common.h" - #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include #endif #include "../Version.h" +#include "../common.h" #include "Console.hpp" #include "Diagnostics.hpp" #include "Guard.hpp" #include "String.hpp" -void openrct2_assert_fwd(bool expression, const char * message, ...) +#include +#include +#include +#include + +void openrct2_assert_fwd(bool expression, const char* message, ...) { va_list va; va_start(va, message); diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index 9c34fbc710..9ed99bff57 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -9,8 +9,11 @@ #ifdef _WIN32 -#include +// Windows.h needs to be included first #include + +// Then the rest +#include #include #include #undef GetEnvironmentVariable diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp index b52a35061e..d3384a783b 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -13,12 +13,12 @@ #define _WIN32_WINNT 0x0600 #endif // __MINGW32__ -#include "../common.h" - #ifdef _WIN32 -#undef interface +// Windows.h needs to be included first #include + +// Then the rest #include #include #include diff --git a/src/openrct2/thirdparty/linenoise.hpp b/src/openrct2/thirdparty/linenoise.hpp index 811a334fed..fb7d28aaae 100644 --- a/src/openrct2/thirdparty/linenoise.hpp +++ b/src/openrct2/thirdparty/linenoise.hpp @@ -131,6 +131,8 @@ #ifndef NOMINMAX #define NOMINMAX #endif +// OpenRCT2: Windows.h defines `interface` too without checking if it exists already, so we we have to undefine it first +#undef interface #include #include #ifndef STDIN_FILENO