The COVID-19 CovidSim model uses the CMake build tool to generate build files for other build systems. Currently, building using clang and gcc with Makefiles and MSVC with Visual Studio are supported.
To build CovidSim
from the command line you need to have the following tools
and libraries installed:
- git Source code control.
- Cmake >=3.8: Controls the build
- Make system (GNU Make, Ninja Build, MSBuild all have been tested)
- Compiler and related tools (GCC >=7, Clang >=10, MSVC >=16.6 have all been tested)
- OpenMP libraries: Strongly recommended, enables multi-threading.
- Python >=3.6: Used to drive the tests.
- Doxygen: Optional, used to generate documentation.
- GraphViz: Optional, used by doxygen to generate images in the documentation.
From the command line:
git clone https://github.com/mrc-ide/covid-sim
Configuring is slightly different depending on your platform
cd covid-sim
mkdir build
cd build
cmake ..
On Windows it is recommended to use Ninja Build as the make system instead of Visual Studio. This is to simplify the instructions following, and because CMake's support for Ninja Build is more feature rich. Ninja Build is installed with CMake in Visual Studio.
cd covid-sim
md build
cd build
cmake .. -G Ninja
Additional configuration variables can be provided in the cmake
invocation.
USE_OPENMP
determines whether the model is compiled with parallelization
using OpenMP. This option defaults to on, but can be disabled by passing
-DUSE_OPENMP=OFF
. The simulation is designed to be run on multi-core systems.
Performance improvements are approximately linear up to 24 to 32 cores,
depending on memory performance.
For Makefile builds, use -DCMAKE_BUILD_TYPE=
to specify the output format:
Debug
MinSizeRel
Release
RelWithDebInfo
By default, Makefile builds will use RelWithDebInfo
. To build a Debug build
you may invoke cmake
like the following:
cmake .. -DCMAKE_BUILD_TYPE=Debug
You may use a different build system to the default by using the -G <generator>
option to CMake.
In particular for Windows it may be useful to use the Ninja generator instead of the Windows one. For example:
cmake .. -G Ninja
cmake --build . --target all
If using the default Windows build system (MSBuild) you may also need to
specify the config in use with the --config <cfg>
command line option.
To specify how many cores the build system can use when building the tools use
the -j N
option, where N
is the number of CPUs to use. For example:
cmake --build . --target all -j 6
To run the tests do:
ctest
The tests can take a while, and may produce no user-visible output for >10 minutes. Therefore, it may be worthwhile to increase the verbosity of the tests:
ctest -V
The tests may be run in parallel by specifying -j N
to the command line. For
example:
ctest -V -j 6
If the output of CovidSim
has changed such that the tests start to fail and
you are happy that the changes in output are acceptable then the make target
test-accept
will update the expected test results.
To accept the test changes do something like the following in the build directory:
cmake --build . --target test-accept -j 6
git add tests/*-input/results-j*.cksum
git commit -m"Update expected results."
If doxygen
is installed there will be a doxygen
build target that builds
the documentation. Build the documentation as follows:
cmake --build . --target doxygen
Visual Studio 2019 supports using CMake to manage the build directly by
selecting File -> Open -> Cmake... and opening CMakeLists.txt
. Then
Visual Studio's normal build shortcuts will update the CMake configuration
as well as building the project.
CMake options are configured using the CMakeSettings.json
file, which
Visual Studio will generate when CMakeLists.txt
is opened.
To enable Visual Studio to pick up the tests added by CMake:
-
Open the
Tests
menu in the Visual Studio menu bar -
Choose
Run CTests
.
Because of the way Visual Studio runs the tests they can only be run serially. It is recommended that you use the command line for running tests.
If the output of CovidSim
has changed such that the tests start to fail and
you are happy that the changes in output are acceptable then the make target
test-accept
will update the expected test results. To do this in Visual
Studio do:
-
From the menu bar "View" menu choose "Solution Explorer"
-
At the top of the "Solution Explorer" window is a drop down menu icon (window and folder with circling arrows). From this menu choose "CMake Targets View".
-
In the tree that appears expand: "covid-sim", "CovidSim (executable)".
-
Right click on "test-accept (utility target)".
-
In the menu that appears click "Build".
A manually created VS-2019 solution and project is included for convenience, but it should not be considered the source of truth for the project.
The regression tests are not supported in the Visual Studio stand-alone solution.
The CMake custom target doxygen
builds the Doxygen documentation
(make doxygen
). Some IDEs do not expose this so alternatively setting the
BUILD_DOC
CMake option to ON
will cause the documentation to be built
every time the software is built regardless of whether anything has changed.
To generate any diagrams GraphViz must be installed.
The Doxygen warnings can be navigated to in Visual Studio:
-
From the
Tools
menu selectExternal Tools...
to launch theExternal Tools
dialogue box. -
Press the
Add
button. -
For
Title
enterCovidSim
. -
For
Command
entercmd.exe
. -
For
Arguments
enter/c type \path\to\warnings.txt
. -
Check
Use Output window
. -
Click
Apply
. -
From the
Tools
menu selectCovidSim
to replay the file. -
Double click on a line in the
Output
window which begins with a filename to jump to that file.