Skip to content

Commit

Permalink
Can now build using cmake on OSX
Browse files Browse the repository at this point in the history
Tested-by: Frost.
  • Loading branch information
Socapex authored and Erik Schilling committed Aug 14, 2012
1 parent 067ad70 commit d18445a
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 82 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -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
12 changes: 12 additions & 0 deletions README.cmake
Expand Up @@ -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
Expand Down Expand Up @@ -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
11 changes: 10 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions src/SDLMain.h
Expand Up @@ -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_ */
124 changes: 60 additions & 64 deletions 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
Expand All @@ -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);
Expand All @@ -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;
}

Expand All @@ -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
{
Expand All @@ -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
Expand All @@ -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]))
{
Expand All @@ -120,7 +119,6 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
if ([menuItem hasSubmenu])
[self fixMenu:[menuItem submenu] withAppName:appName];
}
[ aMenu sizeToFit ];
}

#else
Expand All @@ -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];
Expand All @@ -175,7 +173,7 @@ static void setupWindowMenu(void)
NSMenu *windowMenu;
NSMenuItem *windowMenuItem;
NSMenuItem *menuItem;

windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];

/* "Minimize" item */
Expand All @@ -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];
Expand All @@ -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
{
Expand All @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

4 changes: 0 additions & 4 deletions src/gui/truetypefont.h
Expand Up @@ -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>
Expand Down

0 comments on commit d18445a

Please sign in to comment.