From e221011af2ec272629fdbd56c57175d81099812c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 24 May 2011 22:51:45 +0000 Subject: [PATCH] - bugfixes so that the mingw compile builds --- CMakeLists.txt | 2 +- build-mg.sh | 4 +++- source/configurator/CMakeLists.txt | 9 ++++++- source/g3d_viewer/CMakeLists.txt | 9 ++++++- source/glest_game/CMakeLists.txt | 5 +++- source/glest_game/ai/ai_interface.cpp | 3 ++- source/glest_game/global/config.cpp | 4 ++-- source/glest_game/menu/menu_state_about.cpp | 4 ++-- .../menu/menu_state_custom_game.cpp | 4 ++-- source/glest_game/world/world.cpp | 4 ++-- source/glest_map_editor/CMakeLists.txt | 10 +++++++- .../shared_lib/include/graphics/FileReader.h | 24 ++++++++++--------- .../platform/common/platform_common.cpp | 12 ++++++++-- source/shared_lib/sources/util/properties.cpp | 8 +++---- source/shared_lib/sources/util/util.cpp | 2 +- 15 files changed, 71 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a435fbc..ef27425a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,7 @@ IF(CMAKE_COMPILER_IS_GNUCXX OR MINGW) # For tons of verbose warnings add: -Wall ADD_DEFINITIONS("-Wreturn-type -fno-strict-aliasing -frounding-math -fsignaling-nans -mfpmath=sse -msse -rdynamic") ELSE() - ADD_DEFINITIONS("-Wreturn-type -fno-strict-aliasing -frounding-math -fsignaling-nans -mfpmath=sse -msse") + ADD_DEFINITIONS("-Wreturn-type -fno-strict-aliasing -frounding-math -fsignaling-nans -mfpmath=sse -msse -DUNICODE") ENDIF() #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") diff --git a/build-mg.sh b/build-mg.sh index 616b9e96..e8cc5c29 100755 --- a/build-mg.sh +++ b/build-mg.sh @@ -1,12 +1,14 @@ #!/bin/bash +NUMCORES=`cat /proc/cpuinfo | grep -cE '^processor'` + mkdir -p build cd build [[ -f "CMakeCache.txt" ]] && rm -f "CMakeCache.txt" # This is for regular developers and used by our installer cmake -DCMAKE_INSTALL_PREFIX= -DWANT_STATIC_LIBS=ON .. -make +make -j$NUMCORES cd .. echo 'You may now launch MegaGlest from this directory like this:' diff --git a/source/configurator/CMakeLists.txt b/source/configurator/CMakeLists.txt index 44ee6ce7..d6bed440 100644 --- a/source/configurator/CMakeLists.txt +++ b/source/configurator/CMakeLists.txt @@ -64,7 +64,7 @@ SET(GLEST_LIB_INCLUDE_ROOT "../shared_lib/include/") SET(GLEST_LIB_INCLUDE_DIRS ${GLEST_LIB_INCLUDE_ROOT}platform/common - ${GLEST_LIB_INCLUDE_ROOT}platform/sdl +# ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ${GLEST_LIB_INCLUDE_ROOT}platform/posix ${GLEST_LIB_INCLUDE_ROOT}util ${GLEST_LIB_INCLUDE_ROOT}graphics @@ -79,6 +79,13 @@ SET(GLEST_LIB_INCLUDE_DIRS ) INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_DIRS} ) +IF(WIN32) + INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/win32) + INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ) +ELSE() + INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ) +ENDIF() + SET(MG_SOURCE_FILES "../glest_game/global/config.cpp") FOREACH(DIR IN LISTS DIRS_WITH_SRC) diff --git a/source/g3d_viewer/CMakeLists.txt b/source/g3d_viewer/CMakeLists.txt index 1ed50655..9f32a85f 100644 --- a/source/g3d_viewer/CMakeLists.txt +++ b/source/g3d_viewer/CMakeLists.txt @@ -64,7 +64,7 @@ SET(GLEST_LIB_INCLUDE_ROOT "../shared_lib/include/") SET(GLEST_LIB_INCLUDE_DIRS ${GLEST_LIB_INCLUDE_ROOT}platform/common - ${GLEST_LIB_INCLUDE_ROOT}platform/sdl +# ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ${GLEST_LIB_INCLUDE_ROOT}platform/posix ${GLEST_LIB_INCLUDE_ROOT}util ${GLEST_LIB_INCLUDE_ROOT}graphics @@ -81,6 +81,13 @@ SET(GLEST_LIB_INCLUDE_DIRS ) INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_DIRS} ) +IF(WIN32) + INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/win32) + INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ) +ELSE() + INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ) +ENDIF() + SET(MG_SOURCE_FILES "../glest_game/graphics/particle_type.cpp" "../glest_game/graphics/unit_particle_type.cpp" "../glest_game/global/config.cpp") FOREACH(DIR IN LISTS DIRS_WITH_SRC) diff --git a/source/glest_game/CMakeLists.txt b/source/glest_game/CMakeLists.txt index 6d9e5f9a..999490aa 100644 --- a/source/glest_game/CMakeLists.txt +++ b/source/glest_game/CMakeLists.txt @@ -114,14 +114,17 @@ SET(GLEST_LIB_INCLUDE_DIRS ${GLEST_LIB_INCLUDE_ROOT}streflop/libm_flt32_source ${GLEST_LIB_INCLUDE_ROOT}map) INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_DIRS} ) -INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ) + +#INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ) IF(WIN32) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/include) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/posix) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/win32) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/sound/ds8) + INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ) ELSE() + INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ) SET(GLEST_LIB_INCLUDE_DIRS ${GLEST_LIB_INCLUDE_DIRS} ${GLEST_LIB_INCLUDE_ROOT}platform/sdl) SET(GLEST_LIB_INCLUDE_DIRS ${GLEST_LIB_INCLUDE_DIRS} ${GLEST_LIB_INCLUDE_ROOT}platform/unix) ENDIF() diff --git a/source/glest_game/ai/ai_interface.cpp b/source/glest_game/ai/ai_interface.cpp index bd04856f..725b9181 100644 --- a/source/glest_game/ai/ai_interface.cpp +++ b/source/glest_game/ai/ai_interface.cpp @@ -20,6 +20,7 @@ #include "game.h" #include "config.h" #include "network_manager.h" +#include "platform_util.h" #include "leak_dumper.h" using namespace Shared::Util; @@ -53,7 +54,7 @@ AiInterface::AiInterface(Game &game, int factionIndex, int teamIndex, int useSta //clear log file if(logLevel>0){ #ifdef WIN32 - FILE *f= _wfopen(utf8_decode(getLogFilename()).c_str(), L"wt"); + FILE *f= _wfopen(Shared::Platform::utf8_decode(getLogFilename()).c_str(), L"wt"); #else FILE *f= fopen(getLogFilename().c_str(), "wt"); #endif diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index a0f3fbb0..eb82fcc7 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -194,7 +194,7 @@ Config::Config(std::pair type, std::pair f if(fileName.second != "" && fileExists(fileName.second) == false) { if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] attempting to auto-create cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str()); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) wstring wstr = utf8_decode(fileName.second); FILE *fp = _wfopen(wstr.c_str(), L"w"); std::ofstream userFile(fp); @@ -203,7 +203,7 @@ Config::Config(std::pair type, std::pair f userFile.open(fileName.second.c_str(), ios_base::out | ios_base::trunc); #endif userFile.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) if(fp) { fclose(fp); } diff --git a/source/glest_game/menu/menu_state_about.cpp b/source/glest_game/menu/menu_state_about.cpp index a1311681..e4b86c3c 100644 --- a/source/glest_game/menu/menu_state_about.cpp +++ b/source/glest_game/menu/menu_state_about.cpp @@ -104,7 +104,7 @@ string MenuStateAbout::loadAdditionalCredits(){ string result= ""; const string dir= data_path + "data/core/menu/credits.txt"; if(fileExists(dir) == true) { -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) FILE *fp = _wfopen(utf8_decode(dir).c_str(), L"r"); ifstream file(fp); #else @@ -117,7 +117,7 @@ string MenuStateAbout::loadAdditionalCredits(){ } std::cout << buffer << std::endl; file.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) fclose(fp); #endif } diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 6a738de1..23e7e740 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -2373,7 +2373,7 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) { GameSettings gameSettings; loadGameSettings(&gameSettings); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) FILE *fp = _wfopen(utf8_decode(fileName).c_str(), L"w"); std::ofstream saveGameFile(fp); #else @@ -2421,7 +2421,7 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) { saveGameFile << "FactionPlayerNameForIndex" << slotIndex << "=" << gameSettings.getNetworkPlayerName(i) << std::endl; } -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) fclose(fp); #endif if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 4dfd1c9f..718fe4cc 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -1677,7 +1677,7 @@ std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const { } else { -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) FILE *fp = _wfopen(utf8_decode(debugWorldLogFile).c_str(), L"w"); std::ofstream logFile(fp); #else @@ -1708,7 +1708,7 @@ std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const { } logFile.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) if(fp) { fclose(fp); } diff --git a/source/glest_map_editor/CMakeLists.txt b/source/glest_map_editor/CMakeLists.txt index 136cc58d..a80b6485 100644 --- a/source/glest_map_editor/CMakeLists.txt +++ b/source/glest_map_editor/CMakeLists.txt @@ -65,7 +65,7 @@ SET(GLEST_LIB_INCLUDE_ROOT "../shared_lib/include/") SET(GLEST_LIB_INCLUDE_DIRS ${GLEST_LIB_INCLUDE_ROOT}platform/common - ${GLEST_LIB_INCLUDE_ROOT}platform/sdl +# ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ${GLEST_LIB_INCLUDE_ROOT}platform/posix ${GLEST_LIB_INCLUDE_ROOT}util ${GLEST_LIB_INCLUDE_ROOT}graphics @@ -78,6 +78,14 @@ SET(GLEST_LIB_INCLUDE_DIRS INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_DIRS} ) +IF(WIN32) + INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/win32) + INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ) +ELSE() + INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl ) +ENDIF() + + SET(MG_SOURCE_FILES "../glest_game/global/config.cpp") FOREACH(DIR IN LISTS DIRS_WITH_SRC) diff --git a/source/shared_lib/include/graphics/FileReader.h b/source/shared_lib/include/graphics/FileReader.h index f65d8af1..06bce0b1 100644 --- a/source/shared_lib/include/graphics/FileReader.h +++ b/source/shared_lib/include/graphics/FileReader.h @@ -21,6 +21,7 @@ #include #include #include +#include "conversion.h" #include "leak_dumper.h" using std::map; @@ -29,6 +30,7 @@ using std::vector; using std::ifstream; using std::ios; using std::runtime_error; +using namespace Shared::Util; using Shared::PlatformCommon::extractExtension; @@ -141,7 +143,7 @@ public: template static inline T* readFromFileReaders(vector const *>* readers, const string& filepath) { //try to assign file -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) FILE *fp = _wfopen(utf8_decode(filepath).c_str(), L"rb"); ifstream file(fp); #else @@ -161,14 +163,14 @@ static inline T* readFromFileReaders(vector const *>* readers, con } if (ret != NULL) { file.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) fclose(fp); #endif return ret; } } file.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) fclose(fp); #endif @@ -178,7 +180,7 @@ static inline T* readFromFileReaders(vector const *>* readers, con template static inline T* readFromFileReaders(vector const *>* readers, const string& filepath, T* object) { //try to assign file -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) wstring wstr = utf8_decode(filepath); FILE *fp = _wfopen(wstr.c_str(), L"rb"); int fileErrno = errno; @@ -187,7 +189,7 @@ static inline T* readFromFileReaders(vector const *>* readers, con ifstream file(filepath.c_str(), ios::in | ios::binary); #endif if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message? -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) DWORD error = GetLastError(); throw runtime_error("Could not open file, result: " + intToStr(error) + " - " + intToStr(fileErrno) + " [" + filepath + "]"); #else @@ -205,14 +207,14 @@ static inline T* readFromFileReaders(vector const *>* readers, con } if (ret != NULL) { file.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) fclose(fp); #endif return ret; } } file.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) fclose(fp); #endif return NULL; @@ -326,7 +328,7 @@ bool FileReader::canRead(ifstream& file) const { */ template T* FileReader::read(const string& filepath) const { -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) FILE *fp = _wfopen(utf8_decode(filepath).c_str(), L"rb"); ifstream file(fp); #else @@ -337,7 +339,7 @@ T* FileReader::read(const string& filepath) const { } T* ret = read(file,filepath); file.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) fclose(fp); #endif @@ -351,7 +353,7 @@ T* FileReader::read(const string& filepath) const { */ template T* FileReader::read(const string& filepath, T* object) const { -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) FILE *fp = _wfopen(utf8_decode(filepath).c_str(), L"rb"); ifstream file(fp); #else @@ -362,7 +364,7 @@ T* FileReader::read(const string& filepath, T* object) const { } T* ret = read(file,filepath,object); file.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) fclose(fp); #endif diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 1a015685..3817a8f3 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -370,7 +370,11 @@ bool isdir(const char *path) #endif #ifdef WIN32 + #if defined(__MINGW32__) + struct _stat stats; + #else struct _stat64i32 stats; + #endif int result = _wstat(utf8_decode(friendly_path).c_str(), &stats); #else struct stat stats; @@ -1717,7 +1721,11 @@ bool renameFile(string oldFile, string newFile) { off_t getFileSize(string filename) { #ifdef WIN32 + #if defined(__MINGW32__) + struct _stat stbuf; + #else struct _stat64i32 stbuf; + #endif if(_wstat(utf8_decode(filename).c_str(), &stbuf) != -1) { #else struct stat stbuf; @@ -1873,7 +1881,7 @@ bool searchAndReplaceTextInFile(string fileName, string findText, string replace void copyFileTo(string fromFileName, string toFileName) { //Open an input and output stream in binary mode -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) FILE *fp1 = _wfopen(utf8_decode(fromFileName).c_str(), L"rb"); ifstream in(fp1); FILE *fp2 = _wfopen(utf8_decode(toFileName).c_str(), L"wb"); @@ -1899,7 +1907,7 @@ void copyFileTo(string fromFileName, string toFileName) { in.close(); out.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) if(fp1) { fclose(fp1); } diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 124dbd00..84a68a1a 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -46,7 +46,7 @@ void Properties::load(const string &path, bool clearCurrentProperties) { size_t pos=0; this->path= path; -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) FILE *fp = _wfopen(utf8_decode(path).c_str(), L"r"); ifstream fileStream(fp); #else @@ -110,7 +110,7 @@ void Properties::load(const string &path, bool clearCurrentProperties) { } fileStream.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) fclose(fp); #endif } @@ -269,7 +269,7 @@ bool Properties::applyTagsToValue(string &value, std::map *mapTag } void Properties::save(const string &path){ -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) FILE *fp = _wfopen(utf8_decode(path).c_str(), L"w"); ofstream fileStream(fp); #else @@ -284,7 +284,7 @@ void Properties::save(const string &path){ } fileStream.close(); -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) fclose(fp); #endif } diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 3f08c4ae..cdbf47cd 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -513,7 +513,7 @@ void SystemFlags::logDebugEntry(DebugType type, string debugEntry, time_t debugT } if(currentDebugLog.fileStream == NULL) { -#ifdef WIN32 +#if defined(WIN32) && !defined(__MINGW32__) currentDebugLog.fileStream = new std::ofstream(_wfopen(utf8_decode(debugLog).c_str(), L"w")); #else currentDebugLog.fileStream = new std::ofstream();