Buildsystem: Add support for compiling with MinGW on Windows

Tested with:
- Windows 8 x64
- MySQL 5.5.30 win32
- OpenSSL 1.0.1c (32 bits)
- No PCH
- MinGW with GCC 4.7.0

TODO:
- Fix compile/link with PCH enabled
- Fix compile with WheatyExceptonionReport enabled (ignored for now)
- Fix compile of .rc files (ignored for now)
- Test with more platforms
This commit is contained in:
Nay
2013-03-09 00:12:50 +00:00
parent 2dbe3d6cfe
commit c7463c5f6c
19 changed files with 274 additions and 34 deletions

View File

@@ -0,0 +1,27 @@
# set up output paths for executable binaries (.exe-files, and .dll-files on DLL-capable platforms)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Set build-directive (used in core to tell which buildtype we used)
add_definitions(-D_BUILD_DIRECTIVE=\\"${CMAKE_BUILD_TYPE}\\")
if(PLATFORM EQUAL 32)
# Required on 32-bit systems to enable SSE2 (standard on x64)
set(SSE_FLAGS "-msse2 -mfpmath=sse")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SSE_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS}")
endif()
add_definitions(-DHAVE_SSE2 -D__SSE2__)
message(STATUS "GCC: SFMT enabled, SSE2 flags forced")
if( WITH_WARNINGS )
set(WARNING_FLAGS "-W -Wall -Wextra -Winit-self -Winvalid-pch -Wfatal-errors")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} -Woverloaded-virtual")
message(STATUS "GCC: All warnings enabled")
endif()
if( WITH_COREDEBUG )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
message(STATUS "GCC: Debug-flags set (-g3)")
endif()

View File

@@ -25,4 +25,8 @@ endif()
# endif()
#endif()
include(${CMAKE_SOURCE_DIR}/cmake/compiler/msvc/settings.cmake)
if ( MSVC )
include(${CMAKE_SOURCE_DIR}/cmake/compiler/msvc/settings.cmake)
elseif ( MINGW )
include(${CMAKE_SOURCE_DIR}/cmake/compiler/mingw/settings.cmake)
endif()

31
cmake/stack_direction.c Normal file
View File

@@ -0,0 +1,31 @@
/* Copyright (C) 2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/* Check stack direction (0-down, 1-up) */
int f(int *a)
{
int b;
return(&b > a)?1:0;
}
/*
Prevent compiler optimizations by calling function
through pointer.
*/
volatile int (*ptr_f)(int *) = f;
int main()
{
int a;
return ptr_f(&a);
}

View File

@@ -0,0 +1,15 @@
diff --git a/dep/acelite/ace/CMakeLists.txt b/dep/acelite/ace/CMakeLists.txt
index eb0f6dd..1f9ffa6 100644
--- a/dep/acelite/ace/CMakeLists.txt
+++ b/dep/acelite/ace/CMakeLists.txt
@@ -341,6 +341,10 @@ add_library(ace SHARED
${ace_PCH_SRC}
)
+if (MINGW) # GCC ignores "#prama comment"
+ target_link_libraries(ace ws2_32 iphlpapi netapi32 mswsock)
+endif()
+
# Generate precompiled header
if( USE_COREPCH )
add_cxx_pch(ace ${ace_PCH_HDR} ${ace_PCH_SRC})

View File

@@ -341,6 +341,10 @@ add_library(ace SHARED
${ace_PCH_SRC}
)
if (MINGW) # GCC ignores "#prama comment"
target_link_libraries(ace ws2_32 iphlpapi netapi32 mswsock)
endif()
# Generate precompiled header
if( USE_COREPCH )
add_cxx_pch(ace ${ace_PCH_HDR} ${ace_PCH_SRC})

View File

@@ -0,0 +1,103 @@
diff --git a/dep/g3dlite/include/G3D/platform.h b/dep/g3dlite/include/G3D/platform.h
index 614c0ed..65616f0 100644
--- a/dep/g3dlite/include/G3D/platform.h
+++ b/dep/g3dlite/include/G3D/platform.h
@@ -51,6 +51,11 @@
#ifdef _MSC_VER
#define G3D_WIN32
+#elif defined(__MINGW32__)
+ #define G3D_WIN32
+ #undef __MSVCRT_VERSION__
+ #define __MSVCRT_VERSION__ 0x0601
+ #include <windows.h>
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
#define G3D_FREEBSD
#define G3D_LINUX
diff --git a/dep/g3dlite/source/FileSystem.cpp b/dep/g3dlite/source/FileSystem.cpp
index 76a3611..f082937 100644
--- a/dep/g3dlite/source/FileSystem.cpp
+++ b/dep/g3dlite/source/FileSystem.cpp
@@ -25,8 +25,11 @@
// Needed for _findfirst
# include <io.h>
-
-#define stat64 _stat64
+# ifdef __MINGW32__
+# define stat64 stat
+# else
+# define stat64 _stat64
+# endif
#else
# include <dirent.h>
# include <fnmatch.h>
diff --git a/dep/g3dlite/source/RegistryUtil.cpp b/dep/g3dlite/source/RegistryUtil.cpp
index fc4cebc..7c9e56f 100644
--- a/dep/g3dlite/source/RegistryUtil.cpp
+++ b/dep/g3dlite/source/RegistryUtil.cpp
@@ -16,6 +16,15 @@
#include "G3D/RegistryUtil.h"
#include "G3D/System.h"
+#ifdef __MINGW32__
+# ifndef HKEY_PERFORMANCE_TEXT
+# define HKEY_PERFORMANCE_TEXT ((HKEY)((LONG)0x80000050))
+# endif
+# ifndef HKEY_PERFORMANCE_NLSTEXT
+# define HKEY_PERFORMANCE_NLSTEXT ((HKEY)((LONG)0x80000060))
+# endif
+#endif
+
namespace G3D {
// static helpers
diff --git a/dep/g3dlite/source/System.cpp b/dep/g3dlite/source/System.cpp
index f6b0e03..281104d 100644
--- a/dep/g3dlite/source/System.cpp
+++ b/dep/g3dlite/source/System.cpp
@@ -564,7 +564,7 @@ void System::getStandardProcessorExtensions() {
#endif
}
-#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
+#if defined(G3D_WIN32) && !defined(G3D_64BIT) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit Windows platforms or using MinGW */
#pragma message("Port System::memcpy SIMD to all platforms")
/** Michael Herf's fast memcpy */
void memcpyMMX(void* dst, const void* src, int nbytes) {
@@ -615,7 +615,7 @@ void memcpyMMX(void* dst, const void* src, int nbytes) {
#endif
void System::memcpy(void* dst, const void* src, size_t numBytes) {
-#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
+#if defined(G3D_WIN32) && !defined(G3D_64BIT) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit Windows platforms or using MinGW */
memcpyMMX(dst, src, numBytes);
#else
::memcpy(dst, src, numBytes);
@@ -625,7 +625,7 @@ void System::memcpy(void* dst, const void* src, size_t numBytes) {
/** Michael Herf's fastest memset. n32 must be filled with the same
character repeated. */
-#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
+#if defined(G3D_WIN32) && !defined(G3D_64BIT) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit Windows platforms or using MinGW */
#pragma message("Port System::memfill SIMD to all platforms")
// On x86 processors, use MMX
@@ -664,7 +664,7 @@ void memfill(void *dst, int n32, unsigned long i) {
void System::memset(void* dst, uint8 value, size_t numBytes) {
-#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
+#if defined(G3D_WIN32) && !defined(G3D_64BIT) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit Windows platforms or using MinGW */
uint32 v = value;
v = v + (v << 8) + (v << 16) + (v << 24);
G3D::memfill(dst, v, numBytes);
@@ -1696,7 +1696,7 @@ std::string System::currentDateString() {
// VC on Intel
void System::cpuid(CPUIDFunction func, uint32& areg, uint32& breg, uint32& creg, uint32& dreg) {
-#if !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit platform */
+#if !defined(G3D_64BIT) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit platforms or using MinGW */
// Can't copy from assembler direct to a function argument (which is on the stack) in VC.
uint32 a,b,c,d;

View File

@@ -51,6 +51,11 @@
#ifdef _MSC_VER
#define G3D_WIN32
#elif defined(__MINGW32__)
#define G3D_WIN32
#undef __MSVCRT_VERSION__
#define __MSVCRT_VERSION__ 0x0601
#include <windows.h>
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
#define G3D_FREEBSD
#define G3D_LINUX

View File

@@ -25,8 +25,11 @@
// Needed for _findfirst
# include <io.h>
#define stat64 _stat64
# ifdef __MINGW32__
# define stat64 stat
# else
# define stat64 _stat64
# endif
#else
# include <dirent.h>
# include <fnmatch.h>

View File

@@ -16,6 +16,15 @@
#include "G3D/RegistryUtil.h"
#include "G3D/System.h"
#ifdef __MINGW32__
# ifndef HKEY_PERFORMANCE_TEXT
# define HKEY_PERFORMANCE_TEXT ((HKEY)((LONG)0x80000050))
# endif
# ifndef HKEY_PERFORMANCE_NLSTEXT
# define HKEY_PERFORMANCE_NLSTEXT ((HKEY)((LONG)0x80000060))
# endif
#endif
namespace G3D {
// static helpers

View File

@@ -564,7 +564,7 @@ void System::getStandardProcessorExtensions() {
#endif
}
#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
#if defined(G3D_WIN32) && !defined(G3D_64BIT) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit Windows platforms or using MinGW */
#pragma message("Port System::memcpy SIMD to all platforms")
/** Michael Herf's fast memcpy */
void memcpyMMX(void* dst, const void* src, int nbytes) {
@@ -615,7 +615,7 @@ void memcpyMMX(void* dst, const void* src, int nbytes) {
#endif
void System::memcpy(void* dst, const void* src, size_t numBytes) {
#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
#if defined(G3D_WIN32) && !defined(G3D_64BIT) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit Windows platforms or using MinGW */
memcpyMMX(dst, src, numBytes);
#else
::memcpy(dst, src, numBytes);
@@ -625,7 +625,7 @@ void System::memcpy(void* dst, const void* src, size_t numBytes) {
/** Michael Herf's fastest memset. n32 must be filled with the same
character repeated. */
#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
#if defined(G3D_WIN32) && !defined(G3D_64BIT) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit Windows platforms or using MinGW */
#pragma message("Port System::memfill SIMD to all platforms")
// On x86 processors, use MMX
@@ -664,7 +664,7 @@ void memfill(void *dst, int n32, unsigned long i) {
void System::memset(void* dst, uint8 value, size_t numBytes) {
#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
#if defined(G3D_WIN32) && !defined(G3D_64BIT) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit Windows platforms or using MinGW */
uint32 v = value;
v = v + (v << 8) + (v << 16) + (v << 24);
G3D::memfill(dst, v, numBytes);
@@ -1696,7 +1696,7 @@ std::string System::currentDateString() {
// VC on Intel
void System::cpuid(CPUIDFunction func, uint32& areg, uint32& breg, uint32& creg, uint32& dreg) {
#if !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit platform */
#if !defined(G3D_64BIT) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit platforms or using MinGW */
// Can't copy from assembler direct to a function argument (which is on the stack) in VC.
uint32 a,b,c,d;

View File

@@ -21,7 +21,7 @@
#include "DetourAlloc.h"
#ifdef WIN32
#if defined(WIN32) && not defined(__MINGW32__)
typedef unsigned __int64 uint64;
#else
#include <stdint.h>

View File

@@ -0,0 +1,13 @@
diff --git a/dep/recastnavigation/Detour/DetourNavMesh.h b/dep/recastnavigation/Detour/DetourNavMesh.h
index 52d2c50..99e30c7 100644
--- a/dep/recastnavigation/Detour/DetourNavMesh.h
+++ b/dep/recastnavigation/Detour/DetourNavMesh.h
@@ -21,7 +21,7 @@
#include "DetourAlloc.h"
-#ifdef WIN32
+#if defined(WIN32) && not defined(__MINGW32__)
typedef unsigned __int64 uint64;
#else
#include <stdint.h>

View File

@@ -12,7 +12,7 @@
# This to stop a few silly crashes that could have been avoided IF people
# weren't doing some -O3 psychooptimizations etc.
if(CMAKE_COMPILER_IS_GNUCXX)
if(CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
add_definitions(-fno-delete-null-pointer-checks)
endif()

View File

@@ -29,11 +29,18 @@ set(authserver_SRCS
)
if( WIN32 )
set(authserver_SRCS
${authserver_SRCS}
${sources_Debugging}
if ( MSVC )
set(authserver_SRCS
${authserver_SRCS}
${sources_Debugging}
authserver.rc
)
)
else ( )
set(authserver_SRCS
${authserver_SRCS}
${sources_Debugging}
)
endif ()
endif()
include_directories(
@@ -76,10 +83,17 @@ target_link_libraries(authserver
)
if( WIN32 )
add_custom_command(TARGET authserver
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/authserver.conf.dist ${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/
)
if ( MSVC )
add_custom_command(TARGET authserver
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/authserver.conf.dist ${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/
)
elseif ( MINGW )
add_custom_command(TARGET authserver
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/authserver.conf.dist ${CMAKE_BINARY_DIR}/bin/
)
endif()
endif()
if( UNIX )

View File

@@ -18,12 +18,10 @@
#include "BoundingIntervalHierarchy.h"
#if defined __APPLE__
#define isnan std::isnan
#elif defined __CYGWIN__
#define isnan std::isnan
#elif defined _MSC_VER
#ifdef _MSC_VER
#define isnan _isnan
#else
#define isnan std::isnan
#endif
void BIH::buildHierarchy(std::vector<uint32> &tempTree, buildData &dat, BuildStats &stats)

View File

@@ -3,7 +3,7 @@
// MSDN Magazine, 2002
// FILE: WheatyExceptionReport.CPP
//==========================================
#if PLATFORM == PLATFORM_WINDOWS
#if PLATFORM == PLATFORM_WINDOWS && not defined(__MINGW32__)
#define WIN32_LEAN_AND_MEAN
#pragma warning(disable:4996)
#pragma warning(disable:4312)

View File

@@ -1,7 +1,7 @@
#ifndef _WHEATYEXCEPTIONREPORT_
#define _WHEATYEXCEPTIONREPORT_
#if PLATFORM == PLATFORM_WINDOWS
#if PLATFORM == PLATFORM_WINDOWS && not defined(__MINGW32__)
#include <dbghelp.h>

View File

@@ -29,11 +29,18 @@ set(worldserver_SRCS
)
if( WIN32 )
set(worldserver_SRCS
${worldserver_SRCS}
${sources_Debugging}
worldserver.rc
)
if ( MSVC )
set(worldserver_SRCS
${worldserver_SRCS}
${sources_Debugging}
worldserver.rc
)
else ( )
set(worldserver_SRCS
${worldserver_SRCS}
${sources_Debugging}
)
endif ()
endif()
include_directories(
@@ -175,10 +182,17 @@ target_link_libraries(worldserver
)
if( WIN32 )
add_custom_command(TARGET worldserver
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/worldserver.conf.dist ${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/
)
if ( MSVC )
add_custom_command(TARGET worldserver
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/worldserver.conf.dist ${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/
)
elseif ( MINGW )
add_custom_command(TARGET worldserver
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/worldserver.conf.dist ${CMAKE_BINARY_DIR}/bin/
)
endif()
endif()
if( UNIX )