diff --git a/.gitignore b/.gitignore index 36b1dea28..f37cd9f1a 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ docs/SOURCE/html/* # static libraries *.a -# Xcode settings +# OSX Xcode/mana.xcodeproj/xcuserdata Xcode/mana.xcodeproj/project.xcworkspace/xcuserdata +.DS_Store \ No newline at end of file diff --git a/README.cmake b/README.cmake index 8471473f8..c9175fa58 100644 --- a/README.cmake +++ b/README.cmake @@ -4,6 +4,7 @@ 2. How do I... 3. Crosscompiling using CMake 4. Creating an installer binary for Windows + 5. Building on OS X This readme explains the most common parameters to CMake needed for building mana, as well as setting up a cross build environement to @@ -134,3 +135,14 @@ $ makensis -DDLLDIR=/build/mana-libs/lib/ -DPRODUCT_VERSION=0.1.0.0 \ -DUPX=true -DEXESUFFIX=/src setup.nsi and end up with the installer in mana-0.1.0.0-win32.exe + +5. Building on OS X +------------------- + +In your mana directory: + +$ export CC=/usr/bin/clang +$ export CXX=/usr/bin/clang++ +$ cmake -DENABLE_CPP0X=OFF +$ make +$ src/mana diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b9aa6bb7b..f7483cfa7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -650,7 +650,16 @@ IF (WIN32) utils/specialfolder.h mana.rc ) -ENDIF () +ENDIF (WIN32) + +IF (APPLE) + SET(SRCS + ${SRCS} + log.mm + SDLMain.h + SDLMain.m + ) +ENDIF (APPLE) SET (PROGRAMS mana) diff --git a/src/SDLMain.h b/src/SDLMain.h index 4683df57a..c56d90cbe 100644 --- a/src/SDLMain.h +++ b/src/SDLMain.h @@ -5,7 +5,12 @@ Feel free to customize this file to suit your needs */ +#ifndef _SDLMain_h_ +#define _SDLMain_h_ + #import @interface SDLMain : NSObject @end + +#endif /* _SDLMain_h_ */ diff --git a/src/SDLMain.m b/src/SDLMain.m index d7e9273bc..2434f81aa 100644 --- a/src/SDLMain.m +++ b/src/SDLMain.m @@ -1,14 +1,14 @@ /* SDLMain.m - main entry point for our Cocoa-ized SDL app - Initial Version: Darrell Walisser - Non-NIB-Code & other changes: Max Horn - - Feel free to customize this file to suit your needs - */ + Initial Version: Darrell Walisser + Non-NIB-Code & other changes: Max Horn + + Feel free to customize this file to suit your needs +*/ -#import "SDL.h" -#import "SDLMain.h" -#import /* for MAXPATHLEN */ -#import +#include "SDL.h" +#include "SDLMain.h" +#include /* for MAXPATHLEN */ +#include /* For some reaon, Apple removed setAppleMenu from the headers in 10.4, but the method still is there and works. To avoid warnings, we declare @@ -25,10 +25,10 @@ - (void)setAppleMenu:(NSMenu *)menu; #ifdef SDL_USE_CPS /* Portions of CPS.h */ typedef struct CPSProcessSerNum - { - UInt32 lo; - UInt32 hi; - } CPSProcessSerNum; +{ + UInt32 lo; + UInt32 hi; +} CPSProcessSerNum; extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); @@ -43,17 +43,17 @@ - (void)setAppleMenu:(NSMenu *)menu; static NSString *getApplicationName(void) { - NSDictionary *dict; + const NSDictionary *dict; NSString *appName = 0; - + /* Determine the application name */ - dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); + dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); if (dict) appName = [dict objectForKey: @"CFBundleName"]; if (![appName length]) appName = [[NSProcessInfo processInfo] processName]; - + return appName; } @@ -64,10 +64,10 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; @end #endif -@interface SDLApplication : NSApplication +@interface NSApplication (SDLApplication) @end -@implementation SDLApplication +@implementation NSApplication (SDLApplication) /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { @@ -87,15 +87,14 @@ - (void) setupWorkingDirectory:(BOOL)shouldChdir if (shouldChdir) { char parentdir[MAXPATHLEN]; - CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); - CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); - if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) { - assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */ - } - CFRelease(url); - CFRelease(url2); - } - + CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); + if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) { + chdir(parentdir); /* chdir to the binary app's parent */ + } + CFRelease(url); + CFRelease(url2); + } } #if SDL_USE_NIB_FILE @@ -106,11 +105,11 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName NSRange aRange; NSEnumerator *enumerator; NSMenuItem *menuItem; - + aRange = [[aMenu title] rangeOfString:@"SDL App"]; if (aRange.length != 0) [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]]; - + enumerator = [[aMenu itemArray] objectEnumerator]; while ((menuItem = [enumerator nextObject])) { @@ -120,7 +119,6 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName if ([menuItem hasSubmenu]) [self fixMenu:[menuItem submenu] withAppName:appName]; } - [ aMenu sizeToFit ]; } #else @@ -139,31 +137,31 @@ static void setApplicationMenu(void) /* Add menu items */ title = [@"About " stringByAppendingString:appName]; [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; - + [appleMenu addItem:[NSMenuItem separatorItem]]; - + title = [@"Hide " stringByAppendingString:appName]; [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; - + menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; - + [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; - + [appleMenu addItem:[NSMenuItem separatorItem]]; - + title = [@"Quit " stringByAppendingString:appName]; [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; - + /* Put menu into the menubar */ menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; [menuItem setSubmenu:appleMenu]; [[NSApp mainMenu] addItem:menuItem]; - + /* Tell the application object that this is now the application menu */ [NSApp setAppleMenu:appleMenu]; - + /* Finally give up our references to the objects */ [appleMenu release]; [menuItem release]; @@ -175,7 +173,7 @@ static void setupWindowMenu(void) NSMenu *windowMenu; NSMenuItem *windowMenuItem; NSMenuItem *menuItem; - + windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; /* "Minimize" item */ @@ -190,7 +188,7 @@ static void setupWindowMenu(void) /* Tell the application object that this is now the window menu */ [NSApp setWindowsMenu:windowMenu]; - + /* Finally give up our references to the objects */ [windowMenu release]; [windowMenuItem release]; @@ -201,9 +199,9 @@ static void CustomApplicationMain (int argc, char **argv) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; SDLMain *sdlMain; - + /* Ensure the application object is initialised */ - [SDLApplication sharedApplication]; + [NSApplication sharedApplication]; #ifdef SDL_USE_CPS { @@ -212,15 +210,15 @@ static void CustomApplicationMain (int argc, char **argv) if (!CPSGetCurrentProcess(&PSN)) if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103)) if (!CPSSetFrontProcess(&PSN)) - [SDLApplication sharedApplication]; + [NSApplication sharedApplication]; } #endif /* SDL_USE_CPS */ - + /* Set up the menubar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; setApplicationMenu(); setupWindowMenu(); - + /* Create SDLMain and make it the app delegate */ sdlMain = [[SDLMain alloc] init]; [NSApp setDelegate:sdlMain]; @@ -256,19 +254,19 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam size_t arglen; char *arg; char **newargv; - + if (!gFinderLaunch) /* MacOS is passing command line args. */ return FALSE; - + if (gCalledAppMainline) /* app has started, ignore this document. */ return FALSE; - + temparg = [filename UTF8String]; arglen = SDL_strlen(temparg) + 1; arg = (char *) SDL_malloc(arglen); if (arg == NULL) return FALSE; - + newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2)); if (newargv == NULL) { @@ -276,7 +274,7 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam return FALSE; } gArgv = newargv; - + SDL_strlcpy(arg, temparg, arglen); gArgv[gArgc++] = arg; gArgv[gArgc] = NULL; @@ -288,19 +286,19 @@ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filenam - (void) applicationDidFinishLaunching: (NSNotification *) note { int status; - + /* Set the working directory to the .app's parent directory */ [self setupWorkingDirectory:gFinderLaunch]; - + #if SDL_USE_NIB_FILE /* Set the main menu to contain the real app name instead of "SDL App" */ [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()]; #endif - + /* Hand off to main application code */ gCalledAppMainline = TRUE; status = SDL_main (gArgc, gArgv); - + /* We're done, thank you for playing */ exit(status); } @@ -317,9 +315,9 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString unichar *buffer; NSRange localRange; NSString *result; - + bufferSize = selfLen + aStringLen - aRange.length; - buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar)); + buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar)); /* Get first part into buffer */ localRange.location = 0; @@ -330,7 +328,7 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString localRange.location = 0; localRange.length = aStringLen; [aString getCharacters:(buffer+aRange.location) range:localRange]; - + /* Get last part into buffer */ localRange.location = aRange.location + aRange.length; localRange.length = selfLen - localRange.location; @@ -364,9 +362,7 @@ int main (int argc, char **argv) gArgv[1] = NULL; gArgc = 1; gFinderLaunch = YES; - } - else - { + } else { int i; gArgc = argc; gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1)); @@ -374,12 +370,12 @@ int main (int argc, char **argv) gArgv[i] = argv[i]; gFinderLaunch = NO; } - + #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv); #endif return 0; } + diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index 97fd7f084..a01e2a62d 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -25,15 +25,11 @@ #include -#ifdef __APPLE__ -#include -#else #ifdef __WIN32__ #include #else #include #endif -#endif #include #include diff --git a/src/resources/music.h b/src/resources/music.h index bc2a56ae5..d370f0a53 100644 --- a/src/resources/music.h +++ b/src/resources/music.h @@ -24,11 +24,7 @@ #include "resources/resource.h" -#ifdef __APPLE__ -#include -#else #include -#endif /** * Defines a class for loading and storing music. diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h index decc60a00..38d586819 100644 --- a/src/resources/soundeffect.h +++ b/src/resources/soundeffect.h @@ -24,11 +24,7 @@ #include "resources/resource.h" -#ifdef __APPLE__ -#include -#else #include -#endif /** * Defines a class for loading and storing sound effects. diff --git a/src/sound.h b/src/sound.h index 180bca626..d4d0e8dac 100644 --- a/src/sound.h +++ b/src/sound.h @@ -22,11 +22,7 @@ #ifndef SOUND_H #define SOUND_H -#ifdef __APPLE__ -#include -#else #include -#endif #include