Build under Windows

These instructions build and test the Python module and create a wheel.

Prerequisites

See Build dependencies for the supported versions of shared tools and libraries.

Visual Studio

Install Visual Studio with an x64 C++20 toolchain from visualstudio.microsoft.com.

CMake and Ninja

Install CMake using the Windows x64 installer from cmake.org/download. Install Ninja from ninja-build.org.

Python

Prepare an isolated Python environment with the packages listed under Build dependencies.

SWIG (developer builds only)

SWIG regenerates the Python API wrappers under auto/Wrap/. It is needed only when configuring with -DDEV=ON or -DCONFIGURE_BINDINGS=ON, as required after changes to the C++ API. Download it from swig.org/download.html, unpack the ZIP, and add the folder containing swig.exe (e.g. C:\swigwin) to PATH.

Compiler launcher (optional)

buildcache.exe or another compiler launcher reduces rebuild times.

Libraries

Run the commands below in a Visual Studio developer PowerShell configured for an x64 toolchain.

The BornAgain dependencies are installed into two prefixes: C:/opt/vcpkg/installed/x64-windows for standard libraries and C:/opt/x64 for the MLZ-maintained ones.

Standard libraries (fftw3 and gsl) are installed via vcpkg into C:/opt/vcpkg/installed/x64-windows. Follow the official vcpkg setup guide, install it under C:/opt/vcpkg, and run:

C:/opt/vcpkg/vcpkg.exe install fftw3 gsl --triplet x64-windows

Alternatively, unpack the FFTW3 and GSL shared-library packages from the WinLibs archive into C:/opt/x64.

MLZ-specific libraries must be installed into C:/opt/x64:

  • libcerf: download the Windows x64 package from the latest libcerf release, then unpack it into C:/opt/x64.

  • libformfactor: download the Windows x64 package from the latest libformfactor release, then unpack it into C:/opt/x64.

  • libheinz: download the source from the latest libheinz release and build:

    mkdir build
    cd build
    cmake .. -DCMAKE_INSTALL_PREFIX="C:/opt/x64"
    cmake --build . --config Release
    cmake --install . --config Release
    

Environment paths

Make sure the executable directories for Python, CMake, and Ninja (and SWIG, if used) are available in PATH. The dependency prefixes are passed to CMake through CMAKE_PREFIX_PATH; their runtime DLL directories must also be in PATH when running tests. For example:

$PYTHON = "C:/path/to/venv/Scripts/python.exe"
$OPT_DIR = "C:/opt/x64"
$VCPKG_DIR = "C:/opt/vcpkg/installed/x64-windows"
$SWIG_DIR = "C:/swigwin"

$PYTHON_DIR = Split-Path "$PYTHON"
$DLL_DIRS = "$VCPKG_DIR/bin;$OPT_DIR/bin;$OPT_DIR/lib"
$env:PATH = "$PYTHON_DIR;$SWIG_DIR;$DLL_DIRS;$env:PATH"

If CMake cannot find headers or libraries, check that C:/opt/x64/include, C:/opt/x64/lib, and the vcpkg prefix are covered by the CMAKE_PREFIX_PATH used below.

Configure

Create and enter the build directory:

$BUILD_DIR = Join-Path $PWD "build"
mkdir -Force "$BUILD_DIR"
cd "$BUILD_DIR"

Configure with Ninja:

cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=Release `
  -DCMAKE_PREFIX_PATH="$OPT_DIR;$VCPKG_DIR" `
  -DPython3_EXECUTABLE="$PYTHON" `
  -DBA_PY_PACK=ON

When using buildcache.exe, add -DCMAKE_CXX_COMPILER_LAUNCHER="buildcache.exe" to the command.

For development, add the required developer options.

Build and test

cmake --build . --config Release --parallel
cmake --build . --config Release --target ba_wheel

Before running tests, make the freshly built Python package visible:

$env:PYTHONPATH = "$BUILD_DIR/py/src/"

Then run:

ctest -C Release -j8 --output-on-failure

The wheel is placed under build/py/wheel/.

See Run tests for further CTest commands.