First-class iOS support for CMake
This is a tracking bug to discuss better iOS support in CMake. The goal is to provide a convenient way to build a project for iOS, watchOS, and tvOS. So far it just needs some tweaks of the Modules
scripts.
Example usage:
cmake -GXcode -DCMAKE_SYSTEM_NAME=iOS .
For tvOS and watchOS specify a development team with -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ABCDEFG
.
Some discussion already took place in !1664 (closed).
A work-in-progress branch is here: 17870-iphone-friendly-cmake
What's happening here
Add iOS, tvOS, and watchOS as a system name
Commit af9187ae adds iOS
, tvOS
, and watchOS
as separate platforms. All of those new systems redirect to the Darwin
one for now. For each of the new platforms a matching Xcode SDK is selected by default in case the user did not explicitly selected one.
The Darwin
platform provides about 20 compiler configuration files. That would result in addition of 60 redirection files. Instead a new _CMAKE_EFFECTIVE_SYSTEM_NAME
variable has been introduced. It defaults to CMAKE_SYSTEM_NAME
but could be overridden (for example in -Initialize.cmake
files). The CMake<LANG>Information.cmake
files then use the new variable. That way compiler config files could be shared across all Xcode SDKs. Change is here: 54f54269
Tweak Settings for new non-Darwin platforms
Change c0597b27 requests executable app bundles for the new platforms.
Change 4b8699ea sets the find root path to the SDK root and restricts lookup to just that directory. That way no macOS includes or libraries are looked up in /usr
.
In 9cef09f6 we restrict evaluating MACOSX_DEPLOYMENT_TARGET
environment variable to just macOS.
Compiler detection
The original goal was to succeed a simple configure run for an empty CMakeLists.txt
without having to configure any code signing settings. The first attempt changed compiler detection target from an executable (or xctest) to a static library. Unfortunately for C++ Xcode does not call clang++
but clang -x c++
so the C compiler binary was detected instead of the C++ one.
Therefore the behavior for compiler detection was reverted. As a consequence only macOS and iOS work without code signing configured.
Older patchsets also configured try_compile()
to emit static libraries instead of executables. But as @brad.king noted, that will break linkage checks. As a trade-of the compiler tests (ABI and features) are configured to emit static libraries because they don't rely on the linkage aspect of try_compile
.
Open Issues
-
Get ack from @brad.king for _CMAKE_EFFECTIVE_SYSTEM_NAME
(in 54f54269) -
Reject foreign SDKs ( -DCMAKE_SYSTEM_NAME=iOS
-DCMAKE_OSX_SYSROOT=appletvos
) -
For tvOS and watchOS (maybe even iOS) complain about missing Team variable for code signing -
Fix RunCMake.Configure test -
Fix RunCMake.XcodeProject deployment test -
Fix typo in RunCMake.XcodeProject deployment test -
Write documentation once functional changes have been ack'ed -
Write release note