# HG changeset patch
# User TDRR <srb2gamer@gmail.com>
# Date 1672256982 14400
#      Wed Dec 28 15:49:42 2022 -0400
# Node ID 328a5e1159b33ddb1113e8d463b1fbf3dc2a17a3
# Parent  d71e6eb5bec483faef87665903dd65e9283482be
Fix compilation under Cygwin

diff -r d71e6eb5bec4 -r 328a5e1159b3 CMakeLists.txt
--- a/CMakeLists.txt	Fri Dec 16 10:46:24 2022 -0500
+++ b/CMakeLists.txt	Wed Dec 28 15:49:42 2022 -0400
@@ -1,6 +1,8 @@
 cmake_minimum_required( VERSION 2.4 )
 project(Zandronum)
 
+set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
+
 list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} )
 include( CreateLaunchers )
 include( FindPackageHandleStandardArgs )
@@ -159,6 +161,10 @@
 	set( DEB_C_FLAGS "" )
 endif( MSVC )
 
+if( CYGWIN )
+	set( ALL_C_FLAGS "-D_GNU_SOURCE" )
+endif( CYGWIN )
+
 set( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${REL_LINKER_FLAGS}" )
 set( CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} ${REL_LINKER_FLAGS}" )
 set( CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} ${REL_LINKER_FLAGS}" )
diff -r d71e6eb5bec4 -r 328a5e1159b3 output_sdl/CMakeLists.txt
--- a/output_sdl/CMakeLists.txt	Fri Dec 16 10:46:24 2022 -0500
+++ b/output_sdl/CMakeLists.txt	Wed Dec 28 15:49:42 2022 -0400
@@ -1,4 +1,7 @@
 cmake_minimum_required( VERSION 2.4 )
+
+if( NOT NO_SOUND )
+
 add_library( output_sdl MODULE output_sdl.c )
 include_directories( ${FMOD_INCLUDE_DIR} ${SDL_INCLUDE_DIR} )
 
@@ -6,3 +9,5 @@
 add_custom_command( TARGET output_sdl POST_BUILD
 	COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/link-make
 	COMMAND /bin/sh -c ${CMAKE_CURRENT_BINARY_DIR}/link-make )
+
+endif( NOT NO_SOUND )
\ No newline at end of file
diff -r d71e6eb5bec4 -r 328a5e1159b3 rcon_utility/zstrformat.cpp
--- a/rcon_utility/zstrformat.cpp	Fri Dec 16 10:46:24 2022 -0500
+++ b/rcon_utility/zstrformat.cpp	Wed Dec 28 15:49:42 2022 -0400
@@ -13,6 +13,10 @@
 typedef signed __int64 int64_t;
 #endif
 
+#ifdef __CYGWIN__
+#include <alloca.h>
+#endif
+
 // Even though the standard C library has a function to do printf-style formatting in a
 // generic way, there is no standard interface to this function. So if you want to do
 // some printf formatting that doesn't fit in the context of the provided functions,
diff -r d71e6eb5bec4 -r 328a5e1159b3 src/farchive.cpp
--- a/src/farchive.cpp	Fri Dec 16 10:46:24 2022 -0500
+++ b/src/farchive.cpp	Wed Dec 28 15:49:42 2022 -0400
@@ -57,6 +57,10 @@
 #include "m_misc.h"
 #include "dobject.h"
 
+#ifdef __CYGWIN__
+#include <alloca.h>
+#endif
+
 // These are special tokens found in the data stream of an archive.
 // Whenever a new object is encountered, it gets created using new and
 // is then asked to serialize itself before processing of the previous
diff -r d71e6eb5bec4 -r 328a5e1159b3 src/gccinlines.h
--- a/src/gccinlines.h	Fri Dec 16 10:46:24 2022 -0500
+++ b/src/gccinlines.h	Wed Dec 28 15:49:42 2022 -0400
@@ -24,7 +24,9 @@
 
 #include <stdlib.h>
 
-#ifndef alloca
+#ifdef __CYGWIN__
+#include <alloca.h>
+#elif !defined(alloca)
 // MinGW does not seem to come with alloca defined.
 #define alloca __builtin_alloca
 #endif
diff -r d71e6eb5bec4 -r 328a5e1159b3 src/m_png.cpp
--- a/src/m_png.cpp	Fri Dec 16 10:46:24 2022 -0500
+++ b/src/m_png.cpp	Wed Dec 28 15:49:42 2022 -0400
@@ -41,6 +41,10 @@
 #include <malloc.h>		// for alloca()
 #endif
 
+#ifdef __CYGWIN__
+#include <alloca.h>
+#endif
+
 #include "m_crc32.h"
 #include "m_swap.h"
 #include "c_cvars.h"
diff -r d71e6eb5bec4 -r 328a5e1159b3 src/p_glnodes.cpp
--- a/src/p_glnodes.cpp	Fri Dec 16 10:46:24 2022 -0500
+++ b/src/p_glnodes.cpp	Wed Dec 28 15:49:42 2022 -0400
@@ -35,6 +35,10 @@
 #include <malloc.h>		// for alloca()
 #endif
 
+#ifdef __CYGWIN__
+#include <alloca.h>
+#endif
+
 #ifndef _WIN32
 #include <unistd.h>
 
diff -r d71e6eb5bec4 -r 328a5e1159b3 src/p_setup.cpp
--- a/src/p_setup.cpp	Fri Dec 16 10:46:24 2022 -0500
+++ b/src/p_setup.cpp	Wed Dec 28 15:49:42 2022 -0400
@@ -28,6 +28,10 @@
 #include <malloc.h>		// for alloca()
 #endif
 
+#ifdef __CYGWIN__
+#include <alloca.h>
+#endif
+
 // [BB] network.h has to be included before stats.h under Linux.
 // The reason should be investigated.
 #include "network.h"
diff -r d71e6eb5bec4 -r 328a5e1159b3 src/r_things.cpp
--- a/src/r_things.cpp	Fri Dec 16 10:46:24 2022 -0500
+++ b/src/r_things.cpp	Wed Dec 28 15:49:42 2022 -0400
@@ -70,6 +70,10 @@
 #include "network.h"
 #include "gamemode.h"
 
+#ifdef __CYGWIN__
+#include <alloca.h>
+#endif
+
 // [RH] A c-buffer. Used for keeping track of offscreen voxel spans.
 
 struct FCoverageBuffer
diff -r d71e6eb5bec4 -r 328a5e1159b3 src/sdl/i_system.h
--- a/src/sdl/i_system.h	Fri Dec 16 10:46:24 2022 -0500
+++ b/src/sdl/i_system.h	Wed Dec 28 15:49:42 2022 -0400
@@ -152,6 +152,8 @@
 #define FA_DIREC	8
 #define FA_ARCH		16
 
+// [TDRR] Cygwin already provides an implementation, which is functionally identical.
+#ifndef __CYGWIN__
 static inline char *strlwr(char *str)
 {
 	char *ptr = str;
@@ -162,5 +164,6 @@
 	}
 	return str;
 }
+#endif
 
 #endif
diff -r d71e6eb5bec4 -r 328a5e1159b3 src/textures/multipatchtexture.cpp
--- a/src/textures/multipatchtexture.cpp	Fri Dec 16 10:46:24 2022 -0500
+++ b/src/textures/multipatchtexture.cpp	Wed Dec 28 15:49:42 2022 -0400
@@ -51,6 +51,10 @@
 #include "textures/textures.h"
 #include "r_data/colormaps.h"
 
+#ifdef __CYGWIN__
+#include <alloca.h>
+#endif
+
 // On the Alpha, accessing the shorts directly if they aren't aligned on a
 // 4-byte boundary causes unaligned access warnings. Why it does this at
 // all and only while initing the textures is beyond me.
diff -r d71e6eb5bec4 -r 328a5e1159b3 src/textures/warptexture.cpp
--- a/src/textures/warptexture.cpp	Fri Dec 16 10:46:24 2022 -0500
+++ b/src/textures/warptexture.cpp	Wed Dec 28 15:49:42 2022 -0400
@@ -39,6 +39,10 @@
 #include "r_utility.h"
 #include "textures/textures.h"
 
+#ifdef __CYGWIN__
+#include <alloca.h>
+#endif
+
 
 FWarpTexture::FWarpTexture (FTexture *source)
 : GenTime (0), SourcePic (source), Pixels (0), Spans (0), Speed (1.f)
