Skip to main content

Overview

Zstandard supports multiple build systems for easy integration into your project. make is the primary and reference build system, while others are periodically updated to maintain compatibility.
When your build system allows it, prefer employing make as it is the reference implementation and most up-to-date.

Make

Basic Usage

From the repository root:
make
This generates:
  • zstd CLI in the root directory
  • libzstd library in lib/

Standard Targets

# Build library (both static and dynamic)
make lib

# Build with release optimizations
make lib-release

# Force multithreaded build
make lib-mt

# Force single-threaded build
make lib-nomt

Compilation Variables

The Makefile follows GNU Standard Makefile conventions:
# Customize installation directories
make install PREFIX=/usr/local \
             BINDIR=/usr/local/bin \
             LIBDIR=/usr/local/lib \
             INCLUDEDIR=/usr/local/include

Modular Build Options

Control which modules are compiled:
# Build without compression support
make ZSTD_LIB_COMPRESSION=0

# Build without decompression support
make ZSTD_LIB_DECOMPRESSION=0

# Build without dictionary builder
make ZSTD_LIB_DICTBUILDER=0

# Build without deprecated APIs
make ZSTD_LIB_DEPRECATED=0

Minimize Binary Size

For size-constrained environments:
# Enable all minimization options
make ZSTD_LIB_MINIFY=1

# Disable inlining
make ZSTD_NO_INLINE=1

# Strip error strings
make ZSTD_STRIP_ERROR_STRINGS=1

# Use size-optimized compilation
make CFLAGS="-Os -flto -ffunction-sections -fdata-sections" \
     LDFLAGS="-Wl,--gc-sections"

CMake

Basic Configuration

# Configure from repository root (recommended)
cmake -S . -B build-cmake
cmake --build build-cmake

Installation

cmake --build build-cmake
cmake --install build-cmake

# Or with Make
cd build-cmake
make install

CMake Options

View available options:
cd build-cmake
cmake -LH ..
Configure with options:
cmake -S . -B build-cmake \
  -DZSTD_BUILD_STATIC=ON \
  -DZSTD_BUILD_SHARED=OFF \
  -DZSTD_BUILD_TESTS=ON

CMake FetchContent

Integrate Zstandard using CMake’s FetchContent:
include(FetchContent)

set(ZSTD_BUILD_STATIC ON)
set(ZSTD_BUILD_SHARED OFF)

FetchContent_Declare(
    zstd
    URL "https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz"
    DOWNLOAD_EXTRACT_TIMESTAMP TRUE
    SOURCE_SUBDIR build/cmake
)

FetchContent_MakeAvailable(zstd)

target_link_libraries(
    ${PROJECT_NAME}
    PRIVATE
    libzstd_static
)

# On Windows and macOS this is needed
target_include_directories(
    ${PROJECT_NAME}
    PRIVATE
    ${zstd_SOURCE_DIR}/lib
)

Apple Universal Binaries

Build for both Apple Silicon and Intel:
cmake -S . -B build-cmake \
  -G Ninja \
  -DCMAKE_OSX_ARCHITECTURES="x86_64;x86_64h;arm64" \
  -DZSTD_FRAMEWORK=ON

cd build-cmake
ninja
sudo ninja install

Meson

Setup and Build

From the build/meson directory:
cd build/meson

# Setup build
meson setup -Dbin_programs=true -Dbin_contrib=true builddir

# Build
cd builddir
ninja

# Install
ninja install

# Staged install
DESTDIR=./staging ninja install

Configuration

Configure build options:
meson configure
Common options:
# Build static library only
meson setup -Ddefault_library=static builddir

# Build shared library only
meson setup -Ddefault_library=shared builddir
Meson outputs one libzstd, either shared or static, depending on the default_library option.

Bazel

Integration

Integrate Zstandard into your Bazel project using the Bazel Central Repository: Add to your MODULE.bazel file:
bazel_dep(name = "zstd", version = "1.5.5")
Or in legacy WORKSPACE file:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "zstd",
    urls = ["https://github.com/facebook/zstd/archive/v1.5.5.tar.gz"],
    strip_prefix = "zstd-1.5.5",
)

Usage in BUILD Files

cc_binary(
    name = "my_app",
    srcs = ["main.cc"],
    deps = ["@zstd"],
)

Buck

Building with Buck

From the repository root:
buck build programs:zstd
The output binary will be in buck-out/gen/programs/.

Buck Configuration

Zstandard includes BUCK files for library components in lib/BUCK:
# Main library target
cxx_library(
    name='zstd',
    header_namespace='',
    exported_headers=['zstd.h'],
    visibility=['PUBLIC'],
    deps=[
        ':common',
        ':compress',
        ':decompress',
        ':deprecated',
    ],
)

Using in Your Buck Project

Reference the zstd library in your BUCK file:
cxx_binary(
    name = 'my_app',
    srcs = ['main.c'],
    deps = [
        '//path/to/zstd/lib:zstd',
    ],
)

Package Managers

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install zstd

Comparison

Build SystemBest ForMaturity
MakeReference implementation, most up-to-datePrimary
CMakeCross-platform projects, IDE integrationHigh
MesonFast builds, modern syntaxMedium
BazelLarge monorepos, reproducible buildsMedium
BuckFacebook ecosystem, mobile buildsMedium

Next Steps

C/C++ Integration

Learn how to use Zstandard API in your C/C++ code

Platform Support

Platform-specific build instructions

Build docs developers (and LLMs) love