How to Cross-Compile libaom for ARM?

Cross-compiling libaom (the Alliance for Open Media AV1 codec library) for ARM architectures allows you to build efficient video encoding and decoding software for embedded devices, smartphones, and Raspberry Pi boards from a standard x86_64 host machine. This process requires a proper toolchain, the CMake build system, and specific configuration flags to target the correct ARM architecture (such as ARMv7 or AArch64). By configuring the build environment correctly, you can generate optimized binaries tailored for your target hardware.

Prerequisites and Toolchain Setup

Before starting, you need a host system (typically Linux x86_64) equipped with the necessary cross-compiler. For ARM architectures, the GNU Toolchain is the standard choice.

On Debian or Ubuntu-based systems, you can install these via apt:

sudo apt update
sudo apt install git cmake ninja-build gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

Fetching the libaom Source Code

Clone the official libaom repository from the Alliance for Open Media Git server and navigate into the directory:

git clone https://aomedia.googlesource.com/aom
cd aom

Configuring CMake for ARM Cross-Compilation

libaom uses CMake toolchain files to handle cross-compilation. The repository includes pre-configured toolchain files for common architectures inside the build/cmake/toolchains/ directory.

Create a separate build directory to keep the source tree clean:

mkdir build_arm64 && cd build_arm64

Execute the CMake command, pointing to the appropriate toolchain file. For a 64-bit ARM target using Ninja as the generator, run:

cmake .. \
  -G Ninja \
  -DCMAKE_TOOLCHAIN_FILE=../build/cmake/toolchains/arm64-linux-gcc.cmake \
  -DCONFIG_RUNTIME_CPU_DETECT=0 \
  -DENABLE_DOCS=OFF \
  -DENABLE_EXAMPLES=OFF \
  -DENABLE_TESTS=OFF

Key Configuration Flags

Compiling and Installing

Once CMake successfully generates the build files, start the compilation process:

ninja

If you prefer standard Makefiles over Ninja, replace -G Ninja with -G "Unix Makefiles" in the CMake step, and run make instead.

After the build completes, compile artifacts (including libaom.a and libaom.so) will be available in your build directory. To install the binaries and headers to a specific staging directory for deployment to your ARM target, use:

DESTDIR=/path/to/your/target/sysroot ninja install