Edit 2016-10-10: The instructions below now use dockcross. Cross compile for other platforms by replacing dockcross/browser-asmjs with dockcross/linux-armv7, etc.
1) Get the cross-compiling toolchain
As with previous posts, we will use Docker to grab the toolchain:
docker pull dockcross/browser-asmjs docker run --rm dockcross/browser-asmjs > ./dockcross-browser-asmjs chmod +x ./dockcross-browser-asmjs
2) Obtain the source and create a build tree
If there is a source tree and build tree, e.g.
git clone https://itk.org/ITK.git cd ITK git checkout e19ddf0c830d cd .. mkdir -p ITK-build
3) Build and test
For the purposes of running the test suite, we will add flags for Emscripten that sacrifice run-time performance at the cost of functionality:
flags='-Wno-warn-absolute-paths --memory-init-file 0 -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1'
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.
./dockcross-browser-asmjs cmake -HITK -BITK-build \ -G Ninja \ "-DCMAKE_CXX_FLAGS=$flags" "-DCMAKE_C_FLAGS=$flags" ./dockcross-browser-asmjs ninja -CITK-build
The -G Ninja flag tells CMake to use our favorite generator, the Ninja generator.
Emscripten uses NodeJS as the CMAKE_CROSSCOMPILING_EMULATOR; with CMake 3.3 and later, this means NodeJS is used to also run the test suite. For NodeJS to access the file paths passed as command line arguments, the paths must be mounted to the NODEFS file system. ITK’s test driver is instrumented to mount the source tree and build tree when executed.
Start the Experimental dashboard build!
./dockcross-browser-asmjs bash -c 'cd ITK-build && ctest -D Experimental -j$(nproc)'