Browse files

Can now build using cmake on OSX

Tested-by: Frost.
  • Loading branch information...
1 parent 067ad70 commit d18445a37c9f01c37238858dbceed7533f636aed @Socapex Socapex committed with Ablu Aug 13, 2012
Showing with 89 additions and 82 deletions.
  1. +2 −1 .gitignore
  2. +12 −0 README.cmake
  3. +10 −1 src/CMakeLists.txt
  4. +5 −0 src/SDLMain.h
  5. +60 −64 src/SDLMain.m
  6. +0 −4 src/gui/truetypefont.h
  7. +0 −4 src/resources/music.h
  8. +0 −4 src/resources/soundeffect.h
  9. +0 −4 src/sound.h
View
3 .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
View
12 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
View
11 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)
View
5 src/SDLMain.h
@@ -5,7 +5,12 @@
Feel free to customize this file to suit your needs
*/
+#ifndef _SDLMain_h_
+#define _SDLMain_h_
+
#import <Cocoa/Cocoa.h>
@interface SDLMain : NSObject
@end
+
+#endif /* _SDLMain_h_ */
View
124 src/SDLMain.m
@@ -1,14 +1,14 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
- Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
- Non-NIB-Code & other changes: Max Horn <max@quendi.de>
-
- Feel free to customize this file to suit your needs
- */
+ Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
+ Non-NIB-Code & other changes: Max Horn <max@quendi.de>
+
+ Feel free to customize this file to suit your needs
+*/
-#import "SDL.h"
-#import "SDLMain.h"
-#import <sys/param.h> /* for MAXPATHLEN */
-#import <unistd.h>
+#include "SDL.h"
+#include "SDLMain.h"
+#include <sys/param.h> /* for MAXPATHLEN */
+#include <unistd.h>
/* 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,27 +254,27 @@ - (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)
{
SDL_free(arg);
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,22 +362,20 @@ 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));
for (i = 0; i <= argc; i++)
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;
}
+
View
4 src/gui/truetypefont.h
@@ -25,15 +25,11 @@
#include <guichan/font.hpp>
-#ifdef __APPLE__
-#include <SDL/SDL_ttf.h>
-#else
#ifdef __WIN32__
#include <SDL/SDL_ttf.h>
#else
#include <SDL_ttf.h>
#endif
-#endif
#include <list>
#include <string>
View
4 src/resources/music.h
@@ -24,11 +24,7 @@
#include "resources/resource.h"
-#ifdef __APPLE__
-#include <SDL/SDL_mixer.h>
-#else
#include <SDL_mixer.h>
-#endif
/**
* Defines a class for loading and storing music.
View
4 src/resources/soundeffect.h
@@ -24,11 +24,7 @@
#include "resources/resource.h"
-#ifdef __APPLE__
-#include <SDL/SDL_mixer.h>
-#else
#include <SDL_mixer.h>
-#endif
/**
* Defines a class for loading and storing sound effects.
View
4 src/sound.h
@@ -22,11 +22,7 @@
#ifndef SOUND_H
#define SOUND_H
-#ifdef __APPLE__
-#include <SDL/SDL_mixer.h>
-#else
#include <SDL_mixer.h>
-#endif
#include <string>

0 comments on commit d18445a

Please sign in to comment.