瀏覽代碼

Add MinGW cross compile for Linux (#207)

mrezai 3 年之前
父節點
當前提交
8b43fb806d

+ 15 - 1
Build/README.md

@@ -85,7 +85,7 @@ To implement your custom memory allocator override Allocate, Free, AlignedAlloca
 
 - 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
+- From the MSYS2 MINGW x64 app, in the Build folder run: ./cmake_windows_mingw.sh
 - Run: cmake --build MinGW_Debug
 - Run: MinGW_Debug/UnitTests.exe
 
@@ -97,6 +97,20 @@ To implement your custom memory allocator override Allocate, Free, AlignedAlloca
 - Go to the Linux_Debug folder
 - Run: make -j 8 && ./UnitTests
 
+### Linux (Debian flavor, MinGW Cross Compile)
+
+- This setup can be used to run samples on Linux using wine and vkd3d. Tested on Ubuntu 22.04
+- Graphics card must support Vulkan and related drivers must be installed
+- Install mingw-w64 (apt-get install mingw-w64)
+- Run: update-alternatives --config x86_64-w64-mingw32-g++ (Select /usr/bin/x86_64-w64-mingw32-g++-posix)
+- Install cmake (apt-get install cmake)
+- Install wine64 (apt-get install wine64)
+- Run: export WINEPATH="/usr/x86_64-w64-mingw32/lib;/usr/lib/gcc/x86_64-w64-mingw32/10-posix" (change it based on your environment)
+- Run: ./cmake_linux_mingw.sh Release (Debug doesn't work)
+- Go to the MinGW_Release folder
+- Run: make -j 8 && wine UnitTests.exe
+- Run: wine Samples.exe
+
 ### Android
 
 - Install Android Studio 2020.3.1+ (https://developer.android.com/studio/)

+ 19 - 0
Build/cmake_linux_mingw.sh

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

+ 1 - 1
Build/cmake_mingw.sh → Build/cmake_windows_mingw.sh

@@ -10,7 +10,7 @@ fi
 
 BUILD_DIR=MinGW_$BUILD_TYPE
 
-echo Usage: ./cmake_mingw.sh [Configuration]
+echo Usage: ./cmake_windows_mingw.sh [Configuration]
 echo "Possible configurations: Debug (default), Release, Distribution"
 echo Generating Makefile for build type \"$BUILD_TYPE\" in folder \"$BUILD_DIR\"
 

+ 23 - 0
Build/mingw-w64-x86_64.cmake

@@ -0,0 +1,23 @@
+# Sample toolchain file for building for Windows from an Ubuntu Linux system.
+#
+# Typical usage:
+#    *) install cross compiler: `sudo apt-get install mingw-w64`
+#    *) cd build
+#    *) cmake -DCMAKE_TOOLCHAIN_FILE=~/mingw-w64-x86_64.cmake ..
+
+set(CMAKE_SYSTEM_NAME Windows)
+set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
+
+# cross compilers to use for C, C++ and Fortran
+set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
+set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
+set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
+set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
+
+# target environment on the build host system
+set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
+
+# modify default behavior of FIND_XXX() commands
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

+ 5 - 0
Jolt/Core/JobSystemThreadPool.cpp

@@ -15,7 +15,12 @@ JPH_SUPPRESS_WARNINGS_STD_END
 	JPH_SUPPRESS_WARNING_PUSH
 	JPH_MSVC_SUPPRESS_WARNING(5039) // winbase.h(13179): warning C5039: 'TpSetCallbackCleanupGroup': pointer or reference to potentially throwing function passed to 'extern "C"' function under -EHc. Undefined behavior may occur if this function throws an exception.
 	#define WIN32_LEAN_AND_MEAN
+#ifndef JPH_COMPILER_MINGW
 	#include <Windows.h>
+#else
+	#include <windows.h>
+#endif
+
 	JPH_SUPPRESS_WARNING_POP
 #endif
 

+ 4 - 0
Jolt/Core/TickCounter.cpp

@@ -9,7 +9,11 @@
 	JPH_SUPPRESS_WARNING_PUSH
 	JPH_MSVC_SUPPRESS_WARNING(5039) // winbase.h(13179): warning C5039: 'TpSetCallbackCleanupGroup': pointer or reference to potentially throwing function passed to 'extern "C"' function under -EHc. Undefined behavior may occur if this function throws an exception.
 	#define WIN32_LEAN_AND_MEAN
+#ifndef JPH_COMPILER_MINGW
 	#include <Windows.h>
+#else
+	#include <windows.h>
+#endif
 	JPH_SUPPRESS_WARNING_POP
 #elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID)
 	#include <fstream>

+ 4 - 2
TestFramework/Renderer/Renderer.cpp

@@ -11,8 +11,10 @@
 #include <Utils/Log.h>
 
 #include <d3dcompiler.h>
-#include <d3d12sdklayers.h>
-#include <ShellScalingApi.h>
+#include <shellscalingapi.h>
+#ifdef _DEBUG
+	#include <d3d12sdklayers.h>
+#endif
 
 static Renderer *sRenderer = nullptr;