Author Topic: Retake on building libopenmpt for iOS  (Read 1475 times)

Offline florist

  • Shy artist
  • Posts: 5
  • chiptune loving software architect
    • 4champ Twitter account
  • Operating System: iOS
Retake on building libopenmpt for iOS
« on: April 18, 2018, 06:37:14 »
It's been a year and a half since I last put my finger on OpenMPT iOS integration (originally posted about this at https://forum.openmpt.org/index.php?topic=5695.msg43421#msg43421) - decision for setting the project aside for a while rose from Apple's rather blunt rejection of 4champ from AppStore just when I had an all new and shiny version ready. You can read more about the dispute with Apple and other 4champ development related things on my dev journal at https://sitomani.github.io/4champhttps://github.com/sitomani/openmpt).

Here's some observations that I've made (comments would be appreciated if anyone knows how to work around / mitigate these):

1. premake5 still cannot create iOS projects 
Current official premake5 release is dated 27 August 2017, 269 commits in master since then. I can see from the commit history that on 30 August samsinsane "Added basic iOS support to XCode4" which sounded very promising. However, when I built premake from sources and tried to use the
Code: [Select]
system "iOS" command in the lua script, the resulting xcode project still targets Mac OS only. In my forked repository, I've added a build script that modifies the generated xcode project file and explicitly sets
Code: [Select]
SDKROOT = iphoneos and removes the fixed target architecture setting to enable xcode to autoselect archs. If someone knows how it is supposed to work with premake5 latest master build, let me know.


2. premake5 generated xcode project does not have correct linking phase configuration

I'm creating libopenmpt-small group with premake, and the lua file seems to have intact links section listing miniz, minimp3 and stb_vorbis libs. However, in the generated xcode project, these libs are only listed under Target Dependencies build phase, and not under Link Binary With Libraries phase. I found some discussion under premake-core github around dependson and links usage&issues with xcode but as long as I read it correctly, links should work a-ok. I guess resolving this would require a deeper look at premake code and reporting to their issue list. For now, I've decided to add the libs to the link phase manually in xcode before running the build.


3. update_svn_version_vs_premake.cmd calls in the openmpt targets fails on xcode builds
My solution is to filter them out with
Code: [Select]
filter { "action:vs*" }. Maybe this could be done in the openmpt trunk as well?


4. building the full libopenmpt has more obstacles like missing xcode port under mpg123
For my purposes libopenmpt-small will do, but I recall I managed to build the full lib back in 2016. With the latest code however there is a number of build time errors that would require further adjustments, which mostly are trivial (i.e. tweaking with include paths and adding an include here and there) but for mpg123 it'd require that you pick the xcode port along from https://www.mpg123.de/cgi-bin/scm/mpg123/trunk/ports/ - openmpt repository only has the MSVC++ port. Does that sound feasible to you?


That's all for now - I'm going to working on the 4champ open source version in small chunks, and hopefully getting something usable out later this year that anybody could build locally and run on their own devices. Ultimate goal would be to get the app relisted on AppStore, but it will require getting around the Apple review policy with some trickery that I haven't yet figured out.

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 198
Re: Retake on building libopenmpt for iOS
« Reply #1 on: April 19, 2018, 06:53:54 »
It's been a year and a half since I last put my finger on OpenMPT iOS integration (originally posted about this at https://forum.openmpt.org/index.php?topic=5695.msg43421#msg43421) - decision for setting the project aside for a while rose from Apple's rather blunt rejection of 4champ from AppStore just when I had an all new and shiny version ready. You can read more about the dispute with Apple and other 4champ development related things on my dev journal at https://sitomani.github.io/4champhttps://github.com/sitomani/openmpt).

I have looked at your modifications, and they indeed look rather simple. I think we can include something like that in our repository.

I own no Apple hardware, and I thus cannot test any of this. However, wie are running tests on the free https://travis-ci.org/ service (which offers also MacOS/Xcode environments), and it looks like we should be able to at least build-test with Xcode that way.


1. premake5 still cannot create iOS projects 
2. premake5 generated xcode project does not have correct linking phase configuration

Do you happen to know if other project file generators work better than premake5 does? If for example genie works better, we could use that (we already use it for Windows Store / Windows UWP. Adding cmake for Xcode macOS/iOS would also be fine.


3. update_svn_version_vs_premake.cmd calls in the openmpt targets fails on xcode builds
My solution is to filter them out with
Code: [Select]
filter { "action:vs*" }. Maybe this could be done in the openmpt trunk as well?

Sure, that should be simple. However, by now I think it might make sense to use a separate set of premake configuration files explicitly for Xcode. I think tha would be easier to maintain and result in less confusing files (as our current set of premake configuration is rather specific to MSVC/Windows with its various build configuration options).


4. building the full libopenmpt has more obstacles like missing xcode port under mpg123

Sure, it totally makes sense to add at the Xcode port of mpg123, which, like the MSVC port, in particular adds a proper config.h for Apple platforms. I do not think it would make much sense to use their Xcode project files. We can easily generate those the same way as libopenmpt itself and as we do for mpg123 on Windows.

What is the state of zlib on macOS and iOS? Do we need to also build that ourselves or is it available system-wide by default from Apple?

Offline florist

  • Shy artist
  • Posts: 5
  • chiptune loving software architect
    • 4champ Twitter account
  • Operating System: iOS
Re: Retake on building libopenmpt for iOS
« Reply #2 on: April 20, 2018, 07:44:04 »
Thanks for the comments. My 50 cents below:

I checked genie quickly, seems to have more recent iOS/macosx related features than premake => it might be more feasible for enabling xcode builds in the long run. When I have a slot I can try to cook a xcode-specific genie recipe for building libopenmpt and put that up on my github fork repo and report back how it went.

zlib (or rather libz) is available in iOS/macosx sdks => it should be ok to just link against it and skip building it as part of openmpt builds when building with xcode. Not sure how to do that in the lua scripts, but you probably have an idea? If libz is not part of the build, it must be passed in the other linker flags section for xcode as "-lz".

regarding mpg123 - I agree, including the xcode headers will suffice, the project file can be generated along others. I will be watching the changes in openmpt github for those, and try building the full lib at some point with the xcode port headers included even if you didn't add it yet to trunk.

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 198
Re: Retake on building libopenmpt for iOS
« Reply #3 on: April 20, 2018, 13:54:21 »
I have added libmpg123 config.h for Xcode, as well as tried to generate Xcode9 project files with genie (both in trunk).

However:
Code: [Select]
xcodebuild clean -workspace build/xcode9-iphoneos/libopenmpt.xcworkspace/ -scheme libopenmpt
xcodebuild: error: The workspace named "libopenmpt" does not contain a scheme named "libopenmpt". The "-list" option can be used to find the names of the schemes in the workspace.
is what I am getting on Travis-CI (again, I do not own a Mac).
Not sure what I (or genie) is doing wrong here, maybe you have an idea?

I generate xcode projects for both, iOS and standard macOS. However I am unsure if I should build static or dynamic libraries. Which is more common for macOS and iOS? Are dynamic libraries even supported on iOS (I remember something about them not being supported, however that information might also be severely outdated)?


In any case, as soon as all of this works properly, I will backport it to libopenmpt 0.3, so that we provide Xcode support also for the stable released version of libopenmpt.