Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MinGW32 support #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/contrib/libvorbis/lib/barkmel.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

********************************************************************/

#if 0
#include <stdio.h>
#include "scales.h"
int main(){
Expand Down Expand Up @@ -61,4 +62,4 @@ int main(){
}
return(0);
}

#endif
6 changes: 6 additions & 0 deletions src/engine/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ else ()
set_source_files_properties(src/audio_mixer_avx.cpp PROPERTIES COMPILE_FLAGS -mavx)
endif ()

if (MSVC)
set_source_files_properties(src/audio_mixer_sse.cpp PROPERTIES COMPILE_FLAGS /arch:SSE)
else ()
set_source_files_properties(src/audio_mixer_sse.cpp PROPERTIES COMPILE_FLAGS -msse)
endif ()

add_library (halley-audio ${SOURCES} ${HEADERS})
2 changes: 1 addition & 1 deletion src/engine/audio/include/halley/audio/vorbis_dec.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct OggVorbis_File;
#if defined(_MSC_VER) || defined(__clang__)
using OggOffsetType = int64_t;
#else
using OggOffsetType = long int;
using OggOffsetType = long long;
#endif

namespace Halley {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/include/halley/core/game/halley_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Halley

// Macro to implement program
#if defined(HALLEY_EXECUTABLE)
#if defined(_WIN32) || defined(WINDOWS_STORE)
#if (defined(_WIN32) || defined(WINDOWS_STORE)) && !defined(__MINGW32__)
#define HalleyGame(T) int __stdcall WinMain(void*, void*, char*, int) { return Halley::HalleyMain::winMain<T>(); }
#else
#define HalleyGame(T) int main(int argc, char* argv[]) { return Halley::HalleyMain::main<T>(argc, argv); }
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/include/halley/core/input/input_joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <chrono>
#include "input_button_base.h"

#if defined(_WIN32) && !defined(WINDOWS_STORE)
#if defined(_WIN32) && !defined(WINDOWS_STORE) && !defined(__MINGW32__)
#define XINPUT_AVAILABLE
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/src/game/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void Core::setOutRedirect(bool appendToExisting)
{
#if defined(_WIN32) || defined(__APPLE__) || defined(linux)
String path = (Path(environment->getDataPath()) / "log.txt").getString();
#ifdef _WIN32
#if defined(_WIN32) && !defined(__MINGW32__)
auto outStream = std::make_shared<std::ofstream>(path.getUTF16().c_str(), appendToExisting ? std::ofstream::app : std::ofstream::trunc);
#else
auto outStream = std::make_shared<std::ofstream>(path.c_str(), appendToExisting ? std::ofstream::app : std::ofstream::trunc);
Expand Down
4 changes: 4 additions & 0 deletions src/engine/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,7 @@ assign_source_group(${SOURCES})
assign_source_group(${HEADERS})

add_library (halley-utils ${SOURCES} ${HEADERS})

if (MINGW)
target_link_libraries(halley-utils shlwapi wbemuuid)
endif ()
2 changes: 1 addition & 1 deletion src/engine/utils/src/file/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ Bytes Path::readFile(const Path& path)
{
Bytes result;

#ifdef _WIN32
#if defined(_WIN32) && !defined(__MINGW32__)
std::ifstream fp(path.getString().getUTF16().c_str(), std::ios::binary | std::ios::in);
#else
std::ifstream fp(path.string(), std::ios::binary | std::ios::in);
Expand Down
57 changes: 56 additions & 1 deletion src/engine/utils/src/os/os_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@
#include <io.h>
#include <comutil.h>
#include <objbase.h>
#include <atlbase.h>
#include <fstream>
#include <Windows.h>
#include <shellapi.h>
#include <shlwapi.h>

#if defined(_WIN32) && !defined(__MINGW32__)
#include <atlbase.h>
#endif

#pragma comment(lib, "wbemuuid.lib")
//#pragma comment(lib, "comsupp.lib")
Expand All @@ -57,6 +61,11 @@ Halley::OSWin32::OSWin32()
// "Creating a WMI Application Using C++"

try {
#ifdef __MINGW32__
// Fix symbol undefined bug of MINGW
static const IID CLSID_WbemAdministrativeLocator = {0xcb8555cc, 0x9128, 0x11d1, {0xad,0x9b,0x00,0xc0,0x4f,0xd8,0xfd,0xff}};
#endif

// Initialize COM
HRESULT hr;
hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
Expand Down Expand Up @@ -105,8 +114,13 @@ static String getCOMError(int hr)
if (FAILED(hr2)) return "Failed getting COM error.";
BSTR str;
info->GetDescription(&str);
#ifdef __MINGW32__
String tmp(str);
return "\"" + tmp + "\", code 0x"+ toString(hr, 16);
#else
_bstr_t tmp(str);
return "\"" + String(LPCSTR(tmp)) + "\", code 0x"+ toString(hr, 16);
#endif
}

Halley::String Halley::OSWin32::runWMIQuery(String query, String parameter) const
Expand All @@ -117,6 +131,46 @@ Halley::String Halley::OSWin32::runWMIQuery(String query, String parameter) cons

if (pSvc) {
try {
#ifdef __MINGW32__
HRESULT hr;
IEnumWbemClassObject* enumerator;
BSTR lang = const_cast<BSTR>(L"WQL");
auto query_wchar = query.getUTF16();
BSTR q = const_cast<BSTR>(query_wchar.c_str());
hr = pSvc->ExecQuery(lang, q, WBEM_FLAG_FORWARD_ONLY, nullptr, &enumerator);
if (FAILED(hr)) {
if (enumerator) enumerator->Release(); enumerator = nullptr;
throw Exception("Error running WMI query: "+getCOMError(hr), HalleyExceptions::OS);
}

ULONG retcnt;
IWbemClassObject* result;
hr = enumerator->Next(WBEM_INFINITE, 1L, &result, &retcnt);
if (retcnt == 0) {
if (result) result->Release(); result = nullptr;
if (enumerator) enumerator->Release(); enumerator = nullptr;
return "Unknown";
}
if (FAILED(hr)) {
if (result) result->Release(); result = nullptr;
if (enumerator) enumerator->Release(); enumerator = nullptr;
throw Exception("Error obtaining WMI enumeration", HalleyExceptions::OS);
}

_variant_t var_val;
hr = result->Get(parameter.getUTF16().c_str(), 0, &var_val, nullptr, nullptr);

if (result) result->Release(); result = nullptr;
if (enumerator) enumerator->Release(); enumerator = nullptr;

if (FAILED(hr)) throw Exception("Error retrieving name from WMI query result", HalleyExceptions::OS);

if (var_val.vt == VT_NULL) {
return "";
} else {
return String(var_val.bstrVal);
}
#else
HRESULT hr;
CComPtr<IEnumWbemClassObject> enumerator;
BSTR lang = CComBSTR(L"WQL");
Expand All @@ -139,6 +193,7 @@ Halley::String Halley::OSWin32::runWMIQuery(String query, String parameter) cons
} else {
return String(static_cast<const char*>(_bstr_t(var_val)));
}
#endif
} catch (std::exception& e) {
std::cout << "Exception running WMI query: " << e.what() << std::endl;
} catch (...) {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/utils/src/support/StackWalker/StackWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
*
**********************************************************************/

#if defined(_WIN32) && !defined(WINDOWS_STORE)
#if defined(_WIN32) && !defined(WINDOWS_STORE) && !defined(__MINGW32__)

#include <windows.h>
#include <tchar.h>
Expand Down
2 changes: 1 addition & 1 deletion src/engine/utils/src/support/StackWalker/StackWalker.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
// so we need not to check the version (because we only support _MSC_VER >= 1100)!
#pragma once

#if defined(_WIN32) && !defined(WINDOWS_STORE)
#if defined(_WIN32) && !defined(WINDOWS_STORE) && !defined(__MINGW32__)

#include <windows.h>

Expand Down
6 changes: 5 additions & 1 deletion src/plugins/asio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ assign_source_group(${SOURCES})
assign_source_group(${HEADERS})

add_library (halley-asio ${SOURCES} ${HEADERS})
target_link_libraries(halley-asio halley-core halley-net)
target_link_libraries(halley-asio halley-core halley-net)

if (MINGW)
target_link_libraries(halley-asio ws2_32 wsock32)
endif ()
4 changes: 4 additions & 0 deletions src/plugins/dx11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ assign_source_group(${HEADERS})

add_library (halley-dx11 ${SOURCES} ${HEADERS})
target_link_libraries(halley-dx11 halley-core halley-utils)

if (MINGW)
target_link_libraries(halley-dx11 d3d11 dxgi)
endif ()
6 changes: 6 additions & 0 deletions src/plugins/dx11/src/dx11_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "dx11_texture.h"
#include "dx11_render_target.h"
#include "dx11_material_constant_buffer.h"
#include "dx11_blend.h"
#include "dx11_rasterizer.h"

#include <windows.h>
#include <windowsx.h>
Expand Down Expand Up @@ -113,7 +115,11 @@ void DX11Video::initSwapChain(Window& window)
#else
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
#endif
#ifdef __MINGW32__
swapChainDesc.Scaling = static_cast<DXGI_SCALING>(2); // DXGI_SCALING_ASPECT_RATIO_STRETCH
#else
swapChainDesc.Scaling = DXGI_SCALING_ASPECT_RATIO_STRETCH;
#endif
swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;

IUnknown* coreWindow = reinterpret_cast<IUnknown*>(window.getNativeHandle());
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/mf/src/resource_data_byte_stream.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "resource_data_byte_stream.h"
#include "halley/concurrency/concurrent.h"
#include <atlbase.h>
//#include <atlbase.h>
using namespace Halley;

class AsyncReadOp : public IUnknown
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/opengl/src/video_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,18 @@ void VideoOpenGL::setupDebugCallback()
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
#endif
#ifdef __MINGW32__
struct DebugImpl {
static void APIENTRY Callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) {
reinterpret_cast<const VideoOpenGL*>(userParam)->onGLDebugMessage(source, type, id, severity, message);
}
};
glDebugMessageCallback(DebugImpl::Callback, this);
#else
glDebugMessageCallback([](GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) {
reinterpret_cast<const VideoOpenGL*>(userParam)->onGLDebugMessage(source, type, id, severity, message);
}, this);
#endif
glCheckError();
} else {
glGetError();
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/sdl/src/system_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ std::shared_ptr<IClipboard> SystemSDL::getClipboard() const
}


#if defined(_WIN32) && !defined(WINDOWS_STORE)
#if defined(_WIN32) && !defined(WINDOWS_STORE) && !defined(__MINGW32__)
#pragma warning(default: 6320 6322)
#include <Windows.h>
const DWORD MS_VC_EXCEPTION=0x406D1388;
Expand Down Expand Up @@ -327,7 +327,7 @@ void SetThreadName( DWORD dwThreadID, const char* name)

void SystemSDL::setThreadName(const String& name)
{
#if defined(_WIN32) && !defined(WINDOWS_STORE) && defined(_DEBUG)
#if defined(_WIN32) && !defined(WINDOWS_STORE) && !defined(__MINGW32__) && defined(_DEBUG)
if (name != "main") {
SetThreadName(static_cast<DWORD>(-1), name.c_str());
}
Expand Down
2 changes: 2 additions & 0 deletions src/tools/editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(EXTRA_LIBS bz2 z)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(EXTRA_LIBS pthread)
elseif(MINGW)
set(EXTRA_LIBS ws2_32 wsock32 d3d11 dxgi)
endif()

include_directories(${FREETYPE_INCLUDE_DIR} "../tools/include")
Expand Down
2 changes: 1 addition & 1 deletion src/tools/runner/src/dynamic_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void DynamicLibrary::unload()
void* DynamicLibrary::getFunction(std::string name) const
{
#ifdef _WIN32
return GetProcAddress(handle, name.c_str());
return reinterpret_cast<void*>(GetProcAddress(handle, name.c_str()));
#else
return nullptr;
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/tools/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,7 @@ target_link_libraries (halley-tools
${YAMLCPP_LIBRARY}
${CMAKE_DL_LIBS}
)

if (MINGW)
target_link_libraries(halley-tools d3dcompiler)
endif ()
8 changes: 6 additions & 2 deletions src/tools/tools/src/assets/importers/shader_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "halley/core/graphics/shader.h"
#include "halley/support/logger.h"

#ifdef _MSC_VER
#ifdef _WIN32
#include <D3Dcompiler.h>
#pragma comment(lib, "D3DCompiler.lib")
#endif
Expand Down Expand Up @@ -36,7 +36,7 @@ void ShaderImporter::import(const ImportingAsset& asset, IAssetCollector& collec

Bytes ShaderImporter::compileHLSL(const String& name, ShaderType type, const Bytes& bytes) const
{
#ifdef _MSC_VER
#ifdef _WIN32

String target;

Expand All @@ -59,7 +59,11 @@ Bytes ShaderImporter::compileHLSL(const String& name, ShaderType type, const Byt

ID3D10Blob *codeBlob = nullptr;
ID3D10Blob *errorBlob = nullptr;
#ifdef __MINGW32__
const HRESULT hResult = D3DCompile(bytes.data(), bytes.size(), name.c_str(), nullptr, nullptr, "main", target.c_str(), 0, 0, &codeBlob, &errorBlob);
#else
const HRESULT hResult = D3DCompile2(bytes.data(), bytes.size(), name.c_str(), nullptr, nullptr, "main", target.c_str(), 0, 0, 0, nullptr, 0, &codeBlob, &errorBlob);
#endif
if (hResult != S_OK) {
const auto errorMessage = String(reinterpret_cast<const char*>(errorBlob->GetBufferPointer()), errorBlob->GetBufferSize());
errorBlob->Release();
Expand Down