Skip to content

Apple: First-class iOS, tvOS, and watchOS support for CMake

Gregor Jasny requested to merge gjasny/cmake:17870-iphone-friendly-cmake into master

This merge request is an attempt to improve CMake's handling of non-macOS SDKs. The goal is to provide an convenient way to a project for iOS, tvOS, and watchOS. By default no code signing configuration should be necessary (at least not for compiler id and feature detection) and simple targets like static libraries.

Example usage:

cmake -GXcode -DCMAKE_SYSTEM_NAME=iOS ..

optionally specify:

  • a different SDK with -DCMAKE_OSX_SYSROOT=iphonesimulator
  • a development team with -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ABCDEFG

Ideas behind the implementation

The first commit 7ccc7b25 adds iOS, tvOS, and watchOS system names which redirect to the Darwin one to avoid code duplications. If unset the respective device SDKs are picked and the SDK variable checked for consistency. MACOS_BUNDLE is set by default and library lookup restricted to the SDK directory (to avoid looking in /usr/...).

Next commit 7730e448 deals with code signing requirements for compiler id detection. To disable it CODE_SIGN_IDENTITY is set to "".

Next commit e1791e84 avoids applying MACOSX_DEPLOYMENT_TARGET to non-macOS targets.

Commit c5e7e5df now uses a static library for compiler feature detection.

Because watchOS does not support xctest bundles, commit 928bcc96 makes CMake use frameworks for compiler discovery instead.

Commit 43b5d5b9 now converts RunCMake.XcodeProject tests from Darwin to the new system names. I decided against duplicating those due to the excessive runtime and used Darwin forward. In a later pull request we could get rid of most code signing tweaks there. But due to different Xcode behavior across versions I decided against doing it right now.

Commit c205544e now adds some basic documentation and closes the pull request. It might benefit from some language tweaks by a native speaker.

Edited by Craig Scott

Merge request reports