SDL: Fixed building on Windows with cmake, ninja, and clang

From a91ab883e970611cef0924df8aec7d264f93c8d1 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 6 Aug 2021 12:28:03 -0700
Subject: [PATCH] Fixed building on Windows with cmake, ninja, and clang

---
 CMakeLists.txt                           | 2 +-
 src/hidapi/windows/hid.c                 | 4 ++--
 src/main/windows/version.rc              | 2 +-
 src/render/direct3d11/SDL_render_d3d11.c | 4 +++-
 src/stdlib/SDL_string.c                  | 4 ++--
 src/video/SDL_blit_copy.c                | 2 +-
 6 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e6364f0ce..26fe83205 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -208,7 +208,7 @@ if(APPLE OR ARCH_64)
     set(OPT_DEF_SSEMATH ON)
   endif()
 endif()
-if(UNIX OR MINGW OR MSYS OR USE_CLANG OR VITA)
+if(UNIX OR MINGW OR MSYS OR (USE_CLANG AND NOT WINDOWS) OR VITA)
   set(OPT_DEF_LIBC ON)
 endif()
 
diff --git a/src/hidapi/windows/hid.c b/src/hidapi/windows/hid.c
index f508ee1f6..e6fbf85da 100644
--- a/src/hidapi/windows/hid.c
+++ b/src/hidapi/windows/hid.c
@@ -97,8 +97,8 @@ extern "C" {
 } /* extern "C" */
 #endif
 
-#include <stdio.h>
-#include <stdlib.h>
+/*#include <stdio.h>*/
+/*#include <stdlib.h>*/
 
 
 #include "../hidapi/hidapi.h"
diff --git a/src/main/windows/version.rc b/src/main/windows/version.rc
index dc5891227..2ce9cf0f0 100644
--- a/src/main/windows/version.rc
+++ b/src/main/windows/version.rc
@@ -25,7 +25,7 @@ BEGIN
             VALUE "FileDescription", "SDL\0"
             VALUE "FileVersion", "2, 0, 16, 0\0"
             VALUE "InternalName", "SDL\0"
-            VALUE "LegalCopyright", "Copyright  2021 Sam Lantinga\0"
+            VALUE "LegalCopyright", "Copyright (C) 2021 Sam Lantinga\0"
             VALUE "OriginalFilename", "SDL2.dll\0"
             VALUE "ProductName", "Simple DirectMedia Layer\0"
             VALUE "ProductVersion", "2, 0, 16, 0\0"
diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c
index b848dc32f..016ffc661 100644
--- a/src/render/direct3d11/SDL_render_d3d11.c
+++ b/src/render/direct3d11/SDL_render_d3d11.c
@@ -183,11 +183,13 @@ typedef struct
 
 static const GUID SDL_IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
 static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
+#if defined(__WINRT__) && NTDDI_VERSION > NTDDI_WIN8
 static const GUID SDL_IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } };
+#endif
 static const GUID SDL_IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } };
 static const GUID SDL_IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } };
 static const GUID SDL_IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } };
-static const GUID SDL_IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } };
+/*static const GUID SDL_IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } };*/
 
 #ifdef __GNUC__
 #pragma GCC diagnostic pop
diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c
index 877b453e7..ec43b1eca 100644
--- a/src/stdlib/SDL_string.c
+++ b/src/stdlib/SDL_string.c
@@ -281,7 +281,7 @@ SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
      * execute a 32-bit set. Set first bytes manually if needed until it is
      * aligned. */
     value1 = (Uint8)c;
-    while ((intptr_t)dstp1 & 0x3) {
+    while ((uintptr_t)dstp1 & 0x3) {
         if (len--) {
             *dstp1++ = value1;
         } else {
@@ -329,7 +329,7 @@ SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src,
        using Uint32* pointers, so we need to make sure the pointers are
        aligned before we loop using them.
      */
-    if (((intptr_t)src & 0x3) || ((intptr_t)dst & 0x3)) {
+    if (((uintptr_t)src & 0x3) || ((uintptr_t)dst & 0x3)) {
         /* Do an unaligned byte copy */
         Uint8 *srcp1 = (Uint8 *)src;
         Uint8 *dstp1 = (Uint8 *)dst;
diff --git a/src/video/SDL_blit_copy.c b/src/video/SDL_blit_copy.c
index 03a60f9b3..8788c34c2 100644
--- a/src/video/SDL_blit_copy.c
+++ b/src/video/SDL_blit_copy.c
@@ -34,7 +34,7 @@ SDL_memcpySSE(Uint8 * dst, const Uint8 * src, int len)
 
     __m128 values[4];
     for (i = len / 64; i--;) {
-        _mm_prefetch(src, _MM_HINT_NTA);
+        _mm_prefetch((const char *)src, _MM_HINT_NTA);
         values[0] = *(__m128 *) (src + 0);
         values[1] = *(__m128 *) (src + 16);
         values[2] = *(__m128 *) (src + 32);