Monday, January 18, 2016

iOS Builds

For library projects, it can be helpful to be able to cross-compile the code for iOS, to get reassurance that the code is usable on those platforms. My approach is to start by adding a distinct iOS build to the build matrix, and force objective-c as the language to ensure that the iOS SDKs are available:

    - os: osx
      compiler: clang
      language: objective-c
      env: BUILD_TYPE=ios
  

Then set a collection of config flags in the install step, before ./configure gets run:

    - |
         if [ "$BUILD_TYPE" = "ios" ]; then
             export CONFIG_OPTS=--host=arm-apple-darwin10
             export DEVPATH=`xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer
             export IOSFLAGS="-isysroot $DEVPATH/SDKs/iPhoneOS.sdk -arch armv7 -miphoneos-version-min=8.0.0"
             export CFLAGS=$IOSFLAGS
             export CXXFLAGS=$IOSFLAGS
             export LDFLAGS=$IOSFLAGS
         fi
  

Finally, remember that if there's any attempt to execute the compiled code (such as running a test suite), that needs to be skipped for a cross-compile (e.g. with if [ "$BUILD_TYPE" != "ios" ]).