Next in the series of cross-compiling ITK with CMake and Docker, we target Android’s version of Linux for ARM processors. This follows articles on using Docker to help us cross-compile for
ITK on Android puts advanced image analysis capabilities in physician’s pockets, and it brings new image processing possibilities to low-cost, portable ultrasound systems.
As previously noted, there are three steps when cross-compiling with Docker and CMake.
1) Get the cross-compiling toolchain
Obtaining the toolchain with Docker is easy — just download it with docker pull:
1 |
docker pull thewtex/cross-compiler-android-arm |
2) Start up a container, mounting the source and build tree
If there is a source tree and build tree, e.g.
1 2 3 |
cd ~/src git clone http://itk.org/ITK.git mkdir -p ~/bin/ITK-build |
Then mount these directories as Docker volumes when the container is started:
1 2 3 4 |
docker run --rm -it \ -v ~/src/ITK:/usr/src/ITK:ro \ -v ~/bin/ITK-build:/usr/src/ITK-build:rw \ thewtex/cross-compiler-android-arm |
3) Point CMake to the CMAKE_TOOLCHAIN_FILE
Inside the container, the environmental variable CMAKE_TOOLCHAIN_FILE has been configured to point to the toolchain file CMake uses to inform itself about the build environment. Pass this file to CMake during configuration.
1 2 3 4 5 6 7 8 |
cd /usr/src/ITK-build cmake -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} \ -G Ninja \ -DBUILD_EXAMPLES=OFF \ -DITK_DYNAMIC_LOADING=OFF \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_EXE_LINKER_FLAGS=-static \ ../ITK |
The -G Ninja flag tells CMake to use our favorite generator, the Ninja generator, which is fast and does parallel builds automatically.
The -DBUILD_EXAMPLES=OFF flag disables building the examples.
The options for ITK_DYNAMIC_LOADING, BUILD_SHARED_LIBS, and CMAKE_EXE_LINKER_FLAGS generate static executables. Unlike when cross-compiling for the Raspberry Pi, which is a vanilla Linux target, static executables are used with Android to make it easier to build and test on the host Linux environment. Android ships with its own fancy-pants dynamic loader, /system/bin/linker, which is not present in the toolchain or compatible with a non-Android kernel.
Since the qemu-user emulator has limited multi-threading abilities, run the tests in single-threaded mode:
1 |
export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1 |
And start the Experimental dashboard build!
1 |
ctest -D Experimental -j$(nproc) |
Enjoy ITK!