Updated Objective-C implementation to use ARC; removed i386 support

This commit is contained in:
Marco Antognini 2014-04-13 12:42:14 +02:00
parent ac28902b57
commit 0d47056132
10 changed files with 31 additions and 80 deletions

View File

@ -40,7 +40,7 @@ sfml_set_option(SFML_BUILD_DOC FALSE BOOL "TRUE to generate the API documentatio
if(SFML_OS_MACOSX) if(SFML_OS_MACOSX)
# add an option to build frameworks instead of dylibs (release only) # add an option to build frameworks instead of dylibs (release only)
sfml_set_option(SFML_BUILD_FRAMEWORKS FALSE BOOL "TRUE to build SFML as frameworks libraries (release only), FALSE to build according to BUILD_SHARED_LIBS") sfml_set_option(SFML_BUILD_FRAMEWORKS FALSE BOOL "TRUE to build SFML as frameworks libraries (release only), FALSE to build according to BUILD_SHARED_LIBS")
# add an option to let the user specify a custom directory for frameworks installation (SFML, sndfile, ...) # add an option to let the user specify a custom directory for frameworks installation (SFML, sndfile, ...)
sfml_set_option(CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" STRING "Frameworks installation directory") sfml_set_option(CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" STRING "Frameworks installation directory")
@ -101,6 +101,12 @@ if(SFML_OS_MACOSX)
return() return()
endif() endif()
endif() endif()
# Objective-C ARC requires a 64 bit runtime.
if(NOT CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
message(FATAL_ERROR "CMAKE_OSX_ARCHITECTURES should be 'x86_64' to support ARC")
return()
endif()
endif() endif()
if(SFML_OS_LINUX OR SFML_OS_FREEBSD) if(SFML_OS_LINUX OR SFML_OS_FREEBSD)
@ -161,7 +167,7 @@ else()
add_library(SFML ${SFML_SOURCES}) add_library(SFML ${SFML_SOURCES})
# edit target properties # edit target properties
set_target_properties(SFML PROPERTIES set_target_properties(SFML PROPERTIES
FRAMEWORK TRUE FRAMEWORK TRUE
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.SFML MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.SFML
@ -170,14 +176,14 @@ else()
PUBLIC_HEADER "${SFML_HEADERS}") PUBLIC_HEADER "${SFML_HEADERS}")
# add the remaining headers # add the remaining headers
add_custom_command(TARGET SFML add_custom_command(TARGET SFML
POST_BUILD POST_BUILD
COMMAND cp -r ${PROJECT_SOURCE_DIR}/include/SFML/* SFML.framework/Versions/${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}/Headers) COMMAND cp -r ${PROJECT_SOURCE_DIR}/include/SFML/* SFML.framework/Versions/${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}/Headers)
# adapt install directory to allow distributing dylibs/frameworks in users frameworks/application bundle # adapt install directory to allow distributing dylibs/frameworks in users frameworks/application bundle
# NOTE : it's not required to link agains SFML.framework # NOTE : it's not required to link agains SFML.framework
set_target_properties(SFML PROPERTIES set_target_properties(SFML PROPERTIES
BUILD_WITH_INSTALL_RPATH 1 BUILD_WITH_INSTALL_RPATH 1
INSTALL_NAME_DIR "@executable_path/../Frameworks") INSTALL_NAME_DIR "@executable_path/../Frameworks")
# install rule # install rule

View File

@ -61,6 +61,11 @@ macro(sfml_add_library target)
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden) set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden)
endif() endif()
# On OS X, use Objective-C ARC
if(SFML_OS_MACOSX)
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fobjc-arc)
endif()
# link the target to its SFML dependencies # link the target to its SFML dependencies
if(THIS_DEPENDS) if(THIS_DEPENDS)
target_link_libraries(${target} ${THIS_DEPENDS}) target_link_libraries(${target} ${THIS_DEPENDS})
@ -70,17 +75,17 @@ macro(sfml_add_library target)
if(SFML_OS_MACOSX AND BUILD_SHARED_LIBS) if(SFML_OS_MACOSX AND BUILD_SHARED_LIBS)
if(SFML_BUILD_FRAMEWORKS) if(SFML_BUILD_FRAMEWORKS)
# adapt target to build frameworks instead of dylibs # adapt target to build frameworks instead of dylibs
set_target_properties(${target} PROPERTIES set_target_properties(${target} PROPERTIES
FRAMEWORK TRUE FRAMEWORK TRUE
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.${target} MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.${target}
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
endif() endif()
# adapt install directory to allow distributing dylibs/frameworks in users frameworks/application bundle # adapt install directory to allow distributing dylibs/frameworks in users frameworks/application bundle
set_target_properties(${target} PROPERTIES set_target_properties(${target} PROPERTIES
BUILD_WITH_INSTALL_RPATH 1 BUILD_WITH_INSTALL_RPATH 1
INSTALL_NAME_DIR "@executable_path/../Frameworks") INSTALL_NAME_DIR "@executable_path/../Frameworks")
endif() endif()
@ -92,7 +97,7 @@ macro(sfml_add_library target)
# add the install rule # add the install rule
install(TARGETS ${target} install(TARGETS ${target}
RUNTIME DESTINATION bin COMPONENT bin RUNTIME DESTINATION bin COMPONENT bin
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT bin LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT bin
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} COMPONENT bin) FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} COMPONENT bin)

View File

@ -114,8 +114,6 @@ elseif(SFML_OS_MACOSX)
${SRCROOT}/OSX/WindowImplCocoa.hpp ${SRCROOT}/OSX/WindowImplCocoa.hpp
${SRCROOT}/OSX/WindowImplCocoa.mm ${SRCROOT}/OSX/WindowImplCocoa.mm
${SRCROOT}/OSX/WindowImplDelegateProtocol.h ${SRCROOT}/OSX/WindowImplDelegateProtocol.h
${SRCROOT}/OSX/AutoreleasePoolWrapper.h
${SRCROOT}/OSX/AutoreleasePoolWrapper.mm
) )
source_group("mac" FILES ${PLATFORM_SRC}) source_group("mac" FILES ${PLATFORM_SRC})
endif() endif()

View File

@ -57,7 +57,7 @@ namespace priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SFOpenGLView* getSFOpenGLViewFromSFMLWindow(const Window& window) SFOpenGLView* getSFOpenGLViewFromSFMLWindow(const Window& window)
{ {
id nsHandle = (id)window.getSystemHandle(); id nsHandle = (__bridge id)window.getSystemHandle();
// Get our SFOpenGLView from ... // Get our SFOpenGLView from ...
SFOpenGLView* view = nil; SFOpenGLView* view = nil;

View File

@ -63,17 +63,17 @@
// Application Menu (aka Apple Menu) // Application Menu (aka Apple Menu)
NSMenuItem* appleItem = [mainMenu addItemWithTitle:@"" action:nil keyEquivalent:@""]; NSMenuItem* appleItem = [mainMenu addItemWithTitle:@"" action:nil keyEquivalent:@""];
NSMenu* appleMenu = [[SFApplication createAppleMenu] autorelease]; NSMenu* appleMenu = [SFApplication createAppleMenu];
[appleItem setSubmenu:appleMenu]; [appleItem setSubmenu:appleMenu];
// File Menu // File Menu
NSMenuItem* fileItem = [mainMenu addItemWithTitle:@"" action:nil keyEquivalent:@""]; NSMenuItem* fileItem = [mainMenu addItemWithTitle:@"" action:nil keyEquivalent:@""];
NSMenu* fileMenu = [[SFApplication createFileMenu] autorelease]; NSMenu* fileMenu = [SFApplication createFileMenu];
[fileItem setSubmenu:fileMenu]; [fileItem setSubmenu:fileMenu];
// Window menu // Window menu
NSMenuItem* windowItem = [mainMenu addItemWithTitle:@"" action:nil keyEquivalent:@""]; NSMenuItem* windowItem = [mainMenu addItemWithTitle:@"" action:nil keyEquivalent:@""];
NSMenu* windowMenu = [[SFApplication createWindowMenu] autorelease]; NSMenu* windowMenu = [SFApplication createWindowMenu];
[windowItem setSubmenu:windowMenu]; [windowItem setSubmenu:windowMenu];
[NSApp setWindowsMenu:windowMenu]; [NSApp setWindowsMenu:windowMenu];
} }
@ -120,7 +120,7 @@
[appleMenu addItem:[NSMenuItem separatorItem]]; [appleMenu addItem:[NSMenuItem separatorItem]];
// SERVICES // SERVICES
NSMenu* serviceMenu = [[[NSMenu alloc] initWithTitle:@""] autorelease]; NSMenu* serviceMenu = [[NSMenu alloc] initWithTitle:@""];
NSMenuItem* serviceItem = [appleMenu addItemWithTitle:@"Services" NSMenuItem* serviceItem = [appleMenu addItemWithTitle:@"Services"
action:nil action:nil
keyEquivalent:@""]; keyEquivalent:@""];
@ -174,7 +174,6 @@
action:@selector(performClose:) action:@selector(performClose:)
keyEquivalent:@"w"]; keyEquivalent:@"w"];
[fileMenu addItem:closeItem]; [fileMenu addItem:closeItem];
[closeItem release];
return fileMenu; return fileMenu;
} }
@ -199,7 +198,6 @@
action:@selector(performMiniaturize:) action:@selector(performMiniaturize:)
keyEquivalent:@"m"]; keyEquivalent:@"m"];
[windowMenu addItem:minimizeItem]; [windowMenu addItem:minimizeItem];
[minimizeItem release];
// ZOOM // ZOOM
[windowMenu addItemWithTitle:@"Zoom" [windowMenu addItemWithTitle:@"Zoom"

View File

@ -30,8 +30,6 @@
#include <SFML/Window/OSX/WindowImplCocoa.hpp> #include <SFML/Window/OSX/WindowImplCocoa.hpp>
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#import <SFML/Window/OSX/AutoreleasePoolWrapper.h>
namespace sf namespace sf
{ {
namespace priv namespace priv
@ -43,9 +41,6 @@ SFContext::SFContext(SFContext* shared) :
m_view(0), m_view(0),
m_window(0) m_window(0)
{ {
// Ask for a pool.
retainPool();
// Create the context // Create the context
createContext(shared, createContext(shared,
VideoMode::getDesktopMode().bitsPerPixel, VideoMode::getDesktopMode().bitsPerPixel,
@ -59,9 +54,6 @@ SFContext::SFContext(SFContext* shared, const ContextSettings& settings,
m_view(0), m_view(0),
m_window(0) m_window(0)
{ {
// Ask for a pool.
retainPool();
// Create the context. // Create the context.
createContext(shared, bitsPerPixel, settings); createContext(shared, bitsPerPixel, settings);
@ -80,9 +72,6 @@ m_window(0)
// Ensure the process is setup in order to create a valid window. // Ensure the process is setup in order to create a valid window.
WindowImplCocoa::setUpProcess(); WindowImplCocoa::setUpProcess();
// Ask for a pool.
retainPool();
// Create the context. // Create the context.
createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, settings); createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, settings);
@ -102,12 +91,6 @@ m_window(0)
SFContext::~SFContext() SFContext::~SFContext()
{ {
[m_context clearDrawable]; [m_context clearDrawable];
[m_context release];
[m_view release]; // Might be nil but we don't care.
[m_window release]; // Idem.
releasePool();
} }
@ -210,9 +193,6 @@ void SFContext::createContext(SFContext* shared,
if (m_context == nil) if (m_context == nil)
sf::err() << "Error. Unable to create the context." << std::endl; sf::err() << "Error. Unable to create the context." << std::endl;
// Free up.
[pixFmt release];
// Save the settings. (OpenGL version is updated elsewhere.) // Save the settings. (OpenGL version is updated elsewhere.)
m_settings = settings; m_settings = settings;
} }

View File

@ -292,14 +292,7 @@ BOOL isValidTextUnicode(NSEvent* event);
// Unregister // Unregister
[self removeTrackingArea:m_trackingArea]; [self removeTrackingArea:m_trackingArea];
// Release attributes
[m_hiddenTextView release];
[m_silentResponder release];
[m_trackingArea release];
[self setRequesterTo:0]; [self setRequesterTo:0];
[super dealloc];
} }

View File

@ -44,7 +44,7 @@
m_requester = 0; m_requester = 0;
// Retain the view for our own use. // Retain the view for our own use.
m_view = [view retain]; m_view = view;
if (m_view == nil) if (m_view == nil)
{ {
@ -81,11 +81,6 @@
-(void)dealloc -(void)dealloc
{ {
[self closeWindow]; [self closeWindow];
[m_view release];
[m_oglView release];
[super dealloc];
} }
@ -101,7 +96,7 @@
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
-(sf::WindowHandle)getSystemHandle -(sf::WindowHandle)getSystemHandle
{ {
return m_view; return (__bridge sf::WindowHandle)m_view;
} }

View File

@ -77,7 +77,7 @@
m_fullscreenMode = new sf::VideoMode(); m_fullscreenMode = new sf::VideoMode();
// Retain the window for our own use. // Retain the window for our own use.
m_window = [window retain]; m_window = window;
if (m_window == nil) if (m_window == nil)
{ {
@ -254,12 +254,7 @@
[self closeWindow]; [self closeWindow];
[NSMenu setMenuBarVisible:YES]; [NSMenu setMenuBarVisible:YES];
[m_window release];
[m_oglView release];
delete m_fullscreenMode; delete m_fullscreenMode;
[super dealloc];
} }
@ -279,7 +274,7 @@
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
-(sf::WindowHandle)getSystemHandle -(sf::WindowHandle)getSystemHandle
{ {
return m_window; return (__bridge sf::WindowHandle)m_window;
} }
@ -446,10 +441,6 @@
// Set app icon. // Set app icon.
[[SFApplication sharedApplication] setApplicationIconImage:icon]; [[SFApplication sharedApplication] setApplicationIconImage:icon];
// Free up.
[icon release];
[bitmap release];
} }

View File

@ -30,7 +30,6 @@
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <SFML/System/String.hpp> #include <SFML/System/String.hpp>
#import <SFML/Window/OSX/AutoreleasePoolWrapper.h>
#import <SFML/Window/OSX/cpp_objc_conversion.h> #import <SFML/Window/OSX/cpp_objc_conversion.h>
#import <SFML/Window/OSX/SFApplication.h> #import <SFML/Window/OSX/SFApplication.h>
#import <SFML/Window/OSX/SFApplicationDelegate.h> #import <SFML/Window/OSX/SFApplicationDelegate.h>
@ -50,11 +49,8 @@ namespace priv
WindowImplCocoa::WindowImplCocoa(WindowHandle handle) : WindowImplCocoa::WindowImplCocoa(WindowHandle handle) :
m_showCursor(true) m_showCursor(true)
{ {
// Ask for a pool.
retainPool();
// Treat the handle as it real type // Treat the handle as it real type
id nsHandle = (id)handle; id nsHandle = (__bridge id)handle;
if ([nsHandle isKindOfClass:[NSWindow class]]) if ([nsHandle isKindOfClass:[NSWindow class]])
{ {
// We have a window. // We have a window.
@ -95,9 +91,6 @@ m_showCursor(true)
// Transform the app process. // Transform the app process.
setUpProcess(); setUpProcess();
// Ask for a pool.
retainPool();
m_delegate = [[SFWindowController alloc] initWithMode:mode andStyle:style]; m_delegate = [[SFWindowController alloc] initWithMode:mode andStyle:style];
[m_delegate changeTitle:sfStringToNSString(title)]; [m_delegate changeTitle:sfStringToNSString(title)];
[m_delegate setRequesterTo:this]; [m_delegate setRequesterTo:this];
@ -112,18 +105,10 @@ WindowImplCocoa::~WindowImplCocoa()
{ {
[m_delegate closeWindow]; [m_delegate closeWindow];
[m_delegate release];
// Put the next window in front, if any. // Put the next window in front, if any.
NSArray* windows = [NSApp orderedWindows]; NSArray* windows = [NSApp orderedWindows];
if ([windows count] > 0) if ([windows count] > 0)
[[windows objectAtIndex:0] makeKeyAndOrderFront:nil]; [[windows objectAtIndex:0] makeKeyAndOrderFront:nil];
releasePool();
drainPool(); // Make sure everything was freed
// This solve some issue when sf::Window::Create is called for the
// second time (nothing was render until the function was called again)
} }