Build for Different Platforms

Help to build libical for various platforms and compilers.

Cross-compiling

When cross-compiling, executables built for the host architecture cannot be run on the build architecture. CMake doesn't provide something like CC_FOR_BUILD from autotools, and recommended way to handle this case is the export the required binary from the native build for use by the cross-compiled build.

See the "Searching and finding external software" section of CMake cross-compiling guide

Libical can cross-compile ok if you disable building libical-glib by passing -DICAL_GLIB=False to CMake.

If you want/need libical-glib for your cross-compile then:

  • build and install a native build of libical into (for example) /usr/local
  • then pass -DIMPORT_ICAL_GLIB_SRC_GENERATOR=/usr/local/lib64/cmake/LibIcal/IcalGlibSrcGenerator.cmake to CMake for the cross-compile build.

Read the cmake-toolchains documentation to help you write your own Toolchain file if needed.

Look in the libical/cmake folder for some Toolchain files that may or may not work out-of-the-box.

iOS arm7, arm64, x386

Add the following inside CMakeList.txt:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch armv7")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch armv7")

Then run cmake ..

Modify the following line from the build/CMakeCache.txt that's generated by cmake command:

// The product will be built against the headers and libraries located
// inside the indicated SDK.
CMAKE_OSX_SYSROOT:PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk

(Change it into iPhoneOS.sdk or iPhoneOS8.4.sdk)

run make, and make install as noted in the installation from libical.

use lipo -info to check the generated lib .a files, it will say it is armv7.

Use the same method to generate .a for arm64 and also i386 (for different simulators, etc), and use lipo -create to combine all of the into one FAT.