SFML community forums

General => SFML development => Topic started by: Jonny on January 25, 2018, 10:12:51 pm

Title: iOS development progress
Post by: Jonny on January 25, 2018, 10:12:51 pm
As I've recently found myself with some free time I've been focussing on iOS stuff. I'm going to write down any tips or issues I find here, and hopefully make some progress towards proper iOS support in SFML. I'm mostly just using my SFML-DOOM project to test with, so I'd also like to gather together anyone who has a project they are currently developing for iOS, or plan to develop for iOS in the future.

SFML Installation:

Since the iOS toolchain has been added this is much simpler

cmake .. -GXcode -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/iOS.toolchain.cmake

To generate the example(s) add the usual flag -DSFML_BUILD_EXAMPLES=TRUE

then install as you would normally.

sudo cmake --build . --target install

Notes:

An iOS project using SFML:

If your project is also using cmake, it's just a case of copying the SFML toolchain file and using it in your project to generate the Xcode project.

You'll need to add some extra code to your CMakeLists to generate an app bundle, and set some Xcode parameters, e.g.:

if(APPLE)

    # Set some details for the app bundle. Without these my xcode crashes when debugging ios :S
    set(MACOSX_BUNDLE_IDENTIFIERcom.sfml.boop.SFML-APP)
    set(MACOSX_BUNDLE_NAME SFML-APP)

    set_source_files_properties( ${CMAKE_SOURCE_DIR}/apple/icon.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources )
    set_source_files_properties( ${CMAKE_SOURCE_DIR}/assets PROPERTIES MACOSX_PACKAGE_LOCATION Resources )

    #Include resources when creating executable
    add_executable(SFML-DOOM MACOSX_BUNDLE ${INCLUDE} ${SOURCE} ${CMAKE_SOURCE_DIR}/apple/icon.icns
    ${CMAKE_SOURCE_DIR}/assets)

    # Set the app bundle icon
    set_target_properties( SFML-DOOM PROPERTIES MACOSX_BUNDLE_ICON_FILE icon.icns )
endif()
 

Notes:

Outstanding issues/PR's (Please help test if you can!)

If you follow https://github.com/jonnyptn/sfml-doom I'll update that as I go along.

If anybody has an existing SFML project using cmake and are curious about an iOS build, feel free to mention it in here as I could use as many test projects as possible.

Version support:

These are the platforms and Xcode versions I've tested on, if you've had success with any others please comment here so I can add to the list:

iOS:

Xcode:
Title: Re: iOS development progress
Post by: Ceylo on January 28, 2018, 05:34:09 pm
This is really nice to get some kind of status about iOS development.
I've seen some IOS "if" conditions in CMake code but always wondered how to actually do an iOS build. Now I know :D

Is there a more or less defined list of what's left to do before it can be publicly released? I saw your notes but I don't expect them to be complete.

Are you the main maintainer of the iOS port? Are you currently working alone on it? Also I'm wondering, in case there were other maintainers in the past, who they were and up to where they went.

And one more question (sorry ;D ), how is the iOS port being made consistent with Android port? Both are mobile platforms and I'd expect that problems that affect one platform are very likely to affect the other one. So I'd expect kind of a synchronized development to ensure common API and shared solutions when appropriate.
Title: Re: iOS development progress
Post by: eXpl0it3r on January 28, 2018, 06:17:10 pm
Pretty much right after Laurent did the initial implementation of the iOS port, he said, he didn't want to maintain it. Ever since we haven't had any maintainer and generally the interest was quite low.
Jonny has been fixing up iOS in the past few weeks and I'd be happy to add him as iOS maintainer if he wishes it.

Android and iOS are build on completely different tech, so problems are most often not shared, unless they are of a architectural matter.
Given that we don't have anyone maintaining thr iOS code, there was so far no need for synchronization.
Title: Re: iOS development progress
Post by: Ceylo on January 28, 2018, 11:00:31 pm
Pretty much right after Laurent did the initial implementation of the iOS port, he said, he didn't want to maintain it. Ever since we haven't had any maintainer and generally the interest was quite low.
Oh ok. Do you know how far it went?

Jonny has been fixing up iOS in the past few weeks and I'd be happy to add him as iOS maintainer if he wishes it.
Now you've put pressure ;D (good luck Jonny)

Android and iOS are build on completely different tech, so problems are most often not shared, unless they are of a architectural matter.
Given that we don't have anyone maintaining thr iOS code, there was so far no need for synchronization.
Hmm I don't know enough about both platforms but my feeling says there is a lot to share: how to design the input API and the window API, how to deal with sandboxed resources (in terms of API), should it be a different API from SFML's desktop one, or just an extended one (probably with feature that wouldn't apply to desktop platforms). Things like that. As for the background stuff yeah it's very different, but that's just implementation detail, you're free to do what you want there, you don't need to talk to people (huhu) to decide what to do. So I find this part easier and less time consuming.

Of course if there's no maintainer there's no synchronization. I thought there was one :)
Title: Re: iOS development progress
Post by: eXpl0it3r on January 28, 2018, 11:24:23 pm
To my knowledge it's fully featured. The audio module is still disabled, but Jonny is looking into fixing this. The original reason was that we were using libsndfile which doesn't allow static linking (LGPL) which is required for iOS, but since we moved away from libsndfile this is working fine now (once the CMake bits are updated).

The API is non different to the desktop API, no idea if inner working concepts can be shared, but given the nature of two totally different architectures, I doubt there's that much in common. But I've little knowledge on either platform, so I'm not the best to answer here.
Title: Re: iOS development progress
Post by: Jonny on January 30, 2018, 07:13:51 am
The Audio module has been enabled for a few weeks now, so it's fully featured, and actually looks to be working really good for me right now, other than the afore-mentioned screen size/rotation issue

Can't commit to being maintainer right now, but I'll work on it as much as I can, and maybe the situation will change in future  :P. BlueCobold on IRC has been helping a lot too, although they haven't been able to reproduce the screen issue which is bothering me right now :S

I'm hoping this thread can help some more people to dive into iOS and get something working, I'll add some example cmake script to the OP to show how to set up the bundle properly for Xcode

Title: Re: iOS development progress
Post by: Ceylo on January 30, 2018, 10:04:24 pm
Tried a bit to have SFML compiled for iPhoneSimulator but it can't find OpenAL headers. I just set IOS_PLATFORM to SIMULATOR64 as you suggested in CMake GUI.
(click to show/hide)

In file included from /Users/ceylo/Development/SFML/src/SFML/Audio/ALCheck.cpp:28:
/Users/ceylo/Development/SFML/src/SFML/Audio/ALCheck.hpp:33:14: fatal error: 'OpenAl/al.h' file not found
    #include <OpenAl/al.h>
             ^~~~~~~~~~~~~
1 error generated.

I'm using Xcode 9.1 and current master branch of SFML repo. Not all changed to get it working are pushed to master branch?
Title: Re: iOS development progress
Post by: Foaly on January 30, 2018, 10:06:09 pm
Probably related to this PR: https://github.com/SFML/SFML/pull/1263


Something else I saw recently is that according to this commit message (https://github.com/SFML/SFML/commit/0637a2ef9938b842252056a1b2e69963391ed3ee) the iOS implementation of the Clipboard API was never tested at the time. So now that we have some developers using iOS it would be great if one of you could test it :)
Title: Re: iOS development progress
Post by: Hiura on January 31, 2018, 04:21:48 pm
Yeah, let me know if the clipboard feature works; I'm curious to know ^^


correct link: https://github.com/SFML/SFML/commit/0637a2ef9938b842252056a1b2e69963391ed3ee

Title: Re: iOS development progress
Post by: Jonny on February 01, 2018, 12:15:57 am
Just dropping by to say I’m offline this week due to moving house. Subject to Shaw engineers competency I should be back online on the 8th feb and will pick everything up again then.
Title: Re: iOS development progress
Post by: Ceylo on February 12, 2018, 10:33:57 pm
Hello,

I've tried again to build SFML for iOS but to me it looks like there are so many issues at the moment. Just to have it compile :(
- First when targeting a real device, it tries to compile for armv7 but emit compilation errors because it also targets the latest iOS for deployment target (iOS 11) which doesn't support armv7 (this is 32-bits arm). So I made change to have iOS 10 as deployment target for now.
- Then although the toolchain file sets CMAKE_OSX_ARCHITECTURES correctly, this is set when project(SFML) is called in main CMakeLists.txt, but at that time CMAKE_OSX_ARCHITECTURES is already set to x86_64. And by default CMake doesn't change already set cache entries. So you get a x86_64 build for your iOS device :D (have fixed that on my side too)
- Also I don't understand why find_host_package() is used to find dependencies, because from what I understand this means finding dependencies for the host platform, not the target platform. But when you build for an iOS device you need to build with dependencies made for the target platform. On the other side I can't get anything to work with find_package() so I guess find_host_package() exists for a reason ;D
- find_host_package() finds frameworks in /Library/Frameworks if I don't remove the vorbis, ogg and FLAC frameworks there, instead of choosing the static libraries from SFML's extlibs dir.

Apart from that it builds ;D

Edit: i've put my changes there for now: https://github.com/Ceylo/SFML/compare/feature/CMakeTargetExport...Ceylo:feature/iOSCompilation
Could get all examples to build (with a few tweaks related to OpenGL vs OpenGL ES) not comitted yet as it's WIP. It's based on my other branch because eventually it's easier to setup everything and propagates properties correctly.
Title: Re: iOS development progress
Post by: Jonny on February 16, 2018, 03:10:06 am
I'm back online now, so will start picking things up again.

Ceylo - massive thanks for the input. Great to have another set of eyes, and you've confirmed some things I wasn't sure about. I also had a ping from tlein on IRC who provided the toolchain, but unfortunately I was offline and seemed to have missed them.

As far as the architecture stuff goes, I see no reason to support 32bit, it will be far more hassle than it's worth. all hardware has been 64 bit for several years, and you can't release a 32 bit app on the App Store anymore.

I'm also not 100% clear on the intention of find_host_package :P
Title: Re: iOS development progress
Post by: Ceylo on February 17, 2018, 11:57:31 am
Good to know that 32 bits support can be dropped! That's what I thought but wasn't sure. From what I saw this excludes iPhone 5C (released in 2013) and older. Should be quite ok. Also found this grid which provides a nice overview: http://blakespot.com/ios_device_specifications_grid.html

So will drop armv7 support and probably let the user choose the deployment target. I noticed however that the externals static libs for iOS were built with iOS 10.2 as min target. So unless we recompile these we'll probably have to stick with 10.2 as a minimal requirement for now.
Title: Re: iOS development progress
Post by: Ceylo on February 17, 2018, 03:39:23 pm
I've removed ARM 32 bits support, added an option to choose the iOS deployment target and made sure iOS static libs are found first, even if "matching" frameworks are installed in /Library/Frameworks.
Changes are still visible at https://github.com/Ceylo/SFML/compare/feature/CMakeTargetExport...Ceylo:feature/iOSCompilation

Also the crashes when launching examples in the simulator look to be related to code signing / bundle identifier. After setting them and doing clean/rebuild it launches correctly in simulator.

For now I could launch both the "window" and "opengl" example in simulator and real iOS device, but the display remains full black without any errors in logs. And pausing the app shows a normal running event loop.

Also I couldn't build the pong example because the freetype static lib wasn't built with bitcode enabled. I guess there'll be the same issue with the flac, ogg and vorbis static libs. According to Apple documentation (https://help.apple.com/xcode/mac/current/#/devbbdc5ce4f), bitcode is optional when building for iOS, but is required for tvOS and watchOS. Also even for iOS it is enabled by default, so it feels like it will be much simpler if we stick with their default. I have no idea how iOS dependencies were previously built though. If we go with rebuilding them, we should also take this occasion to lower the iOS deployment target (currently 10.2) as I don't see any reason not to support iOS 9 for example.


Edit: I fixed CMake code to always the bundle identifier on examples so no more IDE crash. Also did half of the work for code signing to ease building for real devices. I say half because Xcode looks to automate some parts when a developer chooses a "Development Team" and I don't know how to do that with CMake.
Title: Re: iOS development progress
Post by: Ceylo on February 17, 2018, 07:20:20 pm
Now I have the "window" example that launches and runs "correctly". It displays the cube, but orientation handling looks wrong, and it doesn't take advantage of the whole screen (on iPad it shows a x1/x2 button to scale contents, booh!).
"pong" and "opengl" also launch but stop because of missing image files for now.

The whole point to not stay with a black screen was including <SFML/Main.hpp> in the example's main file. To avoid further issues with this I added a check in SFAppDelegate.mm, so that this doesn't go unnoticed.
Title: Re: iOS development progress
Post by: Jonny on February 19, 2018, 07:10:19 am
Does your orientation issue look a little something like this? - https://en.sfml-dev.org/forums/index.php?topic=23507.0

If so, that's great, because all I've only had one other person test that, and they couldn't reproduce it

Yeah not including SFML/Main.hpp caught me out a few times too, anything which can catch that would be massively useful
Title: Re: iOS development progress
Post by: Ceylo on February 19, 2018, 08:24:54 am
It may be the same issue indeed. I’ll change the clear color of the window example to be sure, because with a black background I can’t see the display frame :D
Title: Re: iOS development progress
Post by: Jonny on February 22, 2018, 11:24:21 pm
Does anybody on the SFML team have an opinion on dropping 32 bit support?

Ceylo - Would love to have a more direct line of contact for noodling over these changes, are you on IRC/Discord/etc.?
Title: Re: iOS development progress
Post by: Ceylo on February 23, 2018, 01:09:12 pm
@Jonny : Whichever you prefer :) I have both but I’m used to using none so.. only disadvantage I can see with IRC (from what I understand about IRC) is that you’d lose the messages sent to you while being offline.

Apart from that I’m away for the next days AND I don’t wish to continue on iOS as long as this PR (https://github.com/SFML/SFML/pull/1335) isn’t merged (it needs testing from users), because I feel like I’m accumulating too much unmerged work atm.
Title: Re: iOS development progress
Post by: eXpl0it3r on February 23, 2018, 01:14:05 pm
If 32-bit isn't really supported anymore, I don't see the need to keep it around. And since iOS is not used as much yet, it shouldn't be an issue.
Title: Re: iOS development progress
Post by: Jonny on February 24, 2018, 12:48:55 am
Ceylo - I completely understand. I am also looking forward to that PR being merged! You're right about IRC, if you don't have a bouncer set up then offline messages are lost. I do have a bouncer set up so if you join I'll pick up any messages when I'm around. Alternatively you can join the discord channel here: https://discord.gg/R6BtEzu

I'll add some issues on GH to clarify the issues we've discussed, and put together PR's for the solutions we've found.
Title: Re: iOS development progress
Post by: Jonny on February 25, 2018, 10:22:29 pm
There are now PR's for all the issues we've discussed (I think...):

Force the correct architecture (https://github.com/SFML/SFML/pull/1377)
Find OpenAL correctly (https://github.com/SFML/SFML/pull/1376)
Drop 32 bit support (https://github.com/SFML/SFML/pull/1374)

Big thanks again to Ceylo for much helpful input! I'm going to take a look at getting the examples working now
Title: Re: iOS development progress
Post by: Jonny on April 25, 2018, 06:42:21 pm
There's a few outstanding PR's which could do with testing: