HIV transmission dynamic model
- C++ compilation toolchain can be installed via Visual Studio, see step 3 from link
- CMake (>=3.15) for packaging.
- Boost (>=1.82, <=1.85>) installed. The easiest way I find to do this, on windows, is to install one of the prebuilt binaries linked from the download page.
- Catch2 (optional) for testing. It will be fetched by CMake if you do not have it installed locally.
If you just want to get developing in the recommended way with Visual Studio Code on Windows, follow these steps
- Install pre-requisites above and VSCode.
- Install the C/C++ extension for VSCode and CMake Tools extension.
- Copy the
cmake/CMakeUserPresets.jsonfrom thecmakedirectory into the root. - Open the project in VSCode. You will be prompted to select a "Preset". If not, do this manually by opening command palette (Ctrl+Shift+P) and running "CMake: Select Configure Preset" and select "default".
- You should see VSCode compiling your code automatically. It will create a
builddirectory with generated files and compiled code. VSCode will manage when compilation is required. - Create a file
launch.jsoninside a directory.vscodeat the root of this package. And add the contents for your operating system from here. On Windows, this ismsvc. - You are now ready to develop.
You can run and debug tests from the testing tab in VSCode. You can run and debug scripts from the run and debug interface. VSCode will recompile before running a test or a script if it is necessary. If you want to manually compile the project you can do it via the CMake extension.
This project uses CMake & CMakePresets to manage different builds. CMake can manage several stages of dev lifecyle. We will use it to manage configure, build & test.
configuregenerates build system files (Makefiles, Ninja files or VS project files) in thebuilddirectory, and locates dependencies. It does not compile any code.buildthis compiles the code and produces outputs (executables, libraries). This will invoke the appropriate build tool (make, ninja or msbuild).testruns tests withctest.
We have the following presets configured for each stage
- Configure
- default
- ci
- build
- debug
- release
- test
- debug
- release
You can use these as follows
# Configure
cmake --preset=default
# Build
cmake --build --preset=debug
# Test
ctest --preset=debugNote you only need to re-run the configuration step if you modify CMakeLists.txt, or want to set some CMake variable like the build type. If you have just updated source code, just running cmake --build build should be enough.
Testing uses Catch2 and is run via ctest. To add a new test, you can extend the existing tests/tests.cpp or any new file within the tests directory with the .cpp extension will be picked up automatically.
Should work with CMake out of the box.
- Install C/C++ extension from Microsoft
- Install CMake Tools extension from Microsoft
- At the time of writing, VSCode's CMake extension does not pick up env variables in preset config, so we need to work around it. Copy the
cmake/CMakeUserPresets.jsonfrom thecmakedirectory into the root. User presets are a CMake tool for individual users to write specific overrides of configuration inCMakePresets.json. Copy the file over, and in theinheritblock ensure that this is inheriting from the correct presets for your systemcmake/CMakeWindowsPresets.jsonon Windows. - Open the project in VSCode.
- Specify the configure "preset" by opening command palette (Ctrl+Shift+P) and running "CMake: Select Configure Preset" and select "default".
- You should see VSCode compiling your code automatically. It will create a
builddirectory with generated files and compiled code. You can turn off automatic compilation and do it manually if you prefer. - (Optionally) Select the build & test presets by using command palette and running "CMake: Select Build Preset" and "CMake: Select Test Preset". Choose either "vscode-debug", to build with debug symbols and no optimisation, or "vscode-release" to build with optimisation and without debug symbols. For most uses you probably want the "vscode-debug" build. It will work without selecting one of these presets, and will build in debug mode.
- You should now be able to build and debug by using the "Build" and "Debug" buttons in the bottom bar of VSCode. Note that any compilation buttons shown in the top right won't work as these are not being compiled using the CMake configuration.
- You should be able to run individual tests from the testing tab, but to debug from the testing tab you'll need to add a launch.json.