Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Mac: Codify SDK and OS requirements, and clean up.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jorgenpt committed Jul 24, 2013
1 parent 82838e1 commit 140f063
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 159 deletions.
6 changes: 2 additions & 4 deletions build-scripts/g++-fat.sh
Expand Up @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions build-scripts/gcc-fat.sh
Expand Up @@ -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 \
Expand Down
8 changes: 4 additions & 4 deletions cmake/sdlchecks.cmake
Expand Up @@ -18,10 +18,10 @@ macro(CheckDLOPEN)
endif()
check_c_source_compiles("
#include <dlfcn.h>
#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()

Expand Down
5 changes: 2 additions & 3 deletions configure.in
Expand Up @@ -2129,9 +2129,8 @@ AC_HELP_STRING([--enable-sdl-dlopen], [use dlopen for shared object loading [[de
AC_TRY_COMPILE([
#include <dlfcn.h>
],[
#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
])
Expand Down
3 changes: 0 additions & 3 deletions include/SDL_config_macosx.h
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions include/SDL_platform.h
Expand Up @@ -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__) */

Expand Down
3 changes: 0 additions & 3 deletions src/audio/coreaudio/SDL_coreaudio.h
Expand Up @@ -32,9 +32,6 @@
#if MACOSX_COREAUDIO
#include <CoreAudio/CoreAudio.h>
#include <CoreServices/CoreServices.h>
#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
#include <AudioUnit/AUNTComponent.h>
#endif
#else
#include <AudioToolbox/AudioToolbox.h>
#endif
Expand Down
4 changes: 0 additions & 4 deletions src/video/cocoa/SDL_cocoaclipboard.m
Expand Up @@ -28,17 +28,13 @@
static NSString *
GetTextFormat(_THIS)
{
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;

if (data->osversion >= 0x1060) {
return NSPasteboardTypeString;
} else {
return NSStringPboardType;
}
#else
return NSStringPboardType;
#endif
}

int
Expand Down
74 changes: 3 additions & 71 deletions src/video/cocoa/SDL_cocoakeyboard.m
Expand Up @@ -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
Expand Down Expand Up @@ -486,39 +481,28 @@ - (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;
}
data->key_layout = key_layout;

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;
Expand Down Expand Up @@ -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
Expand Down
43 changes: 5 additions & 38 deletions src/video/cocoa/SDL_cocoamodes.m
Expand Up @@ -30,6 +30,9 @@
/* we need this for ShowMenuBar() and HideMenuBar(). */
#include <Carbon/Carbon.h>

/* This gets us MAC_OS_X_VERSION_MIN_REQUIRED... */
#include <AvailabilityMacros.h>

static inline void Cocoa_ToggleMenuBar(const BOOL show)
{
/* !!! FIXME: keep an eye on this.
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -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 *
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}
}
Expand All @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/video/cocoa/SDL_cocoashape.m
Expand Up @@ -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;
Expand Down
10 changes: 0 additions & 10 deletions src/video/cocoa/SDL_cocoavideo.h
Expand Up @@ -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;
Expand Down

0 comments on commit 140f063

Please sign in to comment.