This guide covers cross-compiling ThemisDB for different target platforms using CMake toolchain files.
- Overview
- Prerequisites
- ARM64 Linux Cross-Compilation
- ARMv7 Linux Cross-Compilation
- Windows MinGW Cross-Compilation
- vcpkg Configuration
- Using CMake Presets
- Troubleshooting
ThemisDB supports cross-compilation to multiple target platforms using CMake toolchain files. Cross-compilation allows you to build executables for a different architecture or operating system than your build host.
Supported Cross-Compilation Targets:
| Target | Toolchain File | vcpkg Triplet | Use Case |
|---|---|---|---|
| ARM64 Linux | arm64-linux-gnu.cmake |
arm64-linux |
ARM servers, Raspberry Pi 4+ |
| ARMv7 Linux | armv7-linux-gnueabihf.cmake |
arm-linux |
Raspberry Pi 2/3 |
| Windows x64 | x86_64-w64-mingw32.cmake |
x64-mingw-static |
Windows from Linux |
Install cross-compilation toolchains:
# ARM64 cross-compiler
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
# ARMv7 cross-compiler
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
# MinGW-w64 cross-compiler (for Windows)
sudo apt-get install mingw-w64Ensure vcpkg is properly configured:
# Clone vcpkg as a submodule (if not already done)
git submodule update --init --recursive
# Bootstrap vcpkg
cd vcpkg
./bootstrap-vcpkg.sh
# Set VCPKG_ROOT environment variable
export VCPKG_ROOT=$(pwd)The simplest way to cross-compile for ARM64:
cmake --preset cross-arm64
cmake --build --preset cross-arm64If you need custom configuration:
cmake -S . -B build-arm64 \
-DCMAKE_TOOLCHAIN_FILE=cmake/platforms/Toolchains/arm64-linux-gnu.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DTHEMIS_EDITION=COMMUNITY \
-DVCPKG_TARGET_TRIPLET=arm64-linux
cmake --build build-arm64 -j$(nproc)File: cmake/platforms/Toolchains/arm64-linux-gnu.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(VCPKG_TARGET_TRIPLET arm64-linux CACHE STRING "vcpkg triplet")cmake --preset cross-armv7
cmake --build --preset cross-armv7cmake -S . -B build-armv7 \
-DCMAKE_TOOLCHAIN_FILE=cmake/platforms/Toolchains/armv7-linux-gnueabihf.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DTHEMIS_EDITION=MINIMAL \
-DVCPKG_TARGET_TRIPLET=arm-linux
cmake --build build-armv7 -j$(nproc)For Raspberry Pi 2/3 (ARMv7):
cmake -S . -B build-rpi \
-DCMAKE_TOOLCHAIN_FILE=cmake/platforms/Toolchains/armv7-linux-gnueabihf.cmake \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DTHEMIS_EDITION=MINIMAL \
-DTHEMIS_ENABLE_ARM_NEON=ON \
-DVCPKG_TARGET_TRIPLET=arm-linuxcmake -S . -B build-mingw \
-DCMAKE_TOOLCHAIN_FILE=cmake/platforms/Toolchains/x86_64-w64-mingw32.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DTHEMIS_EDITION=COMMUNITY \
-DVCPKG_TARGET_TRIPLET=x64-mingw-static
cmake --build build-mingw -j$(nproc)- Uses static linking by default (
-static-libgcc -static-libstdc++) - Requires
x64-mingw-staticvcpkg triplet - Windows-specific definitions are automatically set
vcpkg triplets define the target platform and library linkage:
| Triplet | Platform | Arch | Linkage |
|---|---|---|---|
x64-linux |
Linux | x86_64 | Dynamic |
arm64-linux |
Linux | ARM64 | Dynamic |
arm-linux |
Linux | ARMv7 | Dynamic |
x64-mingw-static |
Windows | x86_64 | Static |
vcpkg will automatically build dependencies for the target platform:
# For ARM64 Linux
export VCPKG_DEFAULT_TRIPLET=arm64-linux
./vcpkg/vcpkg install
# For ARMv7 Linux
export VCPKG_DEFAULT_TRIPLET=arm-linux
./vcpkg/vcpkg installEnable vcpkg binary cache to speed up cross-compilation:
# Set cache directory
export VCPKG_BINARY_SOURCES="clear;files,$HOME/.cache/vcpkg/archives,readwrite"ThemisDB includes pre-configured presets for common cross-compilation scenarios.
cmake --list-presetscross-arm64- ARM64 Linux (COMMUNITY edition)cross-armv7- ARMv7 Linux (MINIMAL edition)
# Configure
cmake --preset cross-arm64
# Build
cmake --build --preset cross-arm64
# Results will be in build-cross-arm64/Create CMakeUserPresets.json to override preset values:
{
"version": 6,
"configurePresets": [
{
"name": "my-arm64",
"inherits": "cross-arm64",
"cacheVariables": {
"THEMIS_ENABLE_LLM": "ON"
}
}
]
}Error:
CMake Error: CMAKE_C_COMPILER not found: aarch64-linux-gnu-gcc
Solution:
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnuError:
error: building <package>:arm64-linux failed
Solution:
- Ensure cross-compiler is in PATH
- Set
VCPKG_FORCE_SYSTEM_BINARIES=1on ARM build hosts - Check vcpkg logs:
vcpkg/buildtrees/<package>/config-*.log
Problem: Binary runs on build host but crashes on target
Causes:
- Wrong architecture flags - Check
-march=in toolchain file - Missing libraries - Use static linking or deploy dependencies
- GLIBC version mismatch - Build on system with older GLIBC
Solution:
# Check binary architecture
file build-arm64/bin/themisdb
# Check library dependencies
aarch64-linux-gnu-readelf -d build-arm64/bin/themisdbError:
error: could not find triplet file: arm64-linux.cmake
Solution:
# Verify vcpkg triplet exists
ls vcpkg/triplets/arm64-linux.cmake
# Update vcpkg
cd vcpkg
git pull
./bootstrap-vcpkg.shIf testing the binary on the build host:
# Use QEMU to run ARM binaries on x86_64
sudo apt-get install qemu-user-static
# Run ARM64 binary (adjust path to actual binary location)
qemu-aarch64-static -L /usr/aarch64-linux-gnu ./build-arm64/bin/themis_server
# Run ARMv7 binary (adjust path to actual binary location)
qemu-arm-static -L /usr/arm-linux-gnueabihf ./build-armv7/bin/themis_serverNote: The exact binary name may vary (e.g., themisdb, themis_server). Check build-*/bin/ for available executables.
If you need a custom sysroot (e.g., from a target device):
cmake -S . -B build-arm64 \
-DCMAKE_TOOLCHAIN_FILE=cmake/platforms/Toolchains/arm64-linux-gnu.cmake \
-DCMAKE_SYSROOT=/path/to/arm64-sysroot \
-DCMAKE_FIND_ROOT_PATH=/path/to/arm64-sysrootCreate a custom vcpkg triplet:
# vcpkg/triplets/community/my-arm64.cmake
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME Linux)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE
${CMAKE_CURRENT_LIST_DIR}/../../cmake/platforms/Toolchains/arm64-linux-gnu.cmake)Use it:
cmake -S . -B build \
-DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake \
-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=cmake/platforms/Toolchains/arm64-linux-gnu.cmake \
-DVCPKG_TARGET_TRIPLET=my-arm64