Latest macOS system header causes compilation failures
Issue Description: Im unable to compile projects that uses SDL2 on latest MacOS. The current system header TargetConditionals.h seems to be incompatible with SDL
How to reproduce:
- Install MacOS 14.4.1
- Install SDL2 2.30.2 (for example via Homebrew)
- Create a project that uses SDL2
- Try to compile the project
- Get error:
In file included from /opt/homebrew/include/SDL2/SDL_platform.h:76,
from /opt/homebrew/include/SDL2/SDL_config.h:33,
from /opt/homebrew/include/SDL2/SDL_stdinc.h:31,
from /opt/homebrew/include/SDL2/SDL_main.h:25,
from /opt/homebrew/include/SDL2/SDL.h:32,
from src/pc/audio/audio_sdl2.c:3:
/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/TargetConditionals.h:140:50: error: missing binary operator before token "("
140 | #if !defined(__has_extension) || !__has_extension(define_target_os_macros)
| ^
What I expect: Use SDL in projects without modifying header files first.
Workaround: Change the following code in SDL_platform.h Before (with failure):
#if defined(__APPLE__)
/* lets us know what version of Mac OS X we're compiling on */
#include <AvailabilityMacros.h>
#include <TargetConditionals.h>
After (project builds fine):
#if defined(__APPLE__)
/* lets us know what version of Mac OS X we're compiling on */
#include <AvailabilityMacros.h>
# ifndef __has_extension
# define __has_extension(x) 0
# endif
#include <TargetConditionals.h>
Which compiler are you using that doesn't define __has_extension on macOS? I guess it's GCC?
Which compiler are you using that doesn't define
__has_extensionon macOS? I guess it's GCC?
It may be a clang version e.g. on linux being used as a cross-compiler.
# ifndef __has_extension # define __has_extension(x) 0 # endif
https://clang.llvm.org/docs/LanguageExtensions.html suggests __has_feature
as its replacement, so something like this maybe ??
diff --git a/include/SDL3/SDL_platform_defines.h b/include/SDL3/SDL_platform_defines.h
index de0908f..e582efd 100644
--- a/include/SDL3/SDL_platform_defines.h
+++ b/include/SDL3/SDL_platform_defines.h
@@ -65,6 +65,14 @@
#define SDL_PLATFORM_APPLE 1
/* lets us know what version of macOS we're compiling on */
#include <AvailabilityMacros.h>
+/* macOS 14 SDK has a problematic use of __has_extension in TargetConditionals.h: */
+#ifndef __has_extension
+# ifdef __has_feature
+# define __has_extension __has_feature
+# else
+# define __has_extension(x) 0
+# endif
+#endif
#include <TargetConditionals.h>
/* Fix building with older SDKs that don't define these
Let's make sure we undef that after the include, if we defined it, but otherwise I say we try this approach.
Let's make sure we undef that after the include, if we defined it, but otherwise I say we try this approach.
https://github.com/libsdl-org/SDL/pull/9832