How to build 3D Slicer for Raspberry?

How to build slicer on raspberri Pi having rasbpian OS?

Follow Linux build instructions. Complete build takes several hours on a desktop PC, so on a raspberry Pi it may take days, but it’ll be interesting to see if it is feasible.

Instead of compiling Slicer directly on the Raspberry, I suggest to look at using “cross-compilation” approaches.

In the past, we successfully cross-compiled ITK and VTK:

With the improvement to CMake (e.g support for cross-compiling emulator) as well as the work put into the dockcross project, it should be easier today.

Further experiments would be needed to compile Qt5. Here are some pointers:

At first, I would also suggest to try to compile Slicer with the following options disabled:

-DSlicer_USE_PYTHONQT:BOOL=OFF
-DSlicer_USE_PYTHONQT_WITH_TCL:BOOL=OFF
-DSlicer_BUILD_DICOM_SUPPORT:BOOL=OFF
-DSlicer_BUILD_DIFFUSION_SUPPORT:BOOL=OFF
-DSlicer_BUILD_EXTENSIONMANAGER_SUPPORT:BOOL=OFF
-DSlicer_BUILD_CLI:BOOL=OFF
-DBUILD_TESTING:BOOL=OFF
-DSlicer_BUILD_QTLOADABLEMODULES:BOOL=OFF
-DSlicer_BUILD_QTSCRIPTEDMODULES:BOOL=OFF

Also, since options like CMAKE_CROSSCOMPILING and CMAKE_CROSSCOMPILING_EMULATOR are not propagated down to external projects, I suggest to first build dependent libraries by starting with VTK, then ITK, …

To find in which order to build the dependency, you could look at the topological order displayed when configuring Slicer using a regular toolchain:

$ cmake ...
[...]
-- SuperBuild - First pass
-- SuperBuild - First pass - done
-- SuperBuild - Slicer => Requires curl, CTKAppLauncherLib, teem, VTKv9, ITKv4, CTK, LibArchive, RapidJSON, SimpleITK, SlicerExecutionModel, qRestAPI, DCMTK, python-pydicom, python-chardet, python-couchdb, python-GitPython, python-pip, python-PyGithub, CTKAPPLAUNCHER, python, NUMPY, incrTcl,
[...]

All project listed after – SuperBuild - Slicer => Requires are listed in topological order. (Note that in the case of building for Raspberry, less projects would be listed because of the disabled options.)

After all required projects are cross-compiled independently (e.g using dockcross), you could then configure Slicer also using dockcross with option like these ones:

cmake -DVTK_DIR:PATH= ... -DITK_DIR=PATH= ...  -DSlicer_SUPERBUILD:BOOL=OFF ../Slicer

Also, since there are no prebuilt binaries of the launcher available for Raspberry, you could set Slicer_USE_CTKAPPLAUNCHER to OFF and use a shell script to set the startup environment.

Let us know if you have any questions,
J-Christophe

1 Like

I built Slicer on Odroid-U2 out of technical interest on Arch Linux for ARM. There was just one more step to do :

build CTKAPPLAUNCHER,
download CTKAppLauncher pre-compiled for amd64,
replace the x86_64 blob by the locally compiled ARM binary,
rename the package and patch the cmake file :

 diff --git a/SuperBuild/External_CTKAPPLAUNCHER.cmake b/SuperBuild/External_CTKAPPLAUNCHER.cmake
index dda4e1a54..911cdb428 100644
--- a/SuperBuild/External_CTKAPPLAUNCHER.cmake
+++ b/SuperBuild/External_CTKAPPLAUNCHER.cmake
@@ -30,7 +30,8 @@ if(Slicer_USE_CTKAPPLAUNCHER)
       set(CTKAPPLAUNCHER_ARCHITECTURE "i386")
       set(md5 "9fa2acb7d934a43720a0bee8679cbeff")
     elseif("${CTKAPPLAUNCHER_OS}" STREQUAL "linux")
-      set(md5 "57d9e6fc1fdfe42d78fc4e277b9559ba")
+      set(CTKAPPLAUNCHER_ARCHITECTURE "armv7l")
+      set(md5 "783455a7ee0bea086082f64da6adda1d")
     elseif("${CTKAPPLAUNCHER_OS}" STREQUAL "macosx")
       set(md5 "1f0d86b1eeb386d6892a76db7b111280")
     endif()

Please not that if CTKAPPLAUNCHER_ARCHITECTURE is not explicitely set, it defaults to i386. There’s probably a simpler way to build it automatically, I’m eager to learn about it.

It takes about 24 hours to build using all 4 cores with lowest nice priority. Here is a video captured with Slicer freshly started after rebooting the build device. (You may advance the video with the mouse, some simple steps are very long). Slices are never displayed in the viewers.

Of course it’s not for routine use. Just a curious thing to do in the background.

3 Likes

Well done.

Out of curiosity, did you have to apply any other patch to Slicer/VTK/ITK/… or it “just worked” ?

AppLauncher for ARM

If you could look at dockcross identify the cross-compiler corresponding to Odroid-U2, it should be possible to have the corresponding launcher binaries automatically built and available AppLauncher release assets.

I applied the patches mentioned here because I used GCC 8.1 on the Odroid-U2 SoC too. I guess these three patches would not be needed for GCC < 8, and it would just work.

Concerning cross-compiling, it’s certainly a good idea, I’ll dig into that when I find some time.

Concerning AppLauncher to be built locally, I understand that both with native or cross-compiling, the current cmake file does not build AppLauncher yet, it should be modified to download sources etc… and this is well beyond my skills.