Implement MinGW build support
authorJoshua Ashton <joshua@froggi.es>
Mon, 19 Apr 2021 00:40:10 +0000 (01:40 +0100)
committerJoshua Ashton <joshua@froggi.es>
Mon, 19 Apr 2021 13:25:00 +0000 (14:25 +0100)
This commit adds support for building with the MinGW toolchain.

This is useful as it allows Windows builds of the CTS to be
built on Linux or other platforms.
This can then either be used on Windows natively, or under the Wine
translation layer.

It can be used by either specifying a MinGW toolchain in CMake
or using the x86_64-w64-mingw32-cmake wrapper.

Fixes: #125

Signed-off-by: Joshua Ashton <joshua@froggi.es>
14 files changed:
external/vulkancts/framework/vulkan/vkDefs.h
external/vulkancts/framework/vulkan/vkDefs.hpp
external/vulkancts/modules/vulkan/api/vktApiExternalMemoryTests.cpp
external/vulkancts/modules/vulkan/synchronization/vktSynchronizationWin32KeyedMutexTests.cpp
framework/delibs/cmake/CFlags.cmake
framework/delibs/cmake/Defs.cmake
framework/delibs/debase/deDefs.c
framework/delibs/decpp/deDirectoryIterator.hpp
framework/delibs/deutil/CMakeLists.txt
framework/delibs/deutil/deSocket.c
framework/platform/CMakeLists.txt
framework/platform/win32/tcuWGL.cpp
framework/platform/win32/tcuWin32Platform.cpp
framework/platform/win32/tcuWin32VulkanPlatform.cpp

index e211a5d..257fb15 100644 (file)
@@ -31,7 +31,7 @@
 #      define VKAPI_ATTR
 #endif
 
-#if (DE_OS == DE_OS_WIN32) && ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED))
+#if (DE_OS == DE_OS_WIN32) && ((defined(_MSC_VER) && _MSC_VER >= 800) || defined(__MINGW32__) || defined(_STDCALL_SUPPORTED))
 #      define VKAPI_CALL __stdcall
 #   define VKAPI_PTR  VKAPI_CALL
 #else
index 22dd256..7e38d84 100644 (file)
@@ -31,7 +31,7 @@
 #      define VKAPI_ATTR
 #endif
 
-#if (DE_OS == DE_OS_WIN32) && ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED))
+#if (DE_OS == DE_OS_WIN32) && ((defined(_MSC_VER) && _MSC_VER >= 800) || defined(__MINGW32__) || defined(_STDCALL_SUPPORTED))
 #      define VKAPI_CALL __stdcall
 #else
 #      define VKAPI_CALL
index bffc643..567b48f 100644 (file)
@@ -53,7 +53,7 @@
 #if (DE_OS == DE_OS_WIN32)
 #      define WIN32_LEAN_AND_MEAN
 #      include <windows.h>
-#      include <Dxgi1_2.h>
+#      include <dxgi1_2.h>
 #endif
 
 using tcu::TestLog;
index df2c9a1..4a286d4 100644 (file)
@@ -45,9 +45,9 @@
 #      define NOMINMAX
 #      include <windows.h>
 #      include <aclapi.h>
-#      include "VersionHelpers.h"
-#      include "d3d11_2.h"
-#      include "d3dcompiler.h"
+#      include <versionhelpers.h>
+#      include <d3d11_2.h>
+#      include <d3dcompiler.h>
 
 typedef HRESULT                                (WINAPI * LPD3DX11COMPILEFROMMEMORY)(LPCSTR,
                                                                                                                                 SIZE_T,
index b3abf72..cde5aa5 100644 (file)
@@ -79,3 +79,13 @@ elseif (DE_COMPILER_IS_MSC)
 else ()
        message(FATAL_ERROR "DE_COMPILER is not valid")
 endif ()
+
+if (DE_MINGW AND DE_PTR_SIZE EQUAL 8)
+       # Pass -mbig-obj to mingw gas on Win64. COFF has a 2**16 section limit, and
+       # on Win64, every COMDAT function creates at least 3 sections: .text, .pdata,
+       # and .xdata.
+       # Enable static libgcc and libstdc++ also to avoid needing to have
+       # Windows builds of the standard libraries distributed.
+       set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Wa,-mbig-obj -static -static-libgcc")
+       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj -static -static-libgcc -static-libstdc++")
+endif()
index e710856..c1da84b 100644 (file)
@@ -149,6 +149,14 @@ if (DE_OS_IS_ANDROID AND NOT DEFINED DE_ANDROID_API)
        set(DE_ANDROID_API 5)
 endif ()
 
+# MinGW
+if (CMAKE_CXX_COMPILER MATCHES ".*-mingw32-.*")
+       set(DE_MINGW 1)
+       set(BUILD_SHARED_LIBS OFF)
+else()
+       set(DE_MINGW 0)
+endif()
+
 message(STATUS "DE_OS          = ${DE_OS}")
 message(STATUS "DE_COMPILER    = ${DE_COMPILER}")
 message(STATUS "DE_CPU         = ${DE_CPU}")
@@ -157,6 +165,7 @@ message(STATUS "DE_DEBUG       = ${DE_DEBUG}")
 if (DE_OS_IS_ANDROID)
        message(STATUS "DE_ANDROID_API = ${DE_ANDROID_API}")
 endif ()
+message(STATUS "DE_MINGW       = ${DE_MINGW}")
 
 # Expose definitions
 if (DE_DEBUG)
@@ -167,6 +176,7 @@ add_definitions("-DDE_OS=${DE_OS}")
 add_definitions("-DDE_COMPILER=${DE_COMPILER}")
 add_definitions("-DDE_CPU=${DE_CPU}")
 add_definitions("-DDE_PTR_SIZE=${DE_PTR_SIZE}")
+add_definitions("-DDE_MINGW=${DE_MINGW}")
 
 if (DE_OS_IS_ANDROID)
        add_definitions("-DDE_ANDROID_API=${DE_ANDROID_API}")
index 09c1348..203ce0c 100644 (file)
@@ -120,7 +120,7 @@ void deAssertFail (const char* reason, const char* file, int line)
                assert(wreason);
 #      endif
        }
-#elif ((DE_OS == DE_OS_WIN32) && (DE_COMPILER == DE_COMPILER_CLANG))
+#elif ((DE_OS == DE_OS_WIN32) && (DE_COMPILER == DE_COMPILER_CLANG || DE_COMPILER == DE_COMPILER_GCC))
        _assert(reason, file, line);
 #elif (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS) || defined(__FreeBSD__)
        fprintf(stderr, "Assertion '%s' failed at %s:%d\n", reason, file, line);
index 6e5b04d..7fcec16 100644 (file)
@@ -31,7 +31,7 @@
 
 #if (DE_OS == DE_OS_WIN32 && DE_COMPILER == DE_COMPILER_MSC)
 #      define DE_DIRITER DE_DIRITER_WIN32
-#elif (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_SYMBIAN) || (DE_OS == DE_OS_IOS) || (DE_OS == DE_OS_QNX) || (DE_OS == DE_OS_WIN32 && DE_COMPILER == DE_COMPILER_CLANG)
+#elif (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_SYMBIAN) || (DE_OS == DE_OS_IOS) || (DE_OS == DE_OS_QNX) || (DE_OS == DE_OS_WIN32 && (DE_COMPILER == DE_COMPILER_CLANG || DE_COMPILER == DE_COMPILER_GCC))
 #      define DE_DIRITER DE_DIRITER_POSIX
 #endif
 
index fdfcb39..5d0fe2a 100644 (file)
@@ -36,7 +36,7 @@ if (DE_OS_IS_ANDROID)
 endif ()
 
 if (DE_OS_IS_WIN32)
-       set(DEUTIL_LIBS WS2_32)
+       set(DEUTIL_LIBS ${DEUTIL_LIBS} ws2_32)
 endif ()
 
 if (DE_OS_IS_UNIX OR DE_OS_IS_QNX)
index 97fc17e..fd69477 100644 (file)
@@ -159,9 +159,9 @@ deSocketProtocol deSocketAddress_getProtocol (const deSocketAddress* address)
 #if defined(DE_USE_WINSOCK)
 
        /* WinSock spesific. */
-#      include <WinSock2.h>
-#      include <WS2tcpip.h>
-#      include <WinDef.h>
+#      include <winsock2.h>
+#      include <ws2tcpip.h>
+#      include <windef.h>
 
 static deBool initWinsock (void)
 {
index 260950a..3a972cf 100644 (file)
@@ -178,3 +178,7 @@ if (DEQP_USE_X11)
                add_definitions(-DDEQP_SUPPORT_WAYLAND=1)
        endif ()
 endif ()
+
+if (DE_OS_IS_WIN32)
+       target_link_libraries(tcutil-platform "version")
+endif()
index e0c79b1..26dc96e 100644 (file)
@@ -35,7 +35,7 @@
 #include <iterator>
 #include <set>
 
-#include <WinGDI.h>
+#include <wingdi.h>
 
 // WGL_ARB_pixel_format
 #define WGL_NUMBER_PIXEL_FORMATS_ARB                           0x2000
index bd38dbd..fb87b1c 100644 (file)
 #include "tcuWin32EGLNativeDisplayFactory.hpp"
 #include "egluGLContextFactory.hpp"
 
+// MinGW doesn't define this in its headers, but
+// still has the export in the libs.
+extern "C" WINUSERAPI WINBOOL WINAPI SetProcessDPIAware(VOID);
+
 namespace tcu
 {
 namespace win32
index cf31dda..bfdc609 100644 (file)
@@ -33,8 +33,6 @@
 #include "deUniquePtr.hpp"
 #include "deMemory.h"
 
-#pragma comment(lib, "version.lib")
-
 namespace tcu
 {
 namespace win32