Last Updated: September 29, 2021
·
14.46K
· gpakosz

Compiling for iOS outside of Xcode with xcrun

If you have a project which build system is GNU Make based, it's rather easy to compile it for iOS.

TLDR, use:

$ make CC="$(xcrun --sdk iphoneos --find clang) -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -arch armv7 -arch armv7s -arch arm64"

Then use:

$ codesign -s 'iPhone Develoer' ./path/to/binary

Breaking it down:

$ xcrun --sdk iphoneos --find clang

will find out which version of clang needs to be used to target iPhoneOS, e.g. /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang

Then,

$ xcrun --sdk iphoneos --show-sdk-path

will find out the SDK path that has to be given as -isysroot, e.g. /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk.

Finally,

-arch armv7 -arch armv7s -arch arm64

will build a fat binary targeting armv7, armv7s and armv64 architectures.

To see it in action, you can have a look at my PackedArray project's build instructions and the accompanying Makefile.