Skip to main content
CMake is the recommended build system for Z3 on most platforms. It’s a “meta build system” that generates platform-specific build files from CMakeLists.txt configuration files.
CMake is recommended for most build tasks, except for building OCaml bindings which should use the Make-based system.

Prerequisites

  • CMake 3.16 or later
  • C++20 compatible compiler (GCC, Clang, or MSVC)
  • Python (required for build configuration)
  • Git (optional, for version information)

Quick Start

1

Create build directory

Create a separate build directory outside the source tree:
CMake enforces out-of-source builds. You cannot build directly in the source directory.
2

Configure the build

Run CMake to configure the project:
For a Release build:
3

Build Z3

Build the project using make:
4

Install (optional)

Install Z3 system-wide:

Build Generators

CMake supports multiple generators. Choose based on your platform and preference:

Unix Makefiles

Default on most Linux/Unix systems:
This is a single-configuration generator - you set the build type (Debug/Release) when running cmake.

Ninja

Ninja is significantly faster than Make due to non-recursive builds:
Ninja runs in parallel by default. Use the -j flag to control parallelism.
Ninja also works on Windows - just run cmake in the Visual Studio Developer Command Prompt.

Visual Studio

See the Visual Studio build guide for detailed instructions.

Build Types

CMake supports several build types:
  • Release - Optimized build with no debug symbols
  • Debug - Debug build with symbols, tracing enabled
  • RelWithDebInfo - Optimized build with debug symbols
  • MinSizeRel - Optimized for size
For single-configuration generators (Unix Makefiles, Ninja):
For multi-configuration generators (Visual Studio), select the build type in the IDE.

Compiler Selection

Set the compiler using environment variables on the first cmake invocation:
Once configured, the compiler is fixed. To change compilers, create a new build directory or delete the contents of the current one.

Cross-compilation

For 32-bit builds on 64-bit systems with multilib GCC:

CMake Configuration Options

Core Build Options

Language Bindings

Enable various language bindings:

Security Features (MSVC)

When building with Visual Studio/MSVC, Control Flow Guard is enabled by default:
See Visual Studio build guide for details on security features.

Advanced Options

Installation

Standard Installation

By default, Z3 installs to:
  • Binaries: ${CMAKE_INSTALL_PREFIX}/bin
  • Libraries: ${CMAKE_INSTALL_PREFIX}/lib
  • Headers: ${CMAKE_INSTALL_PREFIX}/include

Custom Installation Paths

Staged Installation

For packaging, use DESTDIR:

Uninstall

Using Z3 in CMake Projects

With FetchContent

Fetch Z3 directly from the repository:

With find_package

Use system-installed Z3:

With Fallback

Try system installation first, fall back to FetchContent:

Building Python Bindings

With libz3

Build both library and bindings:

Python-only (using pre-installed libz3)

For package managers building for multiple Python versions:

Cleaning Source Tree

If you’ve previously used the Python build system, clean generated files:
Be careful with git clean -fx - it permanently deletes untracked files.

Developer Tools

Verbose Build Output

With Unix Makefiles:
With Ninja:

List Available Targets

Special Targets

  • clean - Remove built files
  • edit_cache - Edit CMake configuration
  • rebuild_cache - Re-run CMake
  • api_docs - Build API documentation (if Z3_BUILD_DOCUMENTATION=ON)

Common Issues

Polluted Source Tree

If CMake reports a polluted source tree, you have generated files from the Python build system:

Changing Compiler

To change compilers, either:
  1. Create a new build directory, or
  2. Delete contents of current build directory
Then run cmake with new compiler environment variables.

Java Bindings Not Found

Set JAVA_HOME when configuring:

Next Steps