CMake seems to now allow building with MinGW32 default
authorHarley Laue <losinggeneration@gmail.com>
Tue, 23 Aug 2011 16:29:20 -0500
changeset 156 8838068e622f
parent 154 5af05659e8c5
CMake seems to now allow building with MinGW32

* I've only tested cross compiling, but all seems to work. I couldn't
test the tutorials with sound because Wine crashes.
.hgignore
CMakeLists.txt
src/core/CMakeLists.txt
src/core/windows/BASS/bass.h
src/core/windows/hge_impl.h
src/core/windows/input.cpp
src/core/windows/resource.cpp
src/core/windows/system.cpp
src/fonted/commands.cpp
src/fonted/fontlist.cpp
--- a/.hgignore	Mon Aug 22 16:02:21 2011 -0500
+++ b/.hgignore	Tue Aug 23 16:29:20 2011 -0500
@@ -3,4 +3,5 @@
 *~
 .*swp
 build
-*kdev4*
\ No newline at end of file
+mingw32-build
+*kdev4*
--- a/CMakeLists.txt	Mon Aug 22 16:02:21 2011 -0500
+++ b/CMakeLists.txt	Tue Aug 23 16:29:20 2011 -0500
@@ -58,12 +58,44 @@
 		${JPEG_LIBRARY}
 		${PNG_LIBRARY}
 	)
+
+	set(USE_SHARED SHARED)
+elseif(WIN32)
+	# Windows
+	add_definitions(-D_WINDOWS -D_WIN32)
+	set(USE_INTERNAL_ZLIB ON)
+
+	set(HGE_LIBRARIES
+		d3d8
+		winmm
+	)
+
+	if(MSVC AND NOT (CMAKE_BUILD_TYPE MATCHES Debug))
+		set(HGE_LIBRARIES ${HGE_LIBRARIES}
+			d3dx8
+		)
+	else()
+		#Sorry MinGW32, you're not currently allowed to make a "release"
+		add_definitions(-DDEBUG)
+		set(HGE_LIBRARIES ${HGE_LIBRARIES}
+			d3dx8d
+		)
+	endif()
+
+	set(USE_SHARED SHARED)
+else()
+	message(FATAL_ERROR "Unknown platform")
 endif(UNIX OR APPLE)
 
-# This is the HGE library and required libraries to link against
-set(HGE_LIBRARY hge ${HGE_LIBRARIES})
-# And this is the HGE & Helper library and required libraries to link against
-set(HGE_HELPER_LIBRARY hge_helpers ${HGE_LIBRARY})
+if(WIN32)
+	set(HGE_LIBRARY hge ${HGE_LIBRARIES})
+	set(HGE_HELPER_LIBRARY hge ${HGE_LIBRARIES})
+else()
+	# This is the HGE library and required libraries to link against
+	set(HGE_LIBRARY hge ${HGE_LIBRARIES})
+	# And this is the HGE & Helper library and required libraries to link against
+	set(HGE_HELPER_LIBRARY hge_helpers ${HGE_LIBRARY})
+endif()
 
 # Where HGE is located, this also builds the helper library
 add_subdirectory(src/core)
--- a/src/core/CMakeLists.txt	Mon Aug 22 16:02:21 2011 -0500
+++ b/src/core/CMakeLists.txt	Tue Aug 23 16:29:20 2011 -0500
@@ -96,7 +96,7 @@
 	endif(APPLE)
 else(UNIX OR APPLE)
 	# Win32, though it's probably broken to build
-	include_directories(windows)
+	include_directories(windows unix)
 	set(HGE_SRCS
 		${HGE_SRCS}
 		windows/graphics.cpp
@@ -109,9 +109,6 @@
 	)
 endif(UNIX OR APPLE)
 
-add_library(hge SHARED ${HGE_SRCS})
-target_link_libraries(hge ${HGE_LIBRARIES})
-
 set(HS ${CMAKE_SOURCE_DIR}/src/helpers)
 set(HGE_HELPER_SRCS
 	${HS}/hgeanim.cpp
@@ -131,5 +128,13 @@
 	${HS}/resources.cpp
 )
 
-add_library(hge_helpers SHARED ${HGE_HELPER_SRCS})
-target_link_libraries(hge_helpers hge ${HGE_LIBRARIES})
+if(WIN32)
+	add_library(hge ${USE_SHARED} ${HGE_SRCS} ${HGE_HELPER_SRCS})
+	target_link_libraries(hge ${HGE_LIBRARIES})
+else()
+	add_library(hge ${USE_SHARED} ${HGE_SRCS})
+	target_link_libraries(hge ${HGE_LIBRARIES})
+
+	add_library(hge_helpers ${USE_SHARED} ${HGE_HELPER_SRCS})
+	target_link_libraries(hge_helpers hge ${HGE_LIBRARIES})
+endif()
--- a/src/core/windows/BASS/bass.h	Mon Aug 22 16:02:21 2011 -0500
+++ b/src/core/windows/BASS/bass.h	Tue Aug 23 16:29:20 2011 -0500
@@ -36,15 +36,15 @@
 #define BASSDEF(f) WINAPI f
 #endif
 
-typedef DWORD HMUSIC;		// MOD music handle
-typedef DWORD HSAMPLE;		// sample handle
-typedef DWORD HCHANNEL;		// playing sample's channel handle
-typedef DWORD HSTREAM;		// sample stream handle
-typedef DWORD HRECORD;		// recording handle
-typedef DWORD HSYNC;		// synchronizer handle
-typedef DWORD HDSP;			// DSP handle
-typedef DWORD HFX;			// DX8 effect handle
-typedef DWORD HPLUGIN;		// Plugin handle
+typedef size_t HMUSIC;		// MOD music handle
+typedef size_t HSAMPLE;		// sample handle
+typedef size_t HCHANNEL;		// playing sample's channel handle
+typedef size_t HSTREAM;		// sample stream handle
+typedef size_t HRECORD;		// recording handle
+typedef size_t HSYNC;		// synchronizer handle
+typedef size_t HDSP;			// DSP handle
+typedef size_t HFX;			// DX8 effect handle
+typedef size_t HPLUGIN;		// Plugin handle
 
 // Error codes returned by BASS_ErrorGetCode
 #define BASS_OK				0	// all is OK
--- a/src/core/windows/hge_impl.h	Mon Aug 22 16:02:21 2011 -0500
+++ b/src/core/windows/hge_impl.h	Tue Aug 23 16:29:20 2011 -0500
@@ -167,7 +167,7 @@
 	virtual bool		CALL	Input_KeyDown(int key);
 	virtual bool		CALL	Input_KeyUp(int key);
 	virtual bool		CALL	Input_GetKeyState(int key);
-	virtual char*		CALL	Input_GetKeyName(int key);
+	virtual const char*	CALL	Input_GetKeyName(int key);
 	virtual int			CALL	Input_GetKey();
 	virtual int			CALL	Input_GetChar();
 	virtual bool		CALL	Input_GetEvent(hgeInputEvent *event);
@@ -199,7 +199,7 @@
 
 	static HGE_Impl*	_Interface_Get();
 	void				_FocusChange(bool bAct);
-	void				_PostError(char *error);
+	void				_PostError(const char *error);
 
 
 	HINSTANCE			hInstance;
--- a/src/core/windows/input.cpp	Mon Aug 22 16:02:21 2011 -0500
+++ b/src/core/windows/input.cpp	Tue Aug 23 16:29:20 2011 -0500
@@ -10,7 +10,7 @@
 #include "hge_impl.h"
 
 
-char *KeyNames[] =
+const char *KeyNames[] =
 {
  "?",
  "Left Mouse Button", "Right Mouse Button", "?", "Middle Mouse Button",
@@ -60,7 +60,7 @@
 		delete eptr;
 		return true;
 	}
-	
+
 	return false;
 }
 
@@ -103,7 +103,7 @@
 	return (keyz[key] & 2) != 0;
 }
 
-char* CALL HGE_Impl::Input_GetKeyName(int key)
+const char* CALL HGE_Impl::Input_GetKeyName(int key)
 {
 	return KeyNames[key];
 }
@@ -190,7 +190,7 @@
 		pt.x=(int)Xpos; pt.y=(int)Ypos;
 		bCaptured=false;
 	}
-	
+
 	if(kbstate[VK_SHIFT] & 0x80) flags|=HGEINP_SHIFT;
 	if(kbstate[VK_CONTROL] & 0x80) flags|=HGEINP_CTRL;
 	if(kbstate[VK_MENU] & 0x80) flags|=HGEINP_ALT;
@@ -211,7 +211,7 @@
 		eptr->event.y=(float)pt.y;
 	}
 
-	eptr->next=0; 
+	eptr->next=0;
 
 	if(!queue) queue=eptr;
 	else
@@ -240,7 +240,7 @@
 	CInputEventList *nexteptr, *eptr=queue;
 
 	memset(&keyz, 0, sizeof(keyz));
-	
+
 	while(eptr)
 	{
 		nexteptr=eptr->next;
--- a/src/core/windows/resource.cpp	Mon Aug 22 16:02:21 2011 -0500
+++ b/src/core/windows/resource.cpp	Tue Aug 23 16:29:20 2011 -0500
@@ -6,14 +6,12 @@
 ** Core functions implementation: resources management
 */
 
-
+#define NOCRYPT
+// #define NOUNCRYPT
+#include "ZLIB/unzip.h"
+#undef DWORD
 #include "hge_impl.h"
 
-#define NOCRYPT
-//#define NOUNCRYPT
-#include "ZLIB/unzip.h"
-
-
 bool CALL HGE_Impl::Resource_AttachPack(const char *filename, const char *password)
 {
 	char *szName;
@@ -28,7 +26,7 @@
 		if(!strcmp(szName,resItem->filename)) return false;
 		resItem=resItem->next;
 	}
-	
+
 	zip=unzOpen(szName);
 	if(!zip) return false;
 	unzClose(zip);
@@ -82,7 +80,7 @@
 
 void* CALL HGE_Impl::Resource_Load(const char *filename, DWORD *size)
 {
-	static char *res_err="Can't load resource: %s";
+	const char *res_err="Can't load resource: %s";
 
 	CResourceList *resItem=res;
 	char szName[_MAX_PATH];
@@ -96,7 +94,7 @@
 	if(filename[0]=='\\' || filename[0]=='/' || filename[1]==':') goto _fromfile; // skip absolute paths
 
 	// Load from pack
- 
+
 	strcpy(szName,filename);
 	strupr(szName);
 	for(i=0; szName[i]; i++) { if(szName[i]=='/') szName[i]='\\'; }
@@ -144,10 +142,10 @@
 				if(size) *size=file_info.uncompressed_size;
 				return ptr;
 			}
-			
+
 			done=unzGoToNextFile(zip);
 		}
-		
+
 		unzClose(zip);
 		resItem=resItem->next;
 	}
@@ -171,7 +169,7 @@
 		_PostError(szName);
 		return 0;
 	}
-	if(ReadFile(hF, ptr, file_info.uncompressed_size, &file_info.uncompressed_size, NULL ) == 0)
+	if(ReadFile(hF, ptr, file_info.uncompressed_size, (DWORD *)&file_info.uncompressed_size, NULL ) == 0)
 	{
 		CloseHandle(hF);
 		free(ptr);
@@ -179,7 +177,7 @@
 		_PostError(szName);
 		return 0;
 	}
-	
+
 	CloseHandle(hF);
 	if(size) *size=file_info.uncompressed_size;
 	return ptr;
--- a/src/core/windows/system.cpp	Mon Aug 22 16:02:21 2011 -0500
+++ b/src/core/windows/system.cpp	Tue Aug 23 16:29:20 2011 -0500
@@ -641,7 +641,7 @@
 	if(pD3DDevice)
 	{
 		pD3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pSurf);
-		D3DXSaveSurfaceToFile(filename, D3DXIFF_BMP, pSurf, NULL, NULL);
+// 		D3DXSaveSurfaceToFile(filename, D3DXIFF_BMP, pSurf, NULL, NULL);
 		pSurf->Release();
 	}
 }
--- a/src/fonted/commands.cpp	Mon Aug 22 16:02:21 2011 -0500
+++ b/src/fonted/commands.cpp	Tue Aug 23 16:29:20 2011 -0500
@@ -8,6 +8,7 @@
 
 
 #include "fonted.h"
+#include <cstdio>
 #include <string>
 
 #ifndef PLATFORM_UNIX
--- a/src/fonted/fontlist.cpp	Mon Aug 22 16:02:21 2011 -0500
+++ b/src/fonted/fontlist.cpp	Tue Aug 23 16:29:20 2011 -0500
@@ -9,6 +9,10 @@
 #include "fontlist.h"
 #include "unix_compat.h"
 
+#ifdef _WINDOWS
+#include <wingdi.h>
+#endif
+
 CFontList::CFontList()
 {
 	nFonts=0;