Created
March 2, 2013 02:30
-
-
Save DDuarte/5069437 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 850f5dce38c6644cf15047a0a898b1ddced330df Mon Sep 17 00:00:00 2001 | |
| From: Nay <dnpd.dd@gmail.com> | |
| Date: Sat, 2 Mar 2013 02:16:56 +0000 | |
| Subject: [PATCH] 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 | |
| --- | |
| cmake/compiler/mingw/settings.cmake | 27 ++++++++++++++++++ | |
| cmake/platform/win/settings.cmake | 6 +++- | |
| cmake/stack_direction.c | 31 +++++++++++++++++++++ | |
| dep/acelite/ace/CMakeLists.txt | 4 +++ | |
| dep/g3dlite/include/G3D/RegistryUtil.h | 2 +- | |
| dep/g3dlite/include/G3D/platform.h | 5 ++++ | |
| dep/g3dlite/source/FileSystem.cpp | 7 +++-- | |
| dep/g3dlite/source/RegistryUtil.cpp | 11 +++++++- | |
| dep/g3dlite/source/System.cpp | 10 +++---- | |
| dep/recastnavigation/Detour/DetourNavMesh.h | 2 +- | |
| src/server/CMakeLists.txt | 2 +- | |
| src/server/authserver/CMakeLists.txt | 30 ++++++++++++++------ | |
| src/server/collision/BoundingIntervalHierarchy.cpp | 8 ++---- | |
| .../shared/Debugging/WheatyExceptionReport.cpp | 2 +- | |
| .../shared/Debugging/WheatyExceptionReport.h | 2 +- | |
| src/server/worldserver/CMakeLists.txt | 32 ++++++++++++++++------ | |
| 16 files changed, 145 insertions(+), 36 deletions(-) | |
| create mode 100644 cmake/compiler/mingw/settings.cmake | |
| create mode 100644 cmake/stack_direction.c | |
| diff --git a/cmake/compiler/mingw/settings.cmake b/cmake/compiler/mingw/settings.cmake | |
| new file mode 100644 | |
| index 0000000..68156bd | |
| --- /dev/null | |
| +++ b/cmake/compiler/mingw/settings.cmake | |
| @@ -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() | |
| diff --git a/cmake/platform/win/settings.cmake b/cmake/platform/win/settings.cmake | |
| index b66eb2d..c0f7249 100644 | |
| --- a/cmake/platform/win/settings.cmake | |
| +++ b/cmake/platform/win/settings.cmake | |
| @@ -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() | |
| diff --git a/cmake/stack_direction.c b/cmake/stack_direction.c | |
| new file mode 100644 | |
| index 0000000..11bcf80 | |
| --- /dev/null | |
| +++ b/cmake/stack_direction.c | |
| @@ -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); | |
| +} | |
| \ No newline at end of file | |
| 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}) | |
| diff --git a/dep/g3dlite/include/G3D/RegistryUtil.h b/dep/g3dlite/include/G3D/RegistryUtil.h | |
| index 4b47be5..c836987 100644 | |
| --- a/dep/g3dlite/include/G3D/RegistryUtil.h | |
| +++ b/dep/g3dlite/include/G3D/RegistryUtil.h | |
| @@ -15,7 +15,7 @@ | |
| #include "G3D/g3dmath.h" | |
| // This file is only used on Windows | |
| -#ifdef G3D_WIN32 | |
| +#if defined(G3D_WIN32) | |
| #include <string> | |
| 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..ddb0b01 100644 | |
| --- a/dep/g3dlite/source/RegistryUtil.cpp | |
| +++ b/dep/g3dlite/source/RegistryUtil.cpp | |
| @@ -11,11 +11,20 @@ | |
| #include "G3D/platform.h" | |
| // This file is only used on Windows | |
| -#ifdef G3D_WIN32 | |
| +#if defined(G3D_WIN32) | |
| #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; | |
| 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> | |
| diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt | |
| index e8816ea..02fca56 100644 | |
| --- a/src/server/CMakeLists.txt | |
| +++ b/src/server/CMakeLists.txt | |
| @@ -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() | |
| diff --git a/src/server/authserver/CMakeLists.txt b/src/server/authserver/CMakeLists.txt | |
| index 328369c..f7c4b9c 100644 | |
| --- a/src/server/authserver/CMakeLists.txt | |
| +++ b/src/server/authserver/CMakeLists.txt | |
| @@ -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 ) | |
| diff --git a/src/server/collision/BoundingIntervalHierarchy.cpp b/src/server/collision/BoundingIntervalHierarchy.cpp | |
| index 4c1f449..340d66d 100644 | |
| --- a/src/server/collision/BoundingIntervalHierarchy.cpp | |
| +++ b/src/server/collision/BoundingIntervalHierarchy.cpp | |
| @@ -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) | |
| diff --git a/src/server/shared/Debugging/WheatyExceptionReport.cpp b/src/server/shared/Debugging/WheatyExceptionReport.cpp | |
| index ea9ab09..19db228 100644 | |
| --- a/src/server/shared/Debugging/WheatyExceptionReport.cpp | |
| +++ b/src/server/shared/Debugging/WheatyExceptionReport.cpp | |
| @@ -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) | |
| diff --git a/src/server/shared/Debugging/WheatyExceptionReport.h b/src/server/shared/Debugging/WheatyExceptionReport.h | |
| index 8ade80c..684b10e 100644 | |
| --- a/src/server/shared/Debugging/WheatyExceptionReport.h | |
| +++ b/src/server/shared/Debugging/WheatyExceptionReport.h | |
| @@ -1,7 +1,7 @@ | |
| #ifndef _WHEATYEXCEPTIONREPORT_ | |
| #define _WHEATYEXCEPTIONREPORT_ | |
| -#if PLATFORM == PLATFORM_WINDOWS | |
| +#if PLATFORM == PLATFORM_WINDOWS && not defined(__MINGW32__) | |
| #include <dbghelp.h> | |
| diff --git a/src/server/worldserver/CMakeLists.txt b/src/server/worldserver/CMakeLists.txt | |
| index 8c1350a..b7097be 100644 | |
| --- a/src/server/worldserver/CMakeLists.txt | |
| +++ b/src/server/worldserver/CMakeLists.txt | |
| @@ -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 ) | |
| -- | |
| 1.8.1.msysgit.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+if (MINGW) # GCC ignores "#prama comment"
I know it's just a comment and doesn't really matter, but...