Easy Cross-Compiler Toolchain Access with Docker and CMake

May 5, 2015

In the past, cross-compiling was often an art that required a Unix beard, a considerable amount of time, and a chicken to sacrifice. Assembling the cross-compiler toolchain was often a lengthy manual configuration process that was, at best, poorly documented. A number of recent projects make cross-compilers more readily available, but they still usually only work on a few versions of select Linux distributions. Docker images make cross-compiling toolchains easily accessible from any recent Linux distribution and even MacOSX and Windows. When combined with CMake, which has very good cross-compilation support, it is easy to take C/C++-based code and build it for almost anything.

Previously, we described how to build ITK code for Windows from a Debian Jessie Linux distribution. While building the cross-compiler was relatively straight forward, we can get the toolchain with one simple command on any host with Docker installed:

docker pull thewtex/cross-compiler-windows-x86

To perform an Experimental dashboard build with the source code cloned at ~/src/ITK:

docker run --rm -it -v ~/src/ITK:/usr/src/ITK:ro thewtex/cross-compiler-windows-x86
mkdir ITK-build
cd ITK-build/
ctest -D Experimental -j6

This will run build the Docker image, which has the CMAKE_TOOLCHAIN_FILE location configured in an environmental variable. The -G Ninja flag tells CMake to use the Ninja Generator.

Happy cross-compiling!

Leave a Reply