Illustration representing XNNPACK CMake build configuration

Out of the box, XNNPACK's CMake configuration builds tests and benchmarks alongside the library, which is useful during development but adds significant build time and binary size you don't need in a shipping product. Here are the flags worth knowing about before your first production build.

Build type

This one isn't XNNPACK-specific, but it matters more here than usual because of how much the compiler's optimizer affects the generated micro-kernels:

-DCMAKE_BUILD_TYPE=Release

A Debug build can be dramatically slower at runtime, since several optimization passes that XNNPACK's kernels depend on for speed are disabled by default in Debug mode.

Trimming the build

For a library-only build, disabling tests and benchmarks cuts compile time substantially:

-DXNNPACK_BUILD_TESTS=OFF
-DXNNPACK_BUILD_BENCHMARKS=OFF

Library type

By default XNNPACK builds a static library. If your project needs a shared library instead — for example, to avoid duplicating XNNPACK across multiple plugins that link it separately — set:

-DBUILD_SHARED_LIBS=ON

Static linking is usually the safer default for mobile apps, since it avoids runtime library-loading issues on Android and iOS.

Instruction set scope

If you know exactly which CPUs your build will run on, you can narrow which instruction-set variants get compiled in, which reduces binary size at the cost of losing runtime fallback for other CPUs. This trade-off makes the most sense for embedded targets with a fixed, known chip, and the least sense for a general-purpose desktop or server build where the binary needs to run correctly across a range of customer hardware.

Logging

XNNPACK includes internal logging that's useful while debugging a new integration but adds overhead in a shipping build. Keeping the default logging level for development builds and disabling verbose logging for release builds is a reasonable middle ground.

A practical production configure line

cmake -S . -B build -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DXNNPACK_BUILD_TESTS=OFF \
  -DXNNPACK_BUILD_BENCHMARKS=OFF \
  -DBUILD_SHARED_LIBS=OFF

See it in context

These flags slot directly into the workflows covered in our Windows and Linux build guides.