Browse Source

Add support for MinGW based compilers (#204)

ImperatorS79 3 years ago
parent
commit
8adaf983f4

+ 28 - 0
.github/workflows/build.yml

@@ -55,6 +55,34 @@ jobs:
       working-directory: ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}}
       working-directory: ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}}
       run: ctest --output-on-failure
       run: ctest --output-on-failure
 
 
+  msys2_mingw_gcc:
+    runs-on: windows-latest
+    defaults:
+      run:
+        shell: msys2 {0}
+    name: MSYS2 MinGW GCC
+    strategy:
+        fail-fast: false
+        matrix:
+            build_type: [Debug]
+
+    steps:
+    - name: Checkout Code
+      uses: actions/checkout@v2
+    - name: Setup MSYS2
+      uses: msys2/setup-msys2@v2
+      with:
+        msystem: mingw64
+        install: mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake
+        update: true
+    - name: Configure CMake
+      run: cmake -B Build/MSYS2_MinGW_GCC -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DTARGET_SAMPLES=OFF -DTARGET_VIEWER=OFF Build
+    - name: Build
+      run: cmake --build Build/MSYS2_MinGW_GCC
+    - name: Test
+      working-directory: Build/MSYS2_MinGW_GCC
+      run: ctest --output-on-failure
+      
   msvc_cl:
   msvc_cl:
     runs-on: windows-latest
     runs-on: windows-latest
     name: Visual Studio CL
     name: Visual Studio CL

+ 1 - 0
Build/.gitignore

@@ -1,5 +1,6 @@
 /Linux*
 /Linux*
 /VS20*
 /VS20*
 /XCode*
 /XCode*
+/MinGW*
 /Doxygen
 /Doxygen
 /CoverageReport
 /CoverageReport

+ 5 - 5
Build/CMakeLists.txt

@@ -32,7 +32,7 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}
 	set(CMAKE_CONFIGURATION_TYPES "Debug;Release;ReleaseASAN;ReleaseUBSAN;ReleaseCoverage;Distribution")
 	set(CMAKE_CONFIGURATION_TYPES "Debug;Release;ReleaseASAN;ReleaseUBSAN;ReleaseCoverage;Distribution")
 endif()
 endif()
 
 
-if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
+if (("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore") AND NOT MINGW)
 	# Fill in the path to the asan libraries
 	# Fill in the path to the asan libraries
 	set(CLANG_LIB_PATH "\"$(VSInstallDir)\\VC\\Tools\\Llvm\\x64\\lib\\clang\\${CMAKE_CXX_COMPILER_VERSION}\\lib\\windows\"")
 	set(CLANG_LIB_PATH "\"$(VSInstallDir)\\VC\\Tools\\Llvm\\x64\\lib\\clang\\${CMAKE_CXX_COMPILER_VERSION}\\lib\\windows\"")
 	
 	
@@ -127,7 +127,7 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR "${CMAKE_SYSTEM_NAME}" STREQUAL
 		set(CMAKE_EXE_LINKER_FLAGS_RELEASEUBSAN "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LIBPATH:${CLANG_LIB_PATH}")
 		set(CMAKE_EXE_LINKER_FLAGS_RELEASEUBSAN "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LIBPATH:${CLANG_LIB_PATH}")
 		set(CMAKE_EXE_LINKER_FLAGS_RELEASECOVERAGE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LIBPATH:${CLANG_LIB_PATH}")
 		set(CMAKE_EXE_LINKER_FLAGS_RELEASECOVERAGE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LIBPATH:${CLANG_LIB_PATH}")
 	endif()
 	endif()
-elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
+elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS" OR MINGW)
 	# Set general compiler flags
 	# Set general compiler flags
 	set(CMAKE_CXX_FLAGS "-g -std=c++17 -I. -Wall -Werror")
 	set(CMAKE_CXX_FLAGS "-g -std=c++17 -I. -Wall -Werror")
 
 
@@ -211,7 +211,7 @@ if (TARGET_UNIT_TESTS)
     target_include_directories(UnitTests PUBLIC ${UNIT_TESTS_ROOT})
     target_include_directories(UnitTests PUBLIC ${UNIT_TESTS_ROOT})
     target_link_libraries(UnitTests LINK_PUBLIC Jolt)
     target_link_libraries(UnitTests LINK_PUBLIC Jolt)
 	target_precompile_headers(UnitTests PRIVATE ${JOLT_PHYSICS_ROOT}/Jolt.h)
 	target_precompile_headers(UnitTests PRIVATE ${JOLT_PHYSICS_ROOT}/Jolt.h)
-    if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+    if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND NOT MINGW)
         target_link_options(UnitTests PUBLIC "/SUBSYSTEM:CONSOLE")
         target_link_options(UnitTests PUBLIC "/SUBSYSTEM:CONSOLE")
     endif()
     endif()
     if (IOS)
     if (IOS)
@@ -236,7 +236,7 @@ if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
 		add_executable(HelloWorld ${HELLO_WORLD_SRC_FILES})
 		add_executable(HelloWorld ${HELLO_WORLD_SRC_FILES})
 		target_include_directories(HelloWorld PUBLIC ${HELLO_WORLD_ROOT})
 		target_include_directories(HelloWorld PUBLIC ${HELLO_WORLD_ROOT})
 		target_link_libraries(HelloWorld LINK_PUBLIC Jolt)
 		target_link_libraries(HelloWorld LINK_PUBLIC Jolt)
-		if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+		if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND NOT MINGW)
 			target_link_options(HelloWorld PUBLIC "/SUBSYSTEM:CONSOLE")
 			target_link_options(HelloWorld PUBLIC "/SUBSYSTEM:CONSOLE")
 		endif()
 		endif()
 	endif()
 	endif()
@@ -247,7 +247,7 @@ if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
 		add_executable(PerformanceTest ${PERFORMANCE_TEST_SRC_FILES})
 		add_executable(PerformanceTest ${PERFORMANCE_TEST_SRC_FILES})
 		target_include_directories(PerformanceTest PUBLIC ${PERFORMANCE_TEST_ROOT})
 		target_include_directories(PerformanceTest PUBLIC ${PERFORMANCE_TEST_ROOT})
 		target_link_libraries(PerformanceTest LINK_PUBLIC Jolt)
 		target_link_libraries(PerformanceTest LINK_PUBLIC Jolt)
-		if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+		if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND NOT MINGW)
 			target_link_options(PerformanceTest PUBLIC "/SUBSYSTEM:CONSOLE")
 			target_link_options(PerformanceTest PUBLIC "/SUBSYSTEM:CONSOLE")
 		endif()
 		endif()
 		set_property(TARGET PerformanceTest PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${PHYSICS_REPO_ROOT}")
 		set_property(TARGET PerformanceTest PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${PHYSICS_REPO_ROOT}")

+ 8 - 0
Build/README.md

@@ -81,6 +81,14 @@ To implement your custom memory allocator override Allocate, Free, AlignedAlloca
 - Open the resulting project file VS2022_UWP\JoltPhysics.sln
 - Open the resulting project file VS2022_UWP\JoltPhysics.sln
 - Compile and run 'UnitTests'
 - Compile and run 'UnitTests'
 
 
+### Windows 10+ (MinGW)
+
+- Follow download instructions for MSYS2 (https://www.msys2.org/)
+- From the MSYS2 MSYS app run: pacman -S --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake
+- From the MSYS2 MINGW x64 app, in the Build folder run: ./cmake_mingw.sh
+- Run: cmake --build MinGW_Debug
+- Run: MinGW_Debug/UnitTests.exe
+
 ### Linux (Debian flavor, x64 or ARM64)
 ### Linux (Debian flavor, x64 or ARM64)
 
 
 - Install clang (apt-get install clang)
 - Install clang (apt-get install clang)

+ 19 - 0
Build/cmake_mingw.sh

@@ -0,0 +1,19 @@
+#!/bin/sh
+
+if [ -z $1 ] 
+then
+	BUILD_TYPE=Debug
+else
+	BUILD_TYPE=$1
+	shift
+fi
+
+BUILD_DIR=MinGW_$BUILD_TYPE
+
+echo Usage: ./cmake_mingw.sh [Configuration]
+echo "Possible configurations: Debug (default), Release, Distribution"
+echo Generating Makefile for build type \"$BUILD_TYPE\" in folder \"$BUILD_DIR\"
+
+cmake -S . -B $BUILD_DIR -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DTARGET_SAMPLES=OFF -DTARGET_VIEWER=OFF "${@}"
+
+echo Compile by running \"cmake --build $BUILD_DIR\"

+ 14 - 4
Jolt/Core/Core.h

@@ -35,6 +35,9 @@
 // Determine compiler
 // Determine compiler
 #if defined(__clang__)
 #if defined(__clang__)
 	#define JPH_COMPILER_CLANG
 	#define JPH_COMPILER_CLANG
+#elif defined(__MINGW64__) || defined (__MINGW32__)
+	#define JPH_COMPILER_GCC
+	#define JPH_COMPILER_MINGW
 #elif defined(__GNUC__)
 #elif defined(__GNUC__)
 	#define JPH_COMPILER_GCC
 	#define JPH_COMPILER_GCC
 #elif defined(_MSC_VER)
 #elif defined(_MSC_VER)
@@ -116,6 +119,11 @@
 #else
 #else
 #define JPH_GCC_SUPPRESS_WARNING(w)
 #define JPH_GCC_SUPPRESS_WARNING(w)
 #endif
 #endif
+#ifdef JPH_COMPILER_MINGW
+#define JPH_MINGW_SUPPRESS_WARNING(w)	JPH_PRAGMA(GCC diagnostic ignored w)
+#else
+#define JPH_MINGW_SUPPRESS_WARNING(w)
+#endif
 #ifdef JPH_COMPILER_MSVC
 #ifdef JPH_COMPILER_MSVC
 #define JPH_PRAGMA(x)					__pragma(x)
 #define JPH_PRAGMA(x)					__pragma(x)
 #define JPH_SUPPRESS_WARNING_PUSH		JPH_PRAGMA(warning (push))
 #define JPH_SUPPRESS_WARNING_PUSH		JPH_PRAGMA(warning (push))
@@ -152,6 +160,9 @@
 	JPH_GCC_SUPPRESS_WARNING("-Winvalid-offsetof")												\
 	JPH_GCC_SUPPRESS_WARNING("-Winvalid-offsetof")												\
 	JPH_GCC_SUPPRESS_WARNING("-Wclass-memaccess")												\
 	JPH_GCC_SUPPRESS_WARNING("-Wclass-memaccess")												\
 																								\
 																								\
+	JPH_MINGW_SUPPRESS_WARNING("-Wmaybe-uninitialized")										    \
+	JPH_MINGW_SUPPRESS_WARNING("-Wstringop-overflow=")										    \
+																								\
 	JPH_MSVC_SUPPRESS_WARNING(4514) /* 'X' : unreferenced inline function has been removed */	\
 	JPH_MSVC_SUPPRESS_WARNING(4514) /* 'X' : unreferenced inline function has been removed */	\
 	JPH_MSVC_SUPPRESS_WARNING(4710) /* 'X' : function not inlined */							\
 	JPH_MSVC_SUPPRESS_WARNING(4710) /* 'X' : function not inlined */							\
 	JPH_MSVC_SUPPRESS_WARNING(4711) /* function 'X' selected for automatic inline expansion */	\
 	JPH_MSVC_SUPPRESS_WARNING(4711) /* function 'X' selected for automatic inline expansion */	\
@@ -182,10 +193,6 @@
 	// (you only need to define JPH_BREAKPOINT, JPH_PLATFORM_BLUE_GET_TICKS and JPH_PLATFORM_BLUE_GET_TICK_FREQUENCY and include the right header).
 	// (you only need to define JPH_BREAKPOINT, JPH_PLATFORM_BLUE_GET_TICKS and JPH_PLATFORM_BLUE_GET_TICK_FREQUENCY and include the right header).
 	#include <Jolt/Core/PlatformBlue.h> 
 	#include <Jolt/Core/PlatformBlue.h> 
 #elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID) || defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS)
 #elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID) || defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS)
-	#include <float.h>
-	#include <limits.h>
-	#include <string.h>
-
 	#if defined(JPH_CPU_X86)
 	#if defined(JPH_CPU_X86)
 		#define JPH_BREAKPOINT		__asm volatile ("int $0x3")
 		#define JPH_BREAKPOINT		__asm volatile ("int $0x3")
 	#elif defined(JPH_CPU_ARM64)
 	#elif defined(JPH_CPU_ARM64)
@@ -228,6 +235,9 @@ JPH_SUPPRESS_WARNINGS_STD_BEGIN
 #include <sstream>
 #include <sstream>
 #include <functional>
 #include <functional>
 JPH_SUPPRESS_WARNINGS_STD_END
 JPH_SUPPRESS_WARNINGS_STD_END
+#include <limits.h>
+#include <float.h>
+#include <string.h>
 #if defined(JPH_USE_SSE)
 #if defined(JPH_USE_SSE)
 	#include <immintrin.h>
 	#include <immintrin.h>
 #elif defined(JPH_USE_NEON)
 #elif defined(JPH_USE_NEON)

+ 4 - 4
Jolt/Core/JobSystemThreadPool.cpp

@@ -482,7 +482,7 @@ void JobSystemThreadPool::QueueJobs(Job **inJobs, uint inNumJobs)
 	mSemaphore.Release(min(inNumJobs, (uint)mThreads.size()));
 	mSemaphore.Release(min(inNumJobs, (uint)mThreads.size()));
 }
 }
 
 
-#ifdef JPH_PLATFORM_WINDOWS
+#if defined(JPH_PLATFORM_WINDOWS) && !defined(JPH_COMPILER_MINGW) // MinGW doesn't support __try/__except
 
 
 // Sets the current thread name in MSVC debugger
 // Sets the current thread name in MSVC debugger
 static void SetThreadName(const char *inName)
 static void SetThreadName(const char *inName)
@@ -514,7 +514,7 @@ static void SetThreadName(const char *inName)
 	}
 	}
 }
 }
 
 
-#endif
+#endif // JPH_PLATFORM_WINDOWS && !JPH_COMPILER_MINGW
 
 
 void JobSystemThreadPool::ThreadMain(int inThreadIndex)
 void JobSystemThreadPool::ThreadMain(int inThreadIndex)
 {
 {
@@ -522,9 +522,9 @@ void JobSystemThreadPool::ThreadMain(int inThreadIndex)
 	char name[64];
 	char name[64];
 	snprintf(name, sizeof(name), "Worker %d", int(inThreadIndex + 1));
 	snprintf(name, sizeof(name), "Worker %d", int(inThreadIndex + 1));
 
 
-#ifdef JPH_PLATFORM_WINDOWS
+#if defined(JPH_PLATFORM_WINDOWS) && !defined(JPH_COMPILER_MINGW)
 	SetThreadName(name);
 	SetThreadName(name);
-#endif
+#endif // JPH_PLATFORM_WINDOWS && !JPH_COMPILER_MINGW
 
 
 	// Enable floating point exceptions
 	// Enable floating point exceptions
 	FPExceptionsEnable enable_exceptions;
 	FPExceptionsEnable enable_exceptions;

+ 2 - 2
Jolt/Core/STLAllocator.h

@@ -83,7 +83,7 @@ using IStringStream = basic_istringstream<char, char_traits<char>, STLAllocator<
 
 
 JPH_NAMESPACE_END
 JPH_NAMESPACE_END
 
 
-#if !defined(JPH_PLATFORM_WINDOWS) && !defined(JPH_DISABLE_CUSTOM_ALLOCATOR)
+#if (!defined(JPH_PLATFORM_WINDOWS) || defined(JPH_COMPILER_MINGW)) && !defined(JPH_DISABLE_CUSTOM_ALLOCATOR)
 
 
 namespace std
 namespace std
 {
 {
@@ -98,4 +98,4 @@ namespace std
 	};
 	};
 }
 }
 
 
-#endif // !JPH_PLATFORM_WINDOWS && !JPH_DISABLE_CUSTOM_ALLOCATOR
+#endif // (!JPH_PLATFORM_WINDOWS || JPH_COMPILER_MINGW) && !JPH_DISABLE_CUSTOM_ALLOCATOR

+ 3 - 3
Jolt/Physics/PhysicsSystem.h

@@ -240,6 +240,9 @@ private:
 
 
 	/// The broadphase does quick collision detection between body pairs
 	/// The broadphase does quick collision detection between body pairs
 	BroadPhase *				mBroadPhase = nullptr;
 	BroadPhase *				mBroadPhase = nullptr;
+    
+    /// Simulation settings
+	PhysicsSettings				mPhysicsSettings;
 
 
 	/// The contact manager resolves all contacts during a simulation step
 	/// The contact manager resolves all contacts during a simulation step
 	ContactConstraintManager	mContactManager;
 	ContactConstraintManager	mContactManager;
@@ -262,9 +265,6 @@ private:
 
 
 	/// Previous frame's delta time of one sub step to allow scaling previous frame's constraint impulses
 	/// Previous frame's delta time of one sub step to allow scaling previous frame's constraint impulses
 	float						mPreviousSubStepDeltaTime = 0.0f;
 	float						mPreviousSubStepDeltaTime = 0.0f;
-
-	/// Simulation settings
-	PhysicsSettings				mPhysicsSettings;
 };
 };
 
 
 JPH_NAMESPACE_END
 JPH_NAMESPACE_END

+ 1 - 0
TestFramework/Renderer/Renderer.h

@@ -10,6 +10,7 @@
 #include <Renderer/PipelineState.h>
 #include <Renderer/PipelineState.h>
 #include <Renderer/CommandQueue.h>
 #include <Renderer/CommandQueue.h>
 #include <Renderer/DescriptorHeap.h>
 #include <Renderer/DescriptorHeap.h>
+#include <memory>
 
 
 // Forward declares
 // Forward declares
 class Texture;
 class Texture;

+ 3 - 0
UnitTests/UnitTestFramework.cpp

@@ -7,6 +7,9 @@
 #include <Jolt/Core/FPException.h>
 #include <Jolt/Core/FPException.h>
 #include <Jolt/Core/Factory.h>
 #include <Jolt/Core/Factory.h>
 #include <Jolt/RegisterTypes.h>
 #include <Jolt/RegisterTypes.h>
+#ifdef JPH_PLATFORM_WINDOWS
+#include <crtdbg.h>
+#endif // JPH_PLATFORM_WINDOWS
 #ifdef JPH_PLATFORM_ANDROID
 #ifdef JPH_PLATFORM_ANDROID
 #include <Jolt/Core/Color.h>
 #include <Jolt/Core/Color.h>
 #include <android/log.h>
 #include <android/log.h>