Enable or Disable libavif Command Line Tools

This article explains how to configure the libavif build process to either include or exclude command-line utilities like avifenc and avifdec. By utilizing specific CMake arguments during compilation, developers can customize their build environment to generate only the core library or include the optional helper tools.

The CMake Variable

The libavif library uses CMake as its build configuration system. To control the compilation of the companion command-line tools, you must toggle the AVIF_BUILD_APPS CMake variable.

How to Enable Command-Line Tools

To build the command-line tools (avifenc and avifdec) alongside the static or shared libraries, set the AVIF_BUILD_APPS variable to ON during the CMake configuration step.

Run the following commands in your terminal:

mkdir build
cd build
cmake -DAVIF_BUILD_APPS=ON ..
cmake --build .

Note: Building these tools requires additional dependencies, such as libpng, jpeg, and a supported AV1 encoder/decoder library (like aom, dav1d, or rav1e).

How to Disable Command-Line Tools

If you only need the core C library and want to speed up build times or minimize dependencies, you can disable the compilation of the command-line tools by setting the AVIF_BUILD_APPS variable to OFF.

Run the following commands:

mkdir build
cd build
cmake -DAVIF_BUILD_APPS=OFF ..
cmake --build .

By setting this option to OFF, the compiler will only output the binary library files (such as libavif.a, libavif.so, or avif.dll) and bypass the executable tools entirely.