From 2f1367aab6c7ea2823a035498ac5d7602c06ac3f Mon Sep 17 00:00:00 2001
From: Ronald Kinard <furyhunter600@gmail.com>
Date: Wed, 28 Jan 2015 02:09:03 -0600
Subject: [PATCH] cmake: Fixes to allow MSVC to compile

running is another story
---
 CMakeLists.txt               |  6 +++---
 cmake/Modules/FindSDL2.cmake | 11 +++++++++++
 src/CMakeLists.txt           |  2 +-
 src/doomdef.h                |  1 +
 src/f_wipe.c                 |  7 +++++--
 src/sdl/CMakeLists.txt       | 13 +++++++++++++
 src/sdl/i_system.c           |  2 +-
 src/sdl/sdlmain.h            |  6 +++++-
 8 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index dc511c7e41..808cdca3e5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
 cmake_minimum_required(VERSION 3.0)
 project(SRB2
-	VERSION 2.1.14)
+	VERSION 2.1.14
+	LANGUAGES C)
 
 # Set up CMAKE path
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
@@ -41,9 +42,8 @@ else()
 	set(SRB2_SYSTEM_BITS 32)
 endif()
 
-# DO NOT ALLOW MSVC!
 if(MSVC)
-	message(FATAL_ERROR "MSVC is not supported!")
+	message(WARNING "!! MSVC BUILDS OF SRB2 CANNOT PLAY MULTIPLAYER !! You're more than welcome to try and fix this!")
 endif()
 
 # OS macros
diff --git a/cmake/Modules/FindSDL2.cmake b/cmake/Modules/FindSDL2.cmake
index faa556a883..7939b7d528 100644
--- a/cmake/Modules/FindSDL2.cmake
+++ b/cmake/Modules/FindSDL2.cmake
@@ -27,8 +27,19 @@ find_library(SDL2_LIBRARY
 		"/usr/local/lib"
 )
 
+find_library(SDL2_MAIN_LIBRARY
+	NAMES SDL2_main
+	PATHS
+		${SDL2_PKGCONF_LIBRARY_DIRS}
+		/usr/lib
+		/usr/local/lib
+)
+
 
 # set include dir variables
 set(SDL2_PROCESS_INCLUDES SDL2_INCLUDE_DIR)
 set(SDL2_PROCESS_LIBS SDL2_LIBRARY)
+set(SDL2_MAIN_PROCESS_INCLUDES SDL2_INCLUDE_DIR)
+set(SDL2_MAIN_PROCESS_LIBS SDL2_MAIN_LIBRARY)
 libfind_process(SDL2)
+libfind_process(SDL2_MAIN)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2772ba8a92..6915071e52 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -354,7 +354,7 @@ endif()
 
 # Compatibility flag with later versions of GCC
 # We should really fix our code to not need this
-if(NOT CLANG)
+if(NOT CLANG AND NOT MSVC)
 	add_compile_options(-mno-ms-bitfields)
 endif()
 
diff --git a/src/doomdef.h b/src/doomdef.h
index d14cd5ddbb..4a6d6e5764 100644
--- a/src/doomdef.h
+++ b/src/doomdef.h
@@ -146,6 +146,7 @@ extern FILE *logstream;
 #define VERSION    201 // Game version
 #define SUBVERSION 14  // more precise version number
 #define VERSIONSTRING "v2.1.14"
+#define VERSIONSTRINGW L"v2.1.14"
 // Hey! If you change this, add 1 to the MODVERSION below!
 // Otherwise we can't force updates!
 #endif
diff --git a/src/f_wipe.c b/src/f_wipe.c
index 69e9562162..69c9808804 100644
--- a/src/f_wipe.c
+++ b/src/f_wipe.c
@@ -210,8 +210,8 @@ static void F_DoWipe(fademask_t *fademask)
 		UINT32 draw_linestogo, draw_rowstogo;
 
 		// rectangle coordinates, etc.
-		UINT16 scrxpos[fademask->width  + 1];
-		UINT16 scrypos[fademask->height + 1];
+		UINT16* scrxpos = (UINT16*)malloc(fademask->width + 1); //[fademask->width  + 1];
+		UINT16* scrypos = (UINT16*)malloc(fademask->height + 1);// [fademask->height + 1];
 		UINT16 maskx, masky;
 		UINT32 relativepos;
 
@@ -263,6 +263,9 @@ static void F_DoWipe(fademask_t *fademask)
 			if (++maskx >= fademask->width)
 				++masky, maskx = 0;
 		} while (++mask < maskend);
+
+		free(scrxpos);
+		free(scrypos);
 	}
 }
 #endif
diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt
index 9996922fdc..9c8b03132f 100644
--- a/src/sdl/CMakeLists.txt
+++ b/src/sdl/CMakeLists.txt
@@ -129,6 +129,19 @@ if(${SDL2_FOUND})
 		)
 	endif()
 
+	if(MSVC)
+		target_link_libraries(${SRB2_SDL2_EXE_NAME} PRIVATE
+			${SDL2_MAIN_LIBRARIES}
+		)
+		target_compile_options(${SRB2_SDL2_EXE_NAME} PRIVATE
+			/Umain
+			/D_CRT_SECURE_NO_WARNINGS # something about string functions.
+			/D_CRT_NONSTDC_NO_DEPRECATE
+			/DSDLMAIN
+			/D_WINSOCK_DEPRECATED_NO_WARNINGS # Don't care
+		)
+	endif()
+
 	target_include_directories(${SRB2_SDL2_EXE_NAME} PRIVATE
 		${SDL2_INCLUDE_DIRS}
 		${SDL2_MIXER_INCLUDE_DIRS}
diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c
index 8675301e82..19b6262b39 100644
--- a/src/sdl/i_system.c
+++ b/src/sdl/i_system.c
@@ -1661,7 +1661,7 @@ void I_UpdateMumble(const mobj_t *mobj, const listener_t listener)
 		return;
 
 	if(mumble->uiVersion != 2) {
-		wcsncpy(mumble->name, L"SRB2 "VERSIONSTRING, 256);
+		wcsncpy(mumble->name, L"SRB2 "VERSIONSTRINGW, 256);
 		wcsncpy(mumble->description, L"Sonic Robo Blast 2 with integrated Mumble Link support.", 2048);
 		mumble->uiVersion = 2;
 	}
diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h
index af4e48f750..7ac32f4b3b 100644
--- a/src/sdl/sdlmain.h
+++ b/src/sdl/sdlmain.h
@@ -25,7 +25,11 @@ extern SDL_bool framebuffer;
 #include "../m_fixed.h"
 
 // SDL2 stub macro
-#define SDL2STUB(name) CONS_Printf("SDL2: stubbed: %s:%d\n", __func__, __LINE__)
+#ifdef _MSC_VER
+#define SDL2STUB() CONS_Printf("SDL2: stubbed: %s:%d\n", __FUNCTION__, __LINE__)
+#else
+#define SDL2STUB() CONS_Printf("SDL2: stubbed: %s:%d\n", __func__, __LINE__)
+#endif
 
 /**	\brief	The JoyInfo_s struct
 
-- 
GitLab