I am interested in consolidating our current functionality for cross-compiling VTK for mobile architectures (iOS, tvOS, Android, etc.). This is likely to have a lot of overlap with the new Apple M1 (arm64) chip support. In addition, we can deprecate support for many previous ARM architectures (armv7, armv7s, etc.).
The last time I visited this topic was six years ago, with the results outlined in this external blog post. The gist is that I created custom toolchain files for device and simulator that could be configured to produce a minimal subset of VTK via a global CMake flag
VTK_IOS_BUILD=ON which invokes a configuration path specified in vtkiOS.cmake. This configuration will build the VTK compile tools then build a subset of VTK for each specified mobile architecture. Another CMake script will then consolidate all of the static libraries and headers to make an iOS framework, which can then be included directly in the relevant Xcode project.
The Android path works similar in spirit, albeit with a different toolchain.
The simplest way to build is:
cmake -DVTK_IOS_BUILD=1 -S vtk -B vtk-ios-build
usr/local/frameworks/VTK.framework. Something similar happens with
VTK_ANDROID_BUILD=1 to produce a consumable Android library.
One downside of this is that only a small subset of VTK modules are currently available. I am unsure which modules cross-compile correctly for iOS/Android and which do not. In addition, if a developer wants to add another module, they have to edit
Modern CMake has a lot of nice built-in functionality for cross compiling for these architectures now. It would be great if we could simply rely on CMake to handle all of this, and delete the toolchain and iOS- and Android-specific CMake files from the VTK source.
For VTK, this means first building the compile tools:
cmake -S vtk -B vtk-compile-tools \ -DVTK_BUILD_COMPILE_TOOLS_ONLY=ON \ -DCMAKE_INSTALL_PREFIX=`pwd`/vtk-compile-tools-install cmake --build vtk-compile-tools --config Release --target install
Then using modern CMake to cross compile:
cmake -S vtk -B vtk-ios-build -G Xcode \ -DCMAKE_SYSTEM_NAME=iOS \ -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \ -DCMAKE_INSTALL_PREFIX=vtk-ios-install \ -DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO \ -DVTKCompileTools_DIR=`pwd`/vtk-compile-tools-install -DCMAKE_IOS_INSTALL_COMBINED=YES
However, at first pass CMake has an issue with finding a valid threading library. Alexis has a fix for this; I will post again to this thread when I have made progress.
Alexis and Julien have also noted interest around building VTK as an XCFramework, something of which I currently have little knowledge. This seems like the ideal end goal at present.
This is the current state of affairs. Opening up this discussion to track any progress and to list any issues that those working on this run into.