Skip to main content

Overview

CMake presets provide predefined build configurations in CMakePresets.json. They simplify building by bundling common options into named configurations.

Using Presets

Use presets with the --preset flag:
The build directory name includes the preset name: build-<preset-name>

Available Presets

Linux Presets

x64-linux-gcc-debug
Debug build with GCC compilerx64-linux-gcc-release
Release build with GCC compilerx64-linux-gcc-reldbg
Release with debug info (RelWithDebInfo)x64-linux-gcc+static-release
Static release build with GCC

Windows Presets

x64-windows-llvm-debug
Debug build with LLVM/Clangx64-windows-llvm-release
Release build with LLVM/Clangx64-windows-llvm-reldbg
Release with debug infox64-windows-llvm+static-release
Static release build

macOS Presets

arm64-apple-clang-debug
Debug build for Apple Silicon arm64-apple-clang-release
Release build for Apple Silicon (RelWithDebInfo) arm64-apple-clang+static-release
Static release for Apple Silicon

Listing Available Presets

To see all available presets:
Example output:

Preset Architecture

Base Presets

Presets inherit from hidden base configurations:
  • base: Common settings for all presets
    • Generator: Ninja
    • Build directory: build-${presetName}
    • Export compile commands: ON
    • Install RPATH: $ORIGIN;$ORIGIN/..
  • sycl-base: Base for SYCL builds
    • Compilers: icx (C++), cl (C)
    • SYCL enabled

Build Type Presets (Hidden)

These are combined with other presets:
  • debug: CMAKE_BUILD_TYPE=Debug
  • release: CMAKE_BUILD_TYPE=Release
  • reldbg: CMAKE_BUILD_TYPE=RelWithDebInfo
  • static: GGML_STATIC=ON

Platform Presets (Hidden)

  • x64-windows-llvm: Uses x64-windows-llvm.cmake toolchain
  • arm64-windows-llvm: Uses arm64-windows-llvm.cmake toolchain
  • arm64-apple-clang: Uses arm64-apple-clang.cmake toolchain
  • x64-linux-gcc: Uses GCC compiler

Customizing Presets

Adding CMake Options to Presets

You can add additional options when using presets:
Windows ARM with OpenMP disabled
Linux with CUDA

Creating Custom Presets

You can create a CMakeUserPresets.json file (git-ignored) for personal presets:
CMakeUserPresets.json
Then use your custom preset:

Preset Structure Reference

Each preset in CMakePresets.json contains: Example from CMakePresets.json:
This preset:
  1. Uses Ninja generator (from base)
  2. Uses LLVM toolchain (from x64-windows-llvm)
  3. Sets Release build type (from release)

Common Workflows

Development Cycle

1

Choose debug preset

Select appropriate debug preset for your platform:
2

Build

3

Test changes

4

Rebuild after changes

CMake automatically detects changes:

Release Build

1

Clean previous builds (optional)

2

Configure release preset

3

Build with parallel jobs

4

Install (optional)

Multi-Configuration Build

Build multiple configurations simultaneously:

Platform-Specific Notes

Windows

Use Developer Command Prompt for Visual Studio when using MSVC or LLVM presets.
For ARM64 builds:

macOS

Apple Silicon (M1/M2/M3) builds:
Metal is enabled by default on macOS. The preset does not disable it.

Linux

For production deployments:
Static builds are self-contained and easier to distribute.

Troubleshooting

Preset Not Found

Solution: List available presets:

Wrong Generator

If Ninja is not installed:
Solution: Install Ninja:

Build Directory Exists

Solution: Remove and reconfigure:

Best Practices

  1. Use presets for consistency: Ensures reproducible builds across team members
  2. Create user presets: Use CMakeUserPresets.json for personal configurations
  3. Version control: Commit CMakePresets.json, ignore CMakeUserPresets.json
  4. Name conventions: Follow existing naming patterns for clarity
  5. Build isolation: Each preset uses separate build directory

Further Reading