State of CMake + iOS for SDL2

Hello,

I am interested to see if there’s any update guide on how to build for iOS using solely CMake, without any Xcode project. Xcode updates too much and my projects always seen to get out of date, and Xcode workspaces, which are great for multiple projects, seems to love using absolute paths that are just terrible for sharing it as open source.

Is there any guidance on how to set this up?

I found a project that seems to have figured it out here

Unfortunately it’s in Japanese.

Is there any hope? Since I don’t own any iOS device it always feels very out of reach - Android development is so much more accessible.

Thanks

seems to love using absolute paths that are just terrible for sharing it as open source

CMake isn’t designed for sharing generated IDE projects(.vcxproj or Xcode project).

I found a project that seems to have figured it out here

Although Ninja+CMake still be able to compile sources against iOS SDK, it cannot generate application packages without Xcode thus you cannot installe compiled program, even on the simulator.

Japanese iOS/macOS build instruction for krkr2sdl is here iOS版・MacOS版の吉里吉里SDL2をビルドする · krkrsdl2/krkrsdl2 Wiki · GitHub and it reads

build-iosフォルダに「krkrsdl2.xcodeproj」が出来上がるので、これをダブルクリックしてXcodeで開きます。

says:

krkrsdl2.xcodeproj will be generated on build-ios folder; open it with Xcode

so even krkr2 it requires Xcode for iOS development.

I am alright with using a generated Xcode, I don’t want to maintain a Xcode project.

The Xcode project is absolutely tedious to maintain, each file has a GUID, which means I can’t edit the project with a text editor. And also if I have dependencies, I now have multiple Xcode projects, which a Xcode Workspaces can solve (Xcode Workspace. ) but it comes with absolute paths.

tldr: don’t use Xcode workspaces. Use add_subdirectory etc to integrate multiple CMake projects into single .xcodeproj. CMake should take care of regenerating for this case.

Long version: In case all your dependencies can be built with CMake, try to generate Xcode project with single CMake run which includes both apps and library targets. CMake will automatically takes care of regenerating .xcodeproj which invoked build. Unfortunately, it’s true that CMake doesn’t play nice with Xcode workspaces for this auto regenerating behaviour because it cannot generate workspace itself.

(iOS/macOS specific: regenerating project will lost build customization done against Xcode GUI thus several properties needs to be set inside CMakeLists.txt)

For krkr2 example, it compiles and links with SDL2 from source (external/SDL) here krkrsdl2/CMakeLists.txt at dc45666b527446e97a527b18929305df500387c4 · krkrsdl2/krkrsdl2 · GitHub with add_subdirectory ; generated project will include both SDL2 and app in single .xcodeproj and CMake will auto-regenerate it during build if it needed to be done so you don’t have to maintain any generated project.

Every libraries that compiled inside add_subdirectoryed directory can be referenced from parent CMakeLists.txt; in krkr2 case SDL2-static and SDL2main are linked against application target ${KRKRSDL2_NAME}. Thus it should be easy to build whole app in single CMake run if all of your dependency had CMakeLists.txt to build it.

If you had any dependency that cannot be built with CMake and still needed to be compiled from source, integrating it might be hard… I often port their buildsystem into CMake (e.g. ANGLE which only officially supports GN) for the purpose…