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.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
Compiler Selection
Set the compiler using environment variables on the first cmake invocation: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:Advanced Options
Installation
Standard Installation
- 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:Developer Tools
Verbose Build Output
With Unix Makefiles:List Available Targets
Special Targets
clean- Remove built filesedit_cache- Edit CMake configurationrebuild_cache- Re-run CMakeapi_docs- Build API documentation (ifZ3_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:- Create a new build directory, or
- Delete contents of current build directory
Java Bindings Not Found
SetJAVA_HOME when configuring:
Next Steps
- Learn about building with Make for simple Unix/Linux builds
- See Visual Studio builds for Windows development
- Explore Bazel builds for advanced build orchestration
