Commit 170924278d6eeb2c617ef213e4d615605c3f0b5c

Sam Lantinga 2021-07-08T09:24:54

Fixed https://github.com/libsdl-org/SDL/issues/4475 -Wundef errors from clang-11.1 when targeting macOS Targeting i386 against 10.8 SDK: In file included from src/SDL_assert.c:21: In file included from src/./SDL_internal.h:52: In file included from include/SDL_config.h:33: include/SDL_platform.h:73:5: error: 'TARGET_OS_TV' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_] ^ 1 error generated. src/joystick/iphoneos/SDL_mfijoystick.m:38:5: error: 'TARGET_OS_IOS' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_] ^ src/joystick/iphoneos/SDL_mfijoystick.m:460:5: error: 'TARGET_OS_TV' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_] ^ 2 errors generated. src/filesystem/cocoa/SDL_sysfilesystem.m:83:6: error: 'TARGET_OS_TV' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_] ^ 1 error generated. Targeting x86_64 against 10.12 SDK: src/video/SDL_video.c:1492:25: error: 'TARGET_OS_MACCATALYST' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_] ^ 1 error generated.

diff --git a/include/SDL_platform.h b/include/SDL_platform.h
index ebaa252..b71d1bf 100644
--- a/include/SDL_platform.h
+++ b/include/SDL_platform.h
@@ -70,6 +70,24 @@
 /* lets us know what version of Mac OS X we're compiling on */
 #include "AvailabilityMacros.h"
 #include "TargetConditionals.h"
+
+/* Fix building with older SDKs that don't define these
+   See this for more information:
+   https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets
+*/
+#ifndef TARGET_OS_MACCATALYST
+#define TARGET_OS_MACCATALYST 0
+#endif
+#ifndef TARGET_OS_IOS
+#define TARGET_OS_IOS    0
+#endif
+#ifndef TARGET_OS_IPHONE
+#define TARGET_OS_IPHONE 0
+#endif
+#ifndef TARGET_OS_TV
+#define TARGET_OS_TV 0
+#endif
+
 #if TARGET_OS_TV
 #undef __TVOS__
 #define __TVOS__ 1