Build under Windows

The following instructions have been tested under Windows 10 Pro.

Prerequisites

Visual Studio

Download Visual Studio Community Edition from from the official website visualstudio.microsoft.com

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 Qt 5.15.0 (LTS) and open the sub tree. Only ‘MSVC 2019 64-bit’ component is needed.

Make a symbolic link to the directory corresponding to the current Qt version; e.g., if Qt 5.15.0 is installed in C:\Qt\5.15.0, then in Windows cmd (with administrative rights) execute:

$ mklink /J "C:\Qt\current" "C:\Qt\5.15.0"

CMake

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

Python + Packages

Next up, download Python 3.9. For that, go to python.org/downloads/, look for Python 3.9.x and download the Windows installer (64-bit). Follow the setup and make sure to add Python to PATH.

Once Python is set up correctly, install numpy. Therefore open a PowerShell and type the command:

pip install numpy

Analogously install matplotlib with

pip install matplotlib

MSYS + pkg-config

Go to msys2.org and follow the installation guide.

After the setup ist complete, you should be able to call the MSYS2 MSYS CLI. Install pkg-config with

pacman -S pkg-config

You should find the pkg-config binary under C:\msys64\usr\bin, add the directory to PATH.

SWIG

Install SWIG from the official website swig.org/download.html

Information can be found on [http://www.swig.org/Doc1.3/Windows.html#Windows_installation]

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

Libraries

Go to https://computing.mlz-garching.de/download/WinLibs/

From there download:

  • CERF: libcerf1.14.win64.zip
  • FFTW3: libfftw3.win64.zip
  • GSL (1.16): libgsl-static.win64.zip
  • TIFF (4.0.8): libtiff.win64.zip
  • BOOST (1.73.0): libboost1.73.win64.zip
    • Additional Boost dependencies are included:
      • BZIP2 (1.0.8)
      • ZLib (1.2.11)
      • LZMA (5.2.5)
      • ZSTD (only lib) version not available

Create the folders

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

and paste the corresponding content from the ZIP files in those two folders. On top of that, download the latest ZIP from the official website eigen.tuxfamily.org and copy the Eigen folder to C:\opt\x64\include

Additional: Ninja

The time to compile can be significantly improved, depending on the hardware, if Ninja is used as a build system. To download Ninja, go to ninja-build.org and download the Windows binary via GitHub. Add the binaries directory in your PATH, f.e. C:\Program Files\ninja.

System Enviroment Variables

After those installations your PATH should contain

C:\Qt\5.15.0\msvc2019_64\bin
C:\Program Files\Python39\Scripts\
C:\Program Files\Python39\
C:\opt\x64\include
C:\opt\x64\lib
C:\msys64\usr\bin
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

$OPTLIBS = "C:/opt/x64"
$FFTW3_INCLUDE_DIR = "$OPTLIBS/include"
$FFTW3_LIB = "$OPTLIBS/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 16 2019" -A x64 -T host=x64 -DLIB_MAN=OFF -DQTDIR="$QTDIR" -DQt5_DIR="$QTCMake_DIR/Qt5" -DQt5Test_DIR="$QTCMake_DIR/Qt5Test" -DFFTW3_INCLUDE_DIR="$FFTW3_INCLUDE_DIR" -DFFTW3_LIBRARY="$FFTW3_LIB" -DCMAKE_INCLUDE_PATH="$OPTLIBS/include" -DCMAKE_LIBRARY_PATH="$OPTLIBS/lib" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -B. ..

cmake --build . --config Release

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

Additional: Build with 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 serach for in the start menu.

set OPTLIBS=C:/opt/x64
set FFTW3_INCLUDE_DIR=%OPTLIBS%/include
set FFTW3_LIB=%OPTLIBS%/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%" -DQt5_DIR="%QTCMake_DIR%/Qt5" -DQt5Test_DIR="%QTCMake_DIR%/Qt5Test" -DFFTW3_INCLUDE_DIR="%FFTW3_INCLUDE_DIR%" -DFFTW3_LIBRARY="%FFTW3_LIB%" -DCMAKE_INCLUDE_PATH="%OPTLIBS%/include" -DCMAKE_LIBRARY_PATH="%OPTLIBS%/lib" -DLIB_MAN=OFF -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -B. ..

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

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