Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest macOS system header causes compilation failures #9632

Closed
Traace opened this issue Apr 26, 2024 · 4 comments
Closed

Latest macOS system header causes compilation failures #9632

Traace opened this issue Apr 26, 2024 · 4 comments
Milestone

Comments

@Traace
Copy link

Traace commented Apr 26, 2024

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:

  1. Install MacOS 14.4.1
  2. Install SDL2 2.30.2 (for example via Homebrew)
  3. Create a project that uses SDL2
  4. Try to compile the project
  5. 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>
@slime73
Copy link
Contributor

slime73 commented Apr 26, 2024

Which compiler are you using that doesn't define __has_extension on macOS? I guess it's GCC?

@sezero
Copy link
Contributor

sezero commented Apr 26, 2024

Which compiler are you using that doesn't define __has_extension on 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

@slouken slouken added this to the 3.2.0 milestone Apr 26, 2024
@icculus
Copy link
Collaborator

icculus commented May 18, 2024

Let's make sure we undef that after the include, if we defined it, but otherwise I say we try this approach.

@sezero
Copy link
Contributor

sezero commented May 18, 2024

Let's make sure we undef that after the include, if we defined it, but otherwise I say we try this approach.

#9832

sezero added a commit to sezero/SDL that referenced this issue May 27, 2024
slouken added a commit that referenced this issue May 27, 2024
slouken added a commit that referenced this issue May 27, 2024
…(thanks @sezero!)

Fixes #9632

(cherry picked from commit 36015ad)
(cherry picked from commit 8bc47dc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants