A unified CMake build system that seamlessly integrates the QuantLib C++ library and QuantLib-SWIG Python bindings into a single, streamlined build process.
This build system provides a modern CMake-based approach to building the Model-Validation forks of QuantLib and its Python bindings. It handles all dependencies, automates the SWIG generation process, and produces ready-to-use Python wheels.
- CMake 3.20 or later
- Visual Studio 2019/2022 with MSVC or Clang
- Python 3.8+ with pip
- Git for cloning repositories
- Boost 1.70+ (headers and libraries)
- Eigen3 linear algebra library
- SCS (Splitting Conic Solver) for convex optimization
- SWIG 4.0+ for Python bindings generation
- ISDA CDS Model for credit derivatives support
git clone https://github.com/Model-Validation/QuantLib-Build.git
cd QuantLib-Buildgit clone https://github.com/Model-Validation/QuantLib.git
git clone https://github.com/Model-Validation/QuantLib-SWIG.gitcmake --preset windows-msvc-release# Build QuantLib C++ library only
cmake --build build/windows-msvc-release --target ql_library
# Build complete Python package
cmake --build build/windows-msvc-release --target python_allql_library- Builds the QuantLib C++ static library
python_all- Complete Python build pipeline (recommended)swig_generate- Generates Python wrapper code from SWIG interfacespython_compile- Compiles the C++ Python extensionpython_build- Builds the Python package structurepython_wheel- Creates the distributable wheel filepython_install- Installs the wheel into your Python environment
windows-msvc-release- Optimized release build with MSVCwindows-msvc-debug- Debug build with full symbolswindows-msvc-relwithdebinfo- Release with debug info (recommended)windows-clang-release- Release build using Clangwindows-clang-debug- Debug build using Clang
library-only-release- Just the C++ library, no Pythonlibrary-only-debug- Debug C++ library only
The build system searches for dependencies in standard locations. You can override these by setting CMake variables:
cmake --preset windows-msvc-release \
-DBOOST_ROOT="C:/path/to/boost" \
-DEIGEN3_INCLUDE_DIR="C:/path/to/eigen3" \
-Dscs_DIR="C:/path/to/scs/lib/cmake/scs"choco install boost-msvc-14.3 eigen swigvcpkg install boost:x64-windows eigen3:x64-windowssudo apt-get install libboost-all-dev libeigen3-dev swigIf you have the ISDA CDS model library installed:
cmake --preset windows-msvc-release \
-Disda_cds_model_DIR="C:/path/to/isda_cds_model"To use a specific Python installation:
cmake --preset windows-msvc-release \
-DPython3_EXECUTABLE="C:/path/to/python.exe"Speed up compilation with parallel jobs:
cmake --build build/windows-msvc-release --target python_all --parallel 8The build system automatically embeds metadata into the compiled libraries:
- Build timestamp - When the library was built
- Build user/machine - Who built it and where
- Configuration details - Which features were enabled
Access this information in Python:
import QuantLib as ql
print(ql.get_full_build_info())If CMake reports Could NOT find SWIG:
- Install SWIG 4.0 or later
- Add SWIG to your PATH, or
- Specify the path:
-DSWIG_EXECUTABLE=C:/path/to/swig.exe
The build will fail if required dependencies aren't found. Check the CMake output for specific error messages about missing packages.
If the built module won't import:
- Ensure all runtime dependencies are available
- Check that the Python version matches your environment
- On Windows, you may need to install Visual C++ Redistributables
QuantLib-Build/
├── CMakeLists.txt # Main build configuration
├── CMakePresets.json # Predefined build configurations
├── process_quantlib_py.cmake # Helper for Python timestamp injection
├── README.md # This file
├── QuantLib/ # C++ library source (cloned as subdirectory)
│ └── ...
└── QuantLib-SWIG/ # Python bindings source (cloned as subdirectory)
└── ...
This build system is maintained as part of the Model-Validation QuantLib ecosystem. For issues or improvements, please open an issue on the respective GitHub repository.
This build system is provided under the same BSD-style license as QuantLib. See LICENSE file for details.