When built with the right compiler, we don't need any Obj-C code.

develop
Timothy Collett 2012-05-29 14:44:37 -04:00
parent 7ec0fd6fc0
commit 20a00f53c4
3 changed files with 20 additions and 75 deletions

@ -49,10 +49,6 @@ SET(MAIN_HEADERS_WINDOWS
include/wdirent.h include/wdirent.h
) )
SET(MAIN_HEADERS_DARWIN
MacPool.h
)
SET(MAIN_SOURCES SET(MAIN_SOURCES
Core.cpp Core.cpp
ColorText.cpp ColorText.cpp
@ -95,13 +91,9 @@ Process-linux.cpp
SET(MAIN_SOURCES_DARWIN SET(MAIN_SOURCES_DARWIN
Console-darwin.cpp Console-darwin.cpp
Hooks-darwin.cpp
PlugLoad-darwin.cpp PlugLoad-darwin.cpp
Process-darwin.cpp Process-darwin.cpp
) Hooks-darwin.cpp
SET(OBJC_SOURCES_DARWIN
MacPool.mm
) )
SET(MAIN_SOURCES_LINUX_EGGY SET(MAIN_SOURCES_LINUX_EGGY
@ -172,11 +164,6 @@ IF(UNIX)
LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX_EGGY}) LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX_EGGY})
ELSEIF(APPLE) ELSEIF(APPLE)
LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_DARWIN}) LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_DARWIN})
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -m32 -march=i686 -mtune=generic")
SET(CPP_SOURCES)
LIST(APPEND CPP_SOURCES ${PROJECT_SOURCES})
LIST(APPEND PROJECT_SOURCES ${OBJC_SOURCES_DARWIN})
LIST(APPEND PROJECT_HEADERS ${MAIN_HEADERS_DARWIN})
ELSE() ELSE()
LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX}) LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX})
ENDIF() ENDIF()
@ -231,24 +218,6 @@ ELSE(WIN32)
PROPERTIES COMPILE_FLAGS "/O1 /bigobj") PROPERTIES COMPILE_FLAGS "/O1 /bigobj")
ENDIF() ENDIF()
if(APPLE)
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -m32 -mtune=generic" )
foreach(f ${PROJECT_SOURCES})
if(f MATCHES MacPool.mm)
MESSAGE(STATUS "Not setting properties for ${f}")
SET_SOURCE_FILES_PROPERTIES(${f} PROPERTIES COMPILE_FLAGS "-arch i386 -framework Foundation -x objective-c")
else()
if(f MATCHES MacPool.h)
else()
SET_SOURCE_FILES_PROPERTIES(${f} PROPERTIES COMPILE_FLAGS "-std=c++0x -march=i686")
MESSAGE(STATUS "Setting properties for ${f}")
endif()
endif()
endforeach()
SET_SOURCE_FILES_PROPERTIES(dfhack-run.cpp PROPERTIES COMPILE_FLAGS "-std=c++0x -march=i686")
SET(CMAKE_SHARED_LINKER_FLAGS "-arch i386")
endif()
# Compilation # Compilation
ADD_DEFINITIONS(-DBUILD_DFHACK_LIB) ADD_DEFINITIONS(-DBUILD_DFHACK_LIB)
@ -263,7 +232,6 @@ IF(UNIX)
SET(PROJECT_LIBS rt dl dfhack-md5 dfhack-tinyxml dfhack-tinythread) SET(PROJECT_LIBS rt dl dfhack-md5 dfhack-tinyxml dfhack-tinythread)
IF(APPLE) IF(APPLE)
SET(PROJECT_LIBS dl dfhack-md5 dfhack-tinyxml dfhack-tinythread) SET(PROJECT_LIBS dl dfhack-md5 dfhack-tinyxml dfhack-tinythread)
# include_directories(${CMAKE_INSTALL_PREFIX}/libs/SDL.framework/Headers)
ENDIF() ENDIF()
ELSE(WIN32) ELSE(WIN32)
#FIXME: do we really need psapi? #FIXME: do we really need psapi?
@ -301,6 +269,7 @@ IF(APPLE)
SET(SDL_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/SDL.framework) SET(SDL_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/SDL.framework)
TARGET_LINK_LIBRARIES(dfhack ${SDL_LIBRARY}) TARGET_LINK_LIBRARIES(dfhack ${SDL_LIBRARY})
TARGET_LINK_LIBRARIES(dfhack /System/Library/Frameworks/Foundation.framework) TARGET_LINK_LIBRARIES(dfhack /System/Library/Frameworks/Foundation.framework)
TARGET_LINK_LIBRARIES(dfhack /usr/lib/libc++.dylib)
SET_TARGET_PROPERTIES(dfhack PROPERTIES VERSION 1.0.0) SET_TARGET_PROPERTIES(dfhack PROPERTIES VERSION 1.0.0)
SET_TARGET_PROPERTIES(dfhack PROPERTIES SOVERSION 1.0.0) SET_TARGET_PROPERTIES(dfhack PROPERTIES SOVERSION 1.0.0)
ENDIF() ENDIF()

@ -58,9 +58,6 @@ distribution.
};*/ };*/
extern "C" int create_pool();
extern "C" int destroy_pool();
/******************************************************************************* /*******************************************************************************
* SDL part starts here * * SDL part starts here *
*******************************************************************************/ *******************************************************************************/
@ -82,8 +79,6 @@ DFhackCExport void SDL_Quit(void)
_SDL_Quit(); _SDL_Quit();
}*/ }*/
destroy_pool();
_SDL_Quit(); _SDL_Quit();
} }
@ -140,8 +135,6 @@ DFhackCExport int SDL_Init(uint32_t flags)
//freopen("stderr.log", "w", stderr); //freopen("stderr.log", "w", stderr);
// we don't reroute stdout until we figure out if this should be done at all // we don't reroute stdout until we figure out if this should be done at all
// See: Console-linux.cpp // See: Console-linux.cpp
create_pool();
// find real functions // find real functions
fprintf(stderr,"dfhack: saving real SDL functions\n"); fprintf(stderr,"dfhack: saving real SDL functions\n");
@ -163,7 +156,7 @@ DFhackCExport int SDL_Init(uint32_t flags)
} }
DFHack::Core & c = DFHack::Core::getInstance(); DFHack::Core & c = DFHack::Core::getInstance();
c.Init(); //c.Init();
int ret = _SDL_Init(flags); int ret = _SDL_Init(flags);
return ret; return ret;

@ -38,31 +38,16 @@ distribution.
#include <string> #include <string>
#include <map> #include <map>
typedef struct interpose_s
{
void *new_func;
void *orig_func;
} interpose_t;
#include "DFHack.h" #include "DFHack.h"
#include "Core.h" #include "Core.h"
#include "Hooks.h" #include "Hooks.h"
#include <iostream> #include <iostream>
static const interpose_t interposers[] __attribute__ ((section("__DATA, __interpose"))) =
{
{ (void *)DFH_SDL_Init, (void *)SDL_Init },
{ (void *)DFH_SDL_PollEvent, (void *)SDL_PollEvent },
{ (void *)DFH_SDL_Quit, (void *)SDL_Quit },
{ (void *)DFH_SDL_NumJoysticks, (void *)SDL_NumJoysticks },
};
/******************************************************************************* /*******************************************************************************
* SDL part starts here * * SDL part starts here *
*******************************************************************************/ *******************************************************************************/
// hook - called for each game tick (or more often) // hook - called for each game tick (or more often)
DFhackCExport int DFH_SDL_NumJoysticks(void) DFhackCExport int SDL_NumJoysticks(void)
{ {
DFHack::Core & c = DFHack::Core::getInstance(); DFHack::Core & c = DFHack::Core::getInstance();
return c.Update(); return c.Update();
@ -70,24 +55,23 @@ DFhackCExport int DFH_SDL_NumJoysticks(void)
// hook - called at program exit // hook - called at program exit
static void (*_SDL_Quit)(void) = 0; static void (*_SDL_Quit)(void) = 0;
DFhackCExport void DFH_SDL_Quit(void) DFhackCExport void SDL_Quit(void)
{ {
DFHack::Core & c = DFHack::Core::getInstance(); DFHack::Core & c = DFHack::Core::getInstance();
c.Shutdown(); c.Shutdown();
/*if(_SDL_Quit) if(_SDL_Quit)
{ {
_SDL_Quit(); _SDL_Quit();
}*/ }
SDL_Quit();
} }
// called by DF to check input events // called by DF to check input events
static int (*_SDL_PollEvent)(SDL_Event* event) = 0; static int (*_SDL_PollEvent)(SDL::Event* event) = 0;
DFhackCExport int DFH_SDL_PollEvent(SDL_Event* event) DFhackCExport int SDL_PollEvent(SDL::Event* event)
{ {
pollevent_again: pollevent_again:
// if SDL returns 0 here, it means there are no more events. return 0 // if SDL returns 0 here, it means there are no more events. return 0
int orig_return = SDL_PollEvent(event); int orig_return = _SDL_PollEvent(event);
if(!orig_return) if(!orig_return)
return 0; return 0;
// otherwise we have an event to filter // otherwise we have an event to filter
@ -95,7 +79,7 @@ DFhackCExport int DFH_SDL_PollEvent(SDL_Event* event)
{ {
DFHack::Core & c = DFHack::Core::getInstance(); DFHack::Core & c = DFHack::Core::getInstance();
// if we consume the event, ask SDL for more. // if we consume the event, ask SDL for more.
if(!c.DFH_SDL_Event(event)) if(!c.SDL_Event(event))
goto pollevent_again; goto pollevent_again;
} }
return orig_return; return orig_return;
@ -127,21 +111,20 @@ DFhackCExport int wgetch(WINDOW *win)
// hook - called at program start, initialize some stuffs we'll use later // hook - called at program start, initialize some stuffs we'll use later
static int (*_SDL_Init)(uint32_t flags) = 0; static int (*_SDL_Init)(uint32_t flags) = 0;
DFhackCExport int DFH_SDL_Init(uint32_t flags) DFhackCExport int SDL_Init(uint32_t flags)
{ {
// reroute stderr // reroute stderr
fprintf(stderr,"dfhack: attempting to hook in\n");
freopen("stderr.log", "w", stderr); freopen("stderr.log", "w", stderr);
// we don't reroute stdout until we figure out if this should be done at all // we don't reroute stdout until we figure out if this should be done at all
// See: Console-linux.cpp // See: Console-linux.cpp
// find real functions -- unnecessary in Mac OS X // find real functions
// _SDL_Init = (int (*)( uint32_t )) dlsym(RTLD_NEXT, "SDL_Init"); _SDL_Init = (int (*)( uint32_t )) dlsym(RTLD_NEXT, "SDL_Init");
// _SDL_Quit = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_Quit"); _SDL_Quit = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_Quit");
// _SDL_PollEvent = (int (*)(SDL::Event*))dlsym(RTLD_NEXT,"SDL_PollEvent"); _SDL_PollEvent = (int (*)(SDL::Event*))dlsym(RTLD_NEXT,"SDL_PollEvent");
// check if we got them // check if we got them
/* if(_SDL_Init && _SDL_Quit && _SDL_PollEvent) if(_SDL_Init && _SDL_Quit && _SDL_PollEvent)
{ {
fprintf(stderr,"dfhack: hooking successful\n"); fprintf(stderr,"dfhack: hooking successful\n");
} }
@ -150,11 +133,11 @@ DFhackCExport int DFH_SDL_Init(uint32_t flags)
// bail, this would be a disaster otherwise // bail, this would be a disaster otherwise
fprintf(stderr,"dfhack: something went horribly wrong\n"); fprintf(stderr,"dfhack: something went horribly wrong\n");
exit(1); exit(1);
}*/ }
/* /*
DFHack::Core & c = DFHack::Core::getInstance(); DFHack::Core & c = DFHack::Core::getInstance();
c.Init(); c.Init();
*/ */
int ret = SDL_Init(flags); int ret = _SDL_Init(flags);
return ret; return ret;
} }