Skip to content

Commit

Permalink
Added support for building SDL as a dynamic library on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Mar 19, 2019
1 parent edebdeb commit de82759
Show file tree
Hide file tree
Showing 8 changed files with 775 additions and 7 deletions.
717 changes: 717 additions & 0 deletions Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj 100644 → 100755

Large diffs are not rendered by default.

Empty file modified Xcode/SDL/SDL.xcodeproj/project.pbxproj 100644 → 100755
Empty file.
24 changes: 21 additions & 3 deletions include/SDL_main.h
Expand Up @@ -55,6 +55,10 @@
/* On iOS SDL provides a main function that creates an application delegate
and starts the iOS application run loop.
If you link with SDL dynamically on iOS, the main function can't be in a
shared library, so you need to link with libSDLmain.a, which includes a
stub main function that calls into the shared library to start execution.
See src/video/uikit/SDL_uikitappdelegate.m for more details.
*/
#define SDL_MAIN_NEEDED
Expand Down Expand Up @@ -114,6 +118,7 @@
/**
* The prototype for the application's main() function
*/
typedef C_LINKAGE SDLMAIN_DECLSPEC int (*SDL_main_func)(int argc, char *argv[]);
extern C_LINKAGE SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]);


Expand All @@ -136,8 +141,7 @@ extern DECLSPEC void SDLCALL SDL_SetMainReady(void);
/**
* This can be called to set the application class at startup
*/
extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style,
void *hInst);
extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style, void *hInst);
extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);

#endif /* __WIN32__ */
Expand All @@ -153,10 +157,24 @@ extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
* \return 0 on success, -1 on failure. On failure, use SDL_GetError to retrieve more
* information on the failure.
*/
extern DECLSPEC int SDLCALL SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * reserved);
extern DECLSPEC int SDLCALL SDL_WinRTRunApp(SDL_main_func mainFunction, void * reserved);

#endif /* __WINRT__ */

#if defined(__IPHONEOS__)

/**
* \brief Initializes and launches an SDL application.
*
* \param argc The argc parameter from the application's main() function
* \param argv The argv parameter from the application's main() function
* \param mainFunction The SDL app's C-style main().
* \return the return value from mainFunction
*/
extern DECLSPEC int SDLCALL SDL_UIKitRunApp(int argc, char *argv[], SDL_main_func mainFunction);

#endif /* __IPHONEOS__ */


#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/winrt/SDL_winrtapp_common.cpp
Expand Up @@ -29,7 +29,7 @@
int (*WINRT_SDLAppEntryPoint)(int, char **) = NULL;

extern "C" DECLSPEC int
SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * xamlBackgroundPanel)
SDL_WinRTRunApp(SDL_main_func mainFunction, void * xamlBackgroundPanel)
{
if (xamlBackgroundPanel) {
return SDL_WinRTInitXAMLApp(mainFunction, xamlBackgroundPanel);
Expand Down Expand Up @@ -63,4 +63,4 @@ SDL_WinRTGetDeviceFamily()
#endif

return SDL_WINRT_DEVICEFAMILY_UNKNOWN;
}
}
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_overrides.h
Expand Up @@ -713,3 +713,4 @@
#define SDL_RenderCopyF SDL_RenderCopyF_REAL
#define SDL_RenderCopyExF SDL_RenderCopyExF_REAL
#define SDL_GetTouchDeviceType SDL_GetTouchDeviceType_REAL
#define SDL_UIKitRunApp SDL_UIKitRunApp_REAL
3 changes: 3 additions & 0 deletions src/dynapi/SDL_dynapi_procs.h
Expand Up @@ -767,3 +767,6 @@ SDL_DYNAPI_PROC(int,SDL_RenderFillRectsF,(SDL_Renderer *a, const SDL_FRect *b, i
SDL_DYNAPI_PROC(int,SDL_RenderCopyF,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_FRect *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_RenderCopyExF,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_FRect *d, const double e, const SDL_FPoint *f, const SDL_RendererFlip g),(a,b,c,d,e,f,g),return)
SDL_DYNAPI_PROC(SDL_TouchDeviceType,SDL_GetTouchDeviceType,(SDL_TouchID a),(a),return)
#ifdef __IPHONEOS__
SDL_DYNAPI_PROC(int,SDL_UIKitRunApp,(int a, char *b, SDL_main_func c),(a,b,c),return)
#endif
19 changes: 19 additions & 0 deletions src/main/uikit/SDL_uikit_main.c
@@ -0,0 +1,19 @@
/*
SDL_uiki_main.c, placed in the public domain by Sam Lantinga 3/18/2019
*/
#include "../../SDL_internal.h"

/* Include the SDL main definition header */
#include "SDL_main.h"

#ifdef main
#undef main
#endif

int
main(int argc, char *argv[])
{
return SDL_UIKitRunApp(argc, argv, SDL_main);
}

/* vi: set ts=4 sw=4 expandtab: */
14 changes: 12 additions & 2 deletions src/video/uikit/SDL_uikitappdelegate.m
Expand Up @@ -38,15 +38,25 @@
#undef main
#endif

static SDL_main_func forward_main;
static int forward_argc;
static char **forward_argv;
static int exit_status;

int main(int argc, char **argv)
#if defined(SDL_MAIN_NEEDED) && !defined(IOS_DYLIB)
/* SDL is being built as a static library, include main() */
int main(int argc, char *argv[])
{
return SDL_UIKitRunApp(argc, argv, SDL_main);
}
#endif /* SDL_MAIN_NEEDED && !IOS_DYLIB */

int SDL_UIKitRunApp(int argc, char *argv[], SDL_main_func mainFunction)
{
int i;

/* store arguments */
forward_main = mainFunction;
forward_argc = argc;
forward_argv = (char **)malloc((argc+1) * sizeof(char *));
for (i = 0; i < argc; i++) {
Expand Down Expand Up @@ -344,7 +354,7 @@ - (void)postFinishLaunch

/* run the user's application, passing argc and argv */
SDL_iPhoneSetEventPump(SDL_TRUE);
exit_status = SDL_main(forward_argc, forward_argv);
exit_status = forward_main(forward_argc, forward_argv);
SDL_iPhoneSetEventPump(SDL_FALSE);

if (launchWindow) {
Expand Down

0 comments on commit de82759

Please sign in to comment.