diff --git a/CMakeLists.txt b/CMakeLists.txt index f7b0af115..c8770ca01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,8 +69,11 @@ if (NOT MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") if (ARCHITECTURE_x86_64) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1") + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1") + #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1") + #Some CPU do not support sse4.1 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3") endif() else() # Silence "deprecation" warnings @@ -114,11 +117,16 @@ add_definitions(-DSINGLETHREADED) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$:_DEBUG> $<$>:NDEBUG>) -find_package(PNG QUIET) -if (PNG_FOUND) - add_definitions(-DHAVE_PNG) +option(ENABLE_SUPPORT_PNG "Disable the libpng support" OFF) +if(ENABLE_SUPPORT_PNG) + find_package(PNG QUIET) + if (PNG_FOUND) + add_definitions(-DHAVE_PNG) + else() + message(STATUS "libpng not found. Some debugging features have been disabled.") + endif() else() - message(STATUS "libpng not found. Some debugging features have been disabled.") + endif() find_package(Boost 1.57.0 QUIET) @@ -140,10 +148,17 @@ set (THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) if (ENABLE_SDL2) - if (CITRA_USE_BUNDLED_SDL2) + if (SDL2_PREFIX) + message(STATUS "SDL2_PATH = ${SDL2_PREFIX}") + set(SDL2_INCLUDE_DIR "${SDL2_PREFIX}/include" CACHE PATH "Path to SDL2 headers") + set(SDL2_LIBRARY "${SDL2_PREFIX}/x86_64-w64-mingw32/lib/libSDL2.dll.a" CACHE PATH "Path to SDL2 library") + set(SDL2_DLL_DIR "${SDL2_PREFIX}/x86_64-w64-mingw32/lib/" CACHE PATH "Path to SDL2.dll") + elseif (CITRA_USE_BUNDLED_SDL2) # Detect toolchain and platform if (MSVC14 AND ARCHITECTURE_x86_64) set(SDL2_VER "SDL2-2.0.4") + elseif(MINGW) + set(SDL2_VER "SDL2-2.0.4") else() message(FATAL_ERROR "No bundled SDL2 binaries for your toolchain. Disable CITRA_USE_BUNDLED_SDL2 and provide your own.") endif() @@ -152,10 +167,17 @@ if (ENABLE_SDL2) download_bundled_external("sdl2/" ${SDL2_VER} SDL2_PREFIX) endif() - set(SDL2_FOUND YES) - set(SDL2_INCLUDE_DIR "${SDL2_PREFIX}/include" CACHE PATH "Path to SDL2 headers") - set(SDL2_LIBRARY "${SDL2_PREFIX}/lib/x64/SDL2.lib" CACHE PATH "Path to SDL2 library") - set(SDL2_DLL_DIR "${SDL2_PREFIX}/lib/x64/" CACHE PATH "Path to SDL2.dll") + if (MSVC) + set(SDL2_FOUND YES) + set(SDL2_INCLUDE_DIR "${SDL2_PREFIX}/include" CACHE PATH "Path to SDL2 headers") + set(SDL2_LIBRARY "${SDL2_PREFIX}/lib/x64/SDL2.lib" CACHE PATH "Path to SDL2 library") + set(SDL2_DLL_DIR "${SDL2_PREFIX}/lib/x64/" CACHE PATH "Path to SDL2.dll") + elseif (MINGW) + set(SDL2_FOUND YES) + set(SDL2_INCLUDE_DIR "${SDL2_PREFIX}/include" CACHE PATH "Path to SDL2 headers") + set(SDL2_LIBRARY "${SDL2_PREFIX}/x86_64-w64-mingw32/lib/libSDL2.dll.a" CACHE PATH "Path to SDL2 library") + set(SDL2_DLL_DIR "${SDL2_PREFIX}/x86_64-w64-mingw32/lib/" CACHE PATH "Path to SDL2.dll") + endif() else() find_package(SDL2 REQUIRED) endif() @@ -172,7 +194,9 @@ IF (APPLE) ELSEIF(MINGW) # GCC does not support codecvt, so use iconv instead # PSAPI is the Process Status API - set(PLATFORM_LIBRARIES winmm ws2_32 psapi iconv) + # TDM-GCC64 not support iconv + # set(PLATFORM_LIBRARIES winmm ws2_32 psapi iconv) + set(PLATFORM_LIBRARIES winmm ws2_32 psapi) # WSAPoll functionality doesn't exist before WinNT 6.x (Vista and up) add_definitions(-D_WIN32_WINNT=0x0600) diff --git a/TDMGCC64_SDL2_build.md b/TDMGCC64_SDL2_build.md new file mode 100644 index 000000000..7654e350e --- /dev/null +++ b/TDMGCC64_SDL2_build.md @@ -0,0 +1,13 @@ + +TDM-GCC64 build + + +bash +git clone --recursive https://github.com/yami-hack/citra.git +mkdir build +cd build +cmake ../citra -DCMAKE_BUILD_TYPE=Release -G "MinGW Makefiles" \ + -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \ + -DENABLE_QT=OFF \ + -DMINGW_HOME=/h/TDM-GCC64/ \ + -DSDL2_PATH="G:/src/citra160603/build/externals/SDL2-2.0.4" \ No newline at end of file diff --git a/externals/microprofile/microprofile.h b/externals/microprofile/microprofile.h index d1ae0c1c2..06cf30803 100644 --- a/externals/microprofile/microprofile.h +++ b/externals/microprofile/microprofile.h @@ -923,15 +923,18 @@ void MicroProfileThreadJoin(MicroProfileThread* pThread) } #elif defined(_WIN32) typedef HANDLE MicroProfileThread; -DWORD _stdcall ThreadTrampoline(void* pFunc) +DWORD __stdcall ThreadTrampoline(void* pFunc) { MicroProfileThreadFunc F = (MicroProfileThreadFunc)pFunc; - return (uint32_t)F(0); + //return (uint32_t)F(0); + void *ret = F(0); + return *(uint32_t*)&ret; } void MicroProfileThreadStart(MicroProfileThread* pThread, MicroProfileThreadFunc Func) { - *pThread = CreateThread(0, 0, ThreadTrampoline, Func, 0, 0); + //*pThread = CreateThread(0, 0, ThreadTrampoline, Func, 0, 0); + *pThread = CreateThread(0, 0, ThreadTrampoline, (void*)Func, 0, 0); } void MicroProfileThreadJoin(MicroProfileThread* pThread) { diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 17af7c385..f6f6a9e09 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -8,6 +8,13 @@ #include "common/file_util.h" #include "common/logging/log.h" +#if defined(__MINGW64__) +#include +#endif + +#if defined(__MINGW64__) +#include +#endif #ifdef _WIN32 #include #include // for SHGetFolderPath @@ -926,7 +933,7 @@ void IOFile::Swap(IOFile& other) bool IOFile::Open(const std::string& filename, const char openmode[]) { Close(); -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW64__) _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str()); #else m_file = fopen(filename.c_str(), openmode); @@ -980,6 +987,9 @@ bool IOFile::Flush() bool IOFile::Resize(u64 size) { if (!IsOpen() || 0 != +#if defined(__MINGW64__) + chsize(_fileno(m_file), size) +#else #ifdef _WIN32 // ector: _chsize sucks, not 64-bit safe // F|RES: changed to _chsize_s. i think it is 64-bit safe @@ -987,6 +997,7 @@ bool IOFile::Resize(u64 size) #else // TODO: handle 64bit and growing ftruncate(fileno(m_file), size) +#endif #endif ) m_good = false; diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index f0aa072db..857caf189 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -13,6 +13,18 @@ #include "common/logging/log.h" #include "common/string_util.h" +#if defined(__MINGW64__) + //TDM-GCC64 + #include + #include + #include "common/common_funcs.h" +#else +#if defined(__MINGW32__) + //MINGW32 + #include + #include + #include "common/common_funcs.h" +#else #ifdef _MSC_VER #include #include @@ -20,6 +32,8 @@ #else #include #endif +#endif +#endif namespace Common { @@ -52,7 +66,7 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar { int writtenCount; -#ifdef _MSC_VER +#if defined(_MSC_VER) || !defined(__MINGW64__) // You would think *printf are simple, right? Iterate on each character, // if it's a format specifier handle it properly, etc. // @@ -292,7 +306,7 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st return result; } -#ifdef _MSC_VER +#if defined(_MSC_VER) || !defined(__MINGW32__) || defined(__MINGW64__) std::string UTF16ToUTF8(const std::u16string& input) { @@ -363,6 +377,41 @@ std::string CP1252ToUTF8(const std::string& input) #else +#if defined(__MINGW32__) +// MINGW32 and TDM-GCC64 +static std::wstring CPToUTF16(u32 code_page, const std::string& input) +{ + auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast(input.size()), nullptr, 0); + + std::wstring output; + output.resize(size); + + if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast(input.size()), &output[0], static_cast(output.size()))) + output.clear(); + + return output; +} + +std::wstring UTF8ToUTF16W(const std::string &input) +{ + return CPToUTF16(CP_UTF8, input); +} + +std::string UTF16ToUTF8(const std::wstring& input){ + auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast(input.size()), nullptr, 0, nullptr, nullptr); + + std::string output; + output.resize(size); + + if (size == 0 || size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast(input.size()), &output[0], static_cast(output.size()), nullptr, nullptr)) + output.clear(); + + return output; +} + +#endif + + template static std::string CodeToUTF8(const char* fromcode, const std::basic_string& input) { diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 820b19e1a..94124814c 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -14,6 +14,14 @@ #include #include +#ifdef _WIN32 +#include +#include +#include +#include +#include +#define SHUT_RDWR 2 +#else #ifdef _MSC_VER #include #include @@ -28,6 +36,7 @@ #include #include #endif +#endif #include "common/logging/log.h" #include "common/string_util.h"