## Build under Windows

The following instructions have been tested under Windows 10.

### Prerequisites

#### Visual Studio

Download Visual Studio Community Edition from from the official website visualstudio.microsoft.com The current build instructions are tested with Visual Studio 2022.

#### Qt

Download Qt from from the official website qt.io

> Make sure to choose the open source version of Qt and download the online installer.

Select the latest Qt version with long-time support (LTS) and open the sub tree. To build BornAgain, only the ‘MSVC 2019 64-bit’ component is needed. Qt Installer Framework is required for creating the installer executable.

Make a symbolic link to the directory corresponding to the current Qt version: if `Qt 6.y.z` (e.g. `Qt 6.3.5`) installed in `C:\Qt\6.y.z`, then in Windows `cmd` (with administrative rights) execute:

    $ mklink /D "C:\Qt\current" "C:\Qt\6.y.z"
    $ mklink /D "C:\Qt\msvc" "C:\Qt\6.y.z\msvc2019_64"

#### CMake

Download the Windows x64 Installer from the official website cmake.org/download

#### Python + Packages

Python and some Python modules must be installed, as described in Python on Windows.

#### SWIG

If you want to re-build the Python-API with SWIG, download and install SWIG from the official website swig.org/download.html. Installation instructions are at http://www.swig.org/Doc4.1/windows.html.

Unpack the ZIP file and add its folder to PATH (so e.g. `C:\swigwin-4.0.2`).

#### Libraries

Download

- from https://computing.mlz-garching.de/download/WinLibs:
  - `libfftw3.win64.zip` (fast Fourier transform)
  - `libtiff.win64.zip` (Support for TIFF images)
  - `gsl_*_win64_shared.zip` (GNU Scientific Library)
  - `boost_*.7z` (C++ Library boost, including BZIP2 and ZLib)
- from https://jugit.fz-juelich.de/mlz/libcerf/-/releases
  - from latest release > Asserts > Packages, `cerfcpp-*-win64.zip`
- from https://jugit.fz-juelich.de/mlz/libformfactor/-/releases/
  - from latest release > Asserts > Packages, `formfactor-*-win64.zip` Create the folders

`C:\opt\x64\include`
`C:\opt\x64\lib`

and paste the corresponding content from the ZIP files in those two folders.

#### System Enviroment Variables

After those installations your `PATH` should contain

    C:\Qt\6.y.z\msvc2019_64\bin
    C:\Program Files\Python39\Scripts\
    C:\Program Files\Python39\
    C:\opt\x64\include
    C:\opt\x64\lib
    C:\Program Files\CMake\bin

### Build

With all prerequisites completed, you should be able to build and test BornAgain in a PowerShell. In there, execute

    $OPTDIR = "C:/opt/x64"
    $FFTW3_INCLUDE_DIR = "$OPTDIR/include"
    $FFTW3_LIB = "$OPTDIR/lib/libfftw3-3.lib"
    $QTDIR = "C:/Qt/current/msvc2019_64"
    $QTCMake_DIR = "$QTDIR/lib/cmake"
    $BUILD_DIR = "build"

    mkdir -Force "$BUILD_DIR"
    cd "$BUILD_DIR"

    cmake -G "Visual Studio 17 2022" -A x64 -T host=x64 -DQTDIR="$QTDIR" -DQt6_DIR="$QTCMake_DIR/Qt6" -DQt6Test_DIR="$QTCMake_DIR/Qt6Test" -DFFTW3_INCLUDE_DIR="$FFTW3_INCLUDE_DIR" -DFFTW3_LIBRARY="$FFTW3_LIB" -DCMAKE_INCLUDE_PATH="$OPTDIR/include" -DCMAKE_LIBRARY_PATH="$OPTDIR/lib" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -B. ..

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

    ctest -C Release --parallel 8 --output-on-failure

Build with Ninja

Compilation might be accelerated if Ninja is used as a build system. Download the Ninja binary for Windows from ninja-build.org. Add the binaries to a directory in your `PATH`; e.g. `C:\Program Files\ninja`.

To use Ninja as the build system, the compilation cannot be performed in a PowerShell but in the Visual Studio Shell x64 Native Tools Command Prompt for VS 2019 which you can search for in the start menu.

Use the following commands to build BornAgain:

    set OPTDIR=C:/opt/x64
    set FFTW3_INCLUDE_DIR=%OPTDIR%/include
    set FFTW3_LIB=%OPTDIR%/lib/libfftw3-3.lib
    set QTDIR=C:/Qt/current/msvc2019_64
    set QTCMake_DIR=%QTDIR%/lib/cmake
    set BUILD_DIR=buildnj

    mkdir "%BUILD_DIR%"
    cd "%BUILD_DIR%"

    cmake --version

    cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DQTDIR="%QTDIR%" -DQt6_DIR="%QTCMake_DIR%/Qt6" -DQt6Test_DIR="%QTCMake_DIR%/Qt6Test" -DFFTW3_INCLUDE_DIR="%FFTW3_INCLUDE_DIR%" -DFFTW3_LIBRARY="%FFTW3_LIB%" -DCMAKE_INCLUDE_PATH="%OPTDIR%/include" -DCMAKE_LIBRARY_PATH="%OPTDIR%/lib" -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -B. ..

    echo "## BUILD START:" %time%
    cmake --build . --config Release --parallel 8
    cmake --build . --config Release --target ba_wheel

    echo "## BUILD END:" %time%
    ctest -C Release --parallel 8 --output-on-failure

- Introduction
  - Functionality overview
  - Architectural overview

- Install or build
  - Install Python
    - Python on Linux
    - Python on Windows
    - Python on Mac
    - Python modules
  - Install BornAgain
    - Linux
    - Windows
    - MacOS
    - Development snapshot
  - Build BornAgain
    - Unix
      - Install third-party software
      - Get the source
      - Build and install BornAgain
      - Run a first simulation
    - Windows

- Graphical user interface
  - Quick Start
  - GUI overview
  - Fitting in the GUI

- Python scripting
  - Run a script
  - Understand the syntax
  - Fitting
  - Upgrading

- Reference
  - Simulation model
    - Simulation classes
      - Specular
        - Example
      - Scattering
        - Examples
          - GISAS
          - without DWBA terms
          - with specular peak
          - SAS
          - Polarized SANS
          - Monte-Carlo
      - Off-specular
        - Off-specular
      - Depth probe
        - Examples
          - Thin film
          - Transmitted modulus
          - Resonator
    - Common settings
      - Background
      - Options
        - Monte-Carlo
        - # threads
        - Average materials
        - Include specular
      - Progress monitor
  - Instrument model
    - Beam
      - Footprint
      - Beam divergence
    - Scan
      - TOF reflectometry
      - TOF resolution
      - Beam Angular Spread
      - Beam Wavelength Spread
    - Detectors
      - SphericalDetector
      - 2d detector resolution
      - Offspec detector
    - Neutron polarization
      - Spin asymmetry example
    - Examples
      - 2D detector resolution
      - Neutron polarization
        - Magnetic layer
        - Ditto, realistic instrument
        - Polarized scattering
  - Sample model
    - Materials
      - Magnetization
    - Sample
      - Layer
      - LayerStack
      - Layout
    - Roughness
      - Interface model
      - Transient
      - Cross-correlation
      - Examples
        - GISAS
        - Reflectivity
    - Particles
      - Form factor
        - Hard particles
          - Bipyramid4
          - Box
          - CantellatedCube
          - Cone
          - Cylinder
          - Dodecahedron
          - EllipsoidalCylinder
          - HemiEllipsoid
          - HorizontalCylinder
          - Icosahedron
          - PlatonicOctahedron
          - PlatonicTetrahedron
          - Prism3
          - Prism6
          - Pyramid2
          - Pyramid3
          - Pyramid4
          - Pyramid6
          - Sphere
          - SphericalSegment
          - Spheroid
          - SpheroidalSegment
          - TruncatedCube
        - Ripples
          - Bar ripple
          - Cosine ripple
          - Sawtooth ripple
        - Soft particles
          - FuzzySphere
          - Gauss
        - Custom formfactor
      - Composite particles
        - Core and shell
        - Compound particle
        - Mesocrystal
      - Examples
        - Compound particle
        - Core and shell
        - Crossing an interface
        - Mesocrystal
        - Rotation example
        - Dense cylinders
        - Dense hemispheres
        - Uncorrelated mixture
        - Polydispersity
    - Particle assemblies
      - Grating
        - 1D lattice
        - Cosine ripples in a lattice
        - Triangular ripples in a lattice
      - 2D lattice
        - Square lattice
        - Lattice orientation distribution
        - Finite square lattice
        - Lattice with basis
        - Multi-layer lattice
        - Position variance
      - Radial paracrystal
      - 2D paracrystal
      - Others
        - Size-distribution model: decoupling approximation
        - Size-distribution model: local monodisperse approximation
        - Size-distribution model: size-spacing coupling approximation
  - Model modifiers
    - Rotation
    - Distributions
  - Data types
    - Class Datafield
      - Export
      - Find intensity peaks
    - SLD profile
      - SLD profile with rough interfaces
      - SLD profile with a sliced particle layer
  - Plotting
    - Functions
    - Configuration
    - Heat map
    - LaTeX markup
    - Export
    - Plot axes in different units
  - Fitting
    - Data import
      - TIFF
    - Minimizer settings
    - Multiple datasets
    - Examples
      - Fitting with masks
      - Custom objective function
      - Fitting along slices
      - GISAS 2D fits
      - Experiment at GALAXI
      - Find background
      - Minimizer settings
      - Bayesian Sampling
      - Consecutive fitting
      - Considering uncertainties
      - External minimizer
      - External minimizer: plotting
      - Simultaneous fit of two datasets
      - Spin asymmetry fit example
      - Reflectometry: Fit Pt layer
      - Reflectometry: Fit honeycomb

- Literature
  - Babonneau2010
  - Babonneau2013
  - Croset2021
  - Lazzari2002
  - Lazzari2006
  - Pospelov2020
  - Renaud2009
  - Sears1992
  - Wuttke2021

- How to
  - Get announcements
  - Solve known problems
    - Set Python environmental variables under Windows
  - Request help or report bugs
  - Cite BornAgain

- Developers' corner
  - Configure
    - Build
    - Pyenv
  - Develop
    - Manual checks
    - Debug
    - Webdoc
    - Code analyses
  - Release
    - Manual GUI test