Make iOS/tvOS (uikit) SDL_main header-only

Also adjusted iOS demo's includes to <SDL3/..> and explicit SDL_main.h

untested, I don't have Xcode (or a Mac, for that matter)

The xcode projects (for both Xcode-iOS/ and Xcode/) will probably
have to be adjusted for the SDL_main changes to work, but now at least
the iOS demo source should work as is :)
This commit is contained in:
Daniel Gibson
2022-12-11 05:08:15 +01:00
committed by Sam Lantinga
parent 28ecbbf0b5
commit 8e0693c982
12 changed files with 58 additions and 48 deletions

View File

@@ -65,9 +65,8 @@
/* 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 libSDL_main.a, which includes a
stub main function that calls into the shared library to start execution.
To use it, just #include SDL_main.h in the source file that contains your
main() function.
See src/video/uikit/SDL_uikitappdelegate.m for more details.
*/
@@ -287,9 +286,10 @@ extern DECLSPEC void SDLCALL SDL_GDKSuspendComplete(void);
#if !defined(SDL_MAIN_HANDLED) && !defined(_SDL_MAIN_NOIMPL)
/* include header-only SDL_main implementations */
#if defined(__WIN32__) || defined(__GDK__) /* TODO: other platforms */
#if defined(__WIN32__) || defined(__GDK__) || defined(__IOS__) || defined(__TVOS__) /* TODO: other platforms */
#include <SDL3/SDL_main_impl.h>
#endif
#endif /* SDL_MAIN_HANDLED */
#endif /* SDL_main_h_ */

View File

@@ -103,7 +103,35 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
#define main SDL_main
/* end of __WIN32__ and __GDK__ impls */
#elif 1 /* TODO: next platform */
#elif defined(__IOS__) || defined(__TVOS__)
#ifdef main
# undef main
#endif /* main */
#include <SDL3/begin_code.h>
#ifdef __cplusplus
extern "C" {
#endif
int main(int argc, char *argv[])
{
return SDL_UIKitRunApp(argc, argv, SDL_main);
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#include <SDL3/close_code.h>
/* rename users main() function to SDL_main() so it can be called from the wrapper above */
#define main SDL_main
/* end of __IOS__ and __TVOS__ impls */
/* TODO: remaining platforms */
#endif /* __WIN32__ etc */