From 140f0638eac16d28ef02bc0430f8ba42154118a8 Mon Sep 17 00:00:00 2001 From: "J?rgen P. Tjern?" Date: Tue, 23 Jul 2013 17:38:59 -0700 Subject: [PATCH] Mac: Codify SDK and OS requirements, and clean up. This #errors if you're using an SDK or deployment target that is less than 10.6 and 10.5, respectively, and cleans up uses of MAC_OS_X_VERSION_MIN_REQUIRED and MAC_OS_X_VERSION_MAX_ALLOWED according to those requirements. --- build-scripts/g++-fat.sh | 6 +-- build-scripts/gcc-fat.sh | 7 ++- cmake/sdlchecks.cmake | 8 +-- configure.in | 5 +- include/SDL_config_macosx.h | 3 -- include/SDL_platform.h | 6 +++ src/audio/coreaudio/SDL_coreaudio.h | 3 -- src/video/cocoa/SDL_cocoaclipboard.m | 4 -- src/video/cocoa/SDL_cocoakeyboard.m | 74 ++-------------------------- src/video/cocoa/SDL_cocoamodes.m | 43 ++-------------- src/video/cocoa/SDL_cocoashape.m | 8 +-- src/video/cocoa/SDL_cocoavideo.h | 10 ---- src/video/cocoa/SDL_cocoawindow.h | 5 -- src/video/cocoa/SDL_cocoawindow.m | 7 --- 14 files changed, 30 insertions(+), 159 deletions(-) diff --git a/build-scripts/g++-fat.sh b/build-scripts/g++-fat.sh index 3c4cab717..6e4f53e7c 100755 --- a/build-scripts/g++-fat.sh +++ b/build-scripts/g++-fat.sh @@ -7,15 +7,13 @@ DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer" # Intel 32-bit compiler flags (10.6 runtime compatibility) -GCC_COMPILE_X86="g++ -arch i386 -mmacosx-version-min=10.6 \ --DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \ +GCC_COMPILE_X86="g++ -arch i386 -mmacosx-version-min=10.5 \ -I/usr/local/include" -GCC_LINK_X86="-mmacosx-version-min=10.6" +GCC_LINK_X86="-mmacosx-version-min=10.5" # Intel 64-bit compiler flags (10.6 runtime compatibility) GCC_COMPILE_X64="g++ -arch x86_64 -mmacosx-version-min=10.6 \ --DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \ -I/usr/local/include" GCC_LINK_X64="-mmacosx-version-min=10.6" diff --git a/build-scripts/gcc-fat.sh b/build-scripts/gcc-fat.sh index 1601c9db8..edabb0d87 100755 --- a/build-scripts/gcc-fat.sh +++ b/build-scripts/gcc-fat.sh @@ -6,12 +6,11 @@ DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer" -# Intel 32-bit compiler flags (10.6 runtime compatibility) -GCC_COMPILE_X86="gcc -arch i386 -mmacosx-version-min=10.6 \ --DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \ +# Intel 32-bit compiler flags (10.5 runtime compatibility) +GCC_COMPILE_X86="gcc -arch i386 -mmacosx-version-min=10.5 \ -I/usr/local/include" -GCC_LINK_X86="-mmacosx-version-min=10.6" +GCC_LINK_X86="-mmacosx-version-min=10.5" # Intel 64-bit compiler flags (10.6 runtime compatibility) GCC_COMPILE_X64="gcc -arch x86_64 -mmacosx-version-min=10.6 \ diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake index 7cabbc60c..4d7e34d4e 100644 --- a/cmake/sdlchecks.cmake +++ b/cmake/sdlchecks.cmake @@ -18,10 +18,10 @@ macro(CheckDLOPEN) endif() check_c_source_compiles(" #include - #if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED <= 1020 - #error Use dlcompat for Mac OS X 10.2 compatibility - #endif - int main(int argc, char **argv) {}" HAVE_DLOPEN) + int main(int argc, char **argv) { + void *handle = dlopen("", RTLD_NOW); + const char *loaderror = (char *) dlerror(); + }" HAVE_DLOPEN) set(CMAKE_REQUIRED_LIBRARIES) endif() diff --git a/configure.in b/configure.in index 3346985ea..d2bd7a3d5 100644 --- a/configure.in +++ b/configure.in @@ -2129,9 +2129,8 @@ AC_HELP_STRING([--enable-sdl-dlopen], [use dlopen for shared object loading [[de AC_TRY_COMPILE([ #include ],[ - #if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED <= 1020 - #error Use dlcompat for Mac OS X 10.2 compatibility - #endif + void *handle = dlopen("", RTLD_NOW); + const char *loaderror = (char *) dlerror(); ],[ have_dlopen=yes ]) diff --git a/include/SDL_config_macosx.h b/include/SDL_config_macosx.h index a2d227478..68a0ebb9b 100644 --- a/include/SDL_config_macosx.h +++ b/include/SDL_config_macosx.h @@ -36,10 +36,7 @@ #endif /* Useful headers */ -/* If we specified an SDK or have a post-PowerPC chip, then alloca.h exists. */ -#if ( (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030) || (!defined(__POWERPC__)) ) #define HAVE_ALLOCA_H 1 -#endif #define HAVE_SYS_TYPES_H 1 #define HAVE_STDIO_H 1 #define STDC_HEADERS 1 diff --git a/include/SDL_platform.h b/include/SDL_platform.h index f4f23c41a..1e8e0d9f4 100644 --- a/include/SDL_platform.h +++ b/include/SDL_platform.h @@ -83,6 +83,12 @@ /* if not compiling for iPhone */ #undef __MACOSX__ #define __MACOSX__ 1 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050 +# error SDL for Mac OS X only supports deploying on 10.5 and above. +#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1050 */ +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 +# error SDL for Mac OS X must be built with a 10.6 SDK or above. +#endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1060 */ #endif /* TARGET_OS_IPHONE */ #endif /* defined(__APPLE__) */ diff --git a/src/audio/coreaudio/SDL_coreaudio.h b/src/audio/coreaudio/SDL_coreaudio.h index a05d4504f..2f0db5ba8 100644 --- a/src/audio/coreaudio/SDL_coreaudio.h +++ b/src/audio/coreaudio/SDL_coreaudio.h @@ -32,9 +32,6 @@ #if MACOSX_COREAUDIO #include #include -#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050 -#include -#endif #else #include #endif diff --git a/src/video/cocoa/SDL_cocoaclipboard.m b/src/video/cocoa/SDL_cocoaclipboard.m index 27d222769..ab31031b4 100644 --- a/src/video/cocoa/SDL_cocoaclipboard.m +++ b/src/video/cocoa/SDL_cocoaclipboard.m @@ -28,7 +28,6 @@ static NSString * GetTextFormat(_THIS) { -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; if (data->osversion >= 0x1060) { @@ -36,9 +35,6 @@ } else { return NSStringPboardType; } -#else - return NSStringPboardType; -#endif } int diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index 705b0358d..698343058 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -172,14 +172,9 @@ - (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange return nil; } -/* Needs long instead of NSInteger for compilation on Mac OS X 10.4 */ -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050 -- (long) conversationIdentifier -#else - (NSInteger) conversationIdentifier -#endif { - return (long) self; + return (NSInteger) self; } /* This method returns the index for character that is @@ -486,22 +481,14 @@ - (NSArray *) validAttributesForMarkedText static void UpdateKeymap(SDL_VideoData *data) { -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 TISInputSourceRef key_layout; -#else - KeyboardLayoutRef key_layout; -#endif const void *chr_data; int i; SDL_Scancode scancode; SDL_Keycode keymap[SDL_NUM_SCANCODES]; /* See if the keymap needs to be updated */ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 key_layout = TISCopyCurrentKeyboardLayoutInputSource(); -#else - KLGetCurrentKeyboardLayout(&key_layout); -#endif if (key_layout == data->key_layout) { return; } @@ -509,16 +496,13 @@ - (NSArray *) validAttributesForMarkedText SDL_GetDefaultKeymap(keymap); - /* Try Unicode data first (preferred as of Mac OS X 10.5) */ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 + /* Try Unicode data first */ CFDataRef uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData); if (uchrDataRef) chr_data = CFDataGetBytePtr(uchrDataRef); else goto cleanup; -#else - KLGetKeyboardLayoutProperty(key_layout, kKLuchrData, &chr_data); -#endif + if (chr_data) { UInt32 keyboard_type = LMGetKbdType(); OSStatus err; @@ -552,60 +536,8 @@ - (NSArray *) validAttributesForMarkedText return; } -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 cleanup: CFRelease(key_layout); -#else - /* Fall back to older style key map data */ - KLGetKeyboardLayoutProperty(key_layout, kKLKCHRData, &chr_data); - if (chr_data) { - for (i = 0; i < 128; i++) { - UInt32 c, state = 0; - - /* Make sure this scancode is a valid character scancode */ - scancode = darwin_scancode_table[i]; - if (scancode == SDL_SCANCODE_UNKNOWN || - (keymap[scancode] & SDLK_SCANCODE_MASK)) { - continue; - } - - c = KeyTranslate (chr_data, i, &state) & 255; - if (state) { - /* Dead key, process key up */ - c = KeyTranslate (chr_data, i | 128, &state) & 255; - } - - if (c != 0 && c != 0x10) { - /* MacRoman to Unicode table, taken from X.org sources */ - static const unsigned short macroman_table[128] = { - 0xc4, 0xc5, 0xc7, 0xc9, 0xd1, 0xd6, 0xdc, 0xe1, - 0xe0, 0xe2, 0xe4, 0xe3, 0xe5, 0xe7, 0xe9, 0xe8, - 0xea, 0xeb, 0xed, 0xec, 0xee, 0xef, 0xf1, 0xf3, - 0xf2, 0xf4, 0xf6, 0xf5, 0xfa, 0xf9, 0xfb, 0xfc, - 0x2020, 0xb0, 0xa2, 0xa3, 0xa7, 0x2022, 0xb6, 0xdf, - 0xae, 0xa9, 0x2122, 0xb4, 0xa8, 0x2260, 0xc6, 0xd8, - 0x221e, 0xb1, 0x2264, 0x2265, 0xa5, 0xb5, 0x2202, 0x2211, - 0x220f, 0x3c0, 0x222b, 0xaa, 0xba, 0x3a9, 0xe6, 0xf8, - 0xbf, 0xa1, 0xac, 0x221a, 0x192, 0x2248, 0x2206, 0xab, - 0xbb, 0x2026, 0xa0, 0xc0, 0xc3, 0xd5, 0x152, 0x153, - 0x2013, 0x2014, 0x201c, 0x201d, 0x2018, 0x2019, 0xf7, 0x25ca, - 0xff, 0x178, 0x2044, 0x20ac, 0x2039, 0x203a, 0xfb01, 0xfb02, - 0x2021, 0xb7, 0x201a, 0x201e, 0x2030, 0xc2, 0xca, 0xc1, - 0xcb, 0xc8, 0xcd, 0xce, 0xcf, 0xcc, 0xd3, 0xd4, - 0xf8ff, 0xd2, 0xda, 0xdb, 0xd9, 0x131, 0x2c6, 0x2dc, - 0xaf, 0x2d8, 0x2d9, 0x2da, 0xb8, 0x2dd, 0x2db, 0x2c7, - }; - - if (c >= 128) { - c = macroman_table[c - 128]; - } - keymap[scancode] = c; - } - } - SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES); - return; - } -#endif } void diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m index ad6ece279..f10e7ee20 100644 --- a/src/video/cocoa/SDL_cocoamodes.m +++ b/src/video/cocoa/SDL_cocoamodes.m @@ -30,6 +30,9 @@ /* we need this for ShowMenuBar() and HideMenuBar(). */ #include +/* This gets us MAC_OS_X_VERSION_MIN_REQUIRED... */ +#include + static inline void Cocoa_ToggleMenuBar(const BOOL show) { /* !!! FIXME: keep an eye on this. @@ -47,33 +50,13 @@ static inline void Cocoa_ToggleMenuBar(const BOOL show) /* !!! FIXME: clean out the pre-10.6 code when it makes sense to do so. */ -#define FORCE_OLD_API 0 || (MAC_OS_X_VERSION_MAX_ALLOWED < 1060) +#define FORCE_OLD_API 0 #if FORCE_OLD_API #undef MAC_OS_X_VERSION_MIN_REQUIRED #define MAC_OS_X_VERSION_MIN_REQUIRED 1050 #endif -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 -/* - Add methods to get at private members of NSScreen. - Since there is a bug in Apple's screen switching code - that does not update this variable when switching - to fullscreen, we'll set it manually (but only for the - main screen). -*/ -@interface NSScreen (NSScreenAccess) -- (void) setFrame:(NSRect)frame; -@end - -@implementation NSScreen (NSScreenAccess) -- (void) setFrame:(NSRect)frame; -{ - _frame = frame; -} -@end -#endif - static inline BOOL IS_SNOW_LEOPARD_OR_LATER(_THIS) { @@ -142,7 +125,6 @@ - (void) setFrame:(NSRect)frame; } data->moderef = moderef; - #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (IS_SNOW_LEOPARD_OR_LATER(_this)) { CGDisplayModeRef vidmode = (CGDisplayModeRef) moderef; CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode); @@ -162,7 +144,6 @@ - (void) setFrame:(NSRect)frame; CFRelease(fmt); } - #endif #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 if (!IS_SNOW_LEOPARD_OR_LATER(_this)) { @@ -201,23 +182,17 @@ - (void) setFrame:(NSRect)frame; static inline void Cocoa_ReleaseDisplayMode(_THIS, const void *moderef) { - /* We don't own moderef unless we use the 10.6+ APIs. */ - #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (IS_SNOW_LEOPARD_OR_LATER(_this)) { CGDisplayModeRelease((CGDisplayModeRef) moderef); /* NULL is ok */ } - #endif } static inline void Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist) { - /* We don't own modelis unless we use the 10.6+ APIs. */ - #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (IS_SNOW_LEOPARD_OR_LATER(_this)) { CFRelease(modelist); /* NULL is ok */ } - #endif } static const char * @@ -280,11 +255,9 @@ - (void) setFrame:(NSRect)frame; continue; } - #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (IS_SNOW_LEOPARD_OR_LATER(_this)) { moderef = CGDisplayCopyDisplayMode(displays[i]); } - #endif #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 if (!IS_SNOW_LEOPARD_OR_LATER(_this)) { @@ -344,11 +317,9 @@ - (void) setFrame:(NSRect)frame; SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; CFArrayRef modes = NULL; - #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (IS_SNOW_LEOPARD_OR_LATER(_this)) { modes = CGDisplayCopyAllDisplayModes(data->display, NULL); } - #endif #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 if (!IS_SNOW_LEOPARD_OR_LATER(_this)) { @@ -364,11 +335,9 @@ - (void) setFrame:(NSRect)frame; const void *moderef = CFArrayGetValueAtIndex(modes, i); SDL_DisplayMode mode; if (GetDisplayMode(_this, moderef, &mode)) { - #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (IS_SNOW_LEOPARD_OR_LATER(_this)) { CGDisplayModeRetain((CGDisplayModeRef) moderef); } - #endif SDL_AddDisplayMode(display, &mode); } } @@ -380,12 +349,10 @@ - (void) setFrame:(NSRect)frame; static CGError Cocoa_SwitchMode(_THIS, CGDirectDisplayID display, const void *mode) { - #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (IS_SNOW_LEOPARD_OR_LATER(_this)) { return CGDisplaySetDisplayMode(display, (CGDisplayModeRef) mode, NULL); } - #endif - + #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 if (!IS_SNOW_LEOPARD_OR_LATER(_this)) { return CGDisplaySwitchToMode(display, (CFDictionaryRef) mode); diff --git a/src/video/cocoa/SDL_cocoashape.m b/src/video/cocoa/SDL_cocoashape.m index 3cde7d048..1be93dedb 100644 --- a/src/video/cocoa/SDL_cocoashape.m +++ b/src/video/cocoa/SDL_cocoashape.m @@ -33,9 +33,11 @@ Cocoa_CreateShaper(SDL_Window* window) { SDL_WindowData* windata = (SDL_WindowData*)window->driverdata; [windata->nswindow setOpaque:NO]; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 - [windata->nswindow setStyleMask:NSBorderlessWindowMask]; -#endif + + if ([windata->nswindow respondsToSelector:@selector(setStyleMask:)]) { + [windata->nswindow setStyleMask:NSBorderlessWindowMask]; + } + SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper)); result->window = window; result->mode.mode = ShapeModeDefault; diff --git a/src/video/cocoa/SDL_cocoavideo.h b/src/video/cocoa/SDL_cocoavideo.h index cde0a38cf..5f8be5316 100644 --- a/src/video/cocoa/SDL_cocoavideo.h +++ b/src/video/cocoa/SDL_cocoavideo.h @@ -39,16 +39,6 @@ #include "SDL_cocoaopengl.h" #include "SDL_cocoawindow.h" -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 -#if __LP64__ -typedef long NSInteger; -typedef unsigned long NSUInteger; -#else -typedef int NSInteger; -typedef unsigned int NSUInteger; -#endif -#endif - /* Private display data */ @class SDLTranslatorResponder; diff --git a/src/video/cocoa/SDL_cocoawindow.h b/src/video/cocoa/SDL_cocoawindow.h index d348c34d1..01ff63880 100644 --- a/src/video/cocoa/SDL_cocoawindow.h +++ b/src/video/cocoa/SDL_cocoawindow.h @@ -27,12 +27,7 @@ typedef struct SDL_WindowData SDL_WindowData; -/* *INDENT-OFF* */ -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 @interface Cocoa_WindowListener : NSResponder { -#else -@interface Cocoa_WindowListener : NSResponder { -#endif SDL_WindowData *_data; BOOL observingVisible; BOOL wasVisible; diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index a48a074ea..d94c56744 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -81,11 +81,9 @@ - (void)listen:(SDL_WindowData *)data [view setNextResponder:self]; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if ([view respondsToSelector:@selector(setAcceptsTouchEvents:)]) { [view setAcceptsTouchEvents:YES]; } -#endif } - (void)observeValueForKeyPath:(NSString *)keyPath @@ -450,7 +448,6 @@ - (void)touchesCancelledWithEvent:(NSEvent *) theEvent - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event { -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 NSSet *touches = 0; NSEnumerator *enumerator; NSTouch *touch; @@ -499,7 +496,6 @@ - (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event touch = (NSTouch*)[enumerator nextObject]; } -#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 */ } @end @@ -939,8 +935,6 @@ - (void)resetCursorRects void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) { - /* this message arrived in 10.6. You're out of luck on older OSes. */ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow; if ([nswindow respondsToSelector:@selector(setStyleMask:)]) { @@ -950,7 +944,6 @@ - (void)resetCursorRects } } [pool release]; -#endif } void