mirror of https://github.com/libsdl-org/SDL
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:
parent
28ecbbf0b5
commit
8e0693c982
|
@ -4,7 +4,8 @@
|
|||
* use however you want
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <math.h>
|
||||
#include "common.h"
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "SDL.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
* use however you want
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_opengles.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <SDL3/SDL_opengles.h>
|
||||
#include "common.h"
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
* use however you want
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include "common.h"
|
||||
|
||||
#define NUM_HAPPY_FACES 100 /* number of faces to draw */
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
* use however you want
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include "common.h"
|
||||
|
||||
#define TEST_INPUT_RECT
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
* use however you want
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include "common.h"
|
||||
|
||||
#define NUM_CHANNELS 8 /* max number of sounds we can play at once */
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
* use however you want
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <time.h>
|
||||
#include "common.h"
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
* use however you want
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <math.h>
|
||||
#include "common.h"
|
||||
|
||||
|
|
|
@ -22,10 +22,9 @@ Using the Simple DirectMedia Layer for iOS
|
|||
5. Select the project in the main view, go to the "Build Settings" tab, select "All", and edit "Header Search Path" and drag over the SDL "Public Headers" folder from the left
|
||||
6. Select the project in the main view, go to the "Build Phases" tab, select "Link Binary With Libraries", and add SDL3.framework from "Framework-iOS"
|
||||
7. Select the project in the main view, go to the "General" tab, scroll down to "Frameworks, Libraries, and Embedded Content", and select "Embed & Sign" for the SDL library.
|
||||
8. In the main view, expand SDL -> Library Source -> main -> uikit and drag SDL_uikit_main.c into your game files
|
||||
9. Add the source files that you would normally have for an SDL program, making sure to have #include "SDL.h" at the top of the file containing your main() function.
|
||||
10. Add any assets that your application needs.
|
||||
11. Enjoy!
|
||||
8. Add the source files that you would normally have for an SDL program, making sure to have #include "SDL.h" at the top of the file containing your main() function.
|
||||
9. Add any assets that your application needs.
|
||||
10. Enjoy!
|
||||
|
||||
|
||||
TODO: Add information regarding App Store requirements such as icons, etc.
|
||||
|
@ -202,19 +201,9 @@ The xcframework target builds into a Products directory alongside the SDL.xcodep
|
|||
|
||||
This target requires Xcode 11 or later. The target will simply fail to build if attempted on older Xcodes.
|
||||
|
||||
In addition, on Apple platforms, main() cannot be in a dynamically loaded library. This means that iOS apps which used the statically-linked libSDL3.lib and now link with the xcframwork will need to define their own main() to call SDL_UIKitRunApp(), like this:
|
||||
|
||||
#ifndef SDL_MAIN_HANDLED
|
||||
#ifdef main
|
||||
#undef main
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
return SDL_UIKitRunApp(argc, argv, SDL_main);
|
||||
}
|
||||
#endif /* !SDL_MAIN_HANDLED */
|
||||
In addition, on Apple platforms, main() cannot be in a dynamically loaded library.
|
||||
However, unlike in SDL2, in SDL3 SDL_main is implemented inline in SDL_main.h, so you don't need to link against a static libSDL3main.lib, and you don't need to copy a .c file from the SDL3 source either.
|
||||
This means that iOS apps which used the statically-linked libSDL3.lib and now link with the xcframwork can just `#include <SDL3/SDL3_main.h>` in the source file that contains their standard `int main(int argc; char *argv[])` function to get a header-only SDL_main implementation that calls the `SDL_UIKitRunApp()` with your standard main function.
|
||||
|
||||
Using an xcFramework is similar to using a regular framework. However, issues have been seen with the build system not seeing the headers in the xcFramework. To remedy this, add the path to the xcFramework in your app's target ==> Build Settings ==> Framework Search Paths and mark it recursive (this is critical). Also critical is to remove "*.framework" from Build Settings ==> Sub-Directories to Exclude in Recursive Searches. Clean the build folder, and on your next build the build system should be able to see any of these in your code, as expected:
|
||||
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -1,22 +1,8 @@
|
|||
/*
|
||||
SDL_uikit_main.c, placed in the public domain by Sam Lantinga 3/18/2019
|
||||
|
||||
Nothing to do here, the code moved into SDL_main_impl.h
|
||||
TODO: remove this file
|
||||
*/
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h> /* until this SDL_main impl is converted to header-only.. */
|
||||
|
||||
#if defined(__IOS__) || defined(__TVOS__)
|
||||
|
||||
#ifndef SDL_MAIN_HANDLED
|
||||
#ifdef main
|
||||
#undef main
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return SDL_UIKitRunApp(argc, argv, SDL_main);
|
||||
}
|
||||
#endif /* !SDL_MAIN_HANDLED */
|
||||
|
||||
#endif /* __IOS__ || __TVOS__ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
Loading…
Reference in New Issue