Project State
Co[ro]nan was written during the pandemic of the Corona Virus. The The About Corona Covid-19 API used for the first version is no longer available. However with COVID-19 Statistics API an alternative was found. Unfortunately the COVID-19 Statistics API does have a different data structure, and retrieving data is much slower, because the API does not support timeline data, i.e. every data for specific date requires a GET. But at least the application works again. And the name didn't have to change.
Co[ro]nan is an example C++20 CLI and Qt project using conan and CMake. It reads the latest data of Corona (Covid-19) cases for a country from the COVID-19 Statistics API.
The COVID-19 Statistics API provides statistics via REST API from the Johns Hopkins CSSE.
Expand contents
This projects is a C++ project template. It includes everything a "Modern" C++ project possibly needs:
-
C++ 20 Standard
-
conan package Manager
-
Libraries used:
- Qt6 (minimal version required: 6.4)
- Poco Networking library
- RapidJSON
- Lyra command line arguments parser
- {fmt} formatting library (std::print is C++23 and therefore not used yet)
- date date and time library (std::chrono::year_month_day is not fully supported in older c++20 compilers (gcc 12, 13 and clang 13-16) therefor it is not used yet)
-
Unittests with Coverage using Catch2
-
CMake with CMakePresets (CMake >= 3.23)
-
CPack packaging:
- Debian package
- Qt Installer Framework
- WIX
-
Build Caching support:
-
Static Analyzer support:
-
Sanitizers support:
-
Documentation Generation using
-
Code formatting:
- clang-format for C++ files
- cmake-format for CMake files
-
Pre-commit-hooks support
-
Nix environment support
-
gitpod support
-
Continuous integration (CI):
-
GitHub Action
-
Mac OS X
- 13 (AppleClang 14)
- 14 (AppleClang 15)
- 15 (AppleClang 15)
-
Ubuntu 22.04
- GCC 12
- Clang 13, 14 & 15
-
Ubuntu 24.04
- GCC 13 & 14
- Clang 16, 17 & 18
-
Windows
- Visual Studio 2022
-
Nix
- GCC 14
- Clang 18
-
Codecov Coverage Reporter
-
-
- Windows Visual Studio 2019
-
To build the project you need python and a recent conan version, a recent version of CMake (>= 3.23), a modern C++ compiler (C++20 support) and Qt6 with QtCharts.
To install all python requirements for documentation generation, build and coverage generation (including conan and cmake) use:
pip3 install -r py-requirements.txt
You have the following options to build the project
Use build script:
In a linux shell you can build the project with the provided build.sh
script. E.g. to build in folder build
execute:
./build.sh ./build
See ./build.sh -h
for more options
CMake:
You can also build it yourself using CMake and conan
-
Install dependencies with conan
conan install . --build=missing --settings=build_type=Debug
Because the conan cmake_layout and the
CMakeDeps
generator is used, the necessary cmake files used withfind_packages()
are generated intobuild\<build_type>\generators
.CMAKE_PREFIX_PATH
is adapted accordingly in the rootCMakeLists.txt
. -
Without CMake Presets
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Debug cmake --build ./build
-
With CMake Presets
cmake -S . --preset=linux-gcc-debug cmake --build --preset=gcc-debug
or any other CMakePresets.
For source code formatting clang-format for C++ files and cmake-format for the CMake files are used. Run format_source_files.sh
to format all C++ and CMake files.
Note: Delete the build directory before formatting, otherwise all CMake files in the build folder will be formatted as well, what may take a while.
DOWNLOAD_QT6
: Download and build Qt6 otherwise use installed. Default:OFF
ENABLE_TESTING
: Build (and run) unittests. Default:ON
ENABLE_BUILD_WITH_TIME_TRACE
: Enable Clang Time Trace Feature. Default:OFF
ENABLE_PCH
: Enable Precompiled Headers. Default:OFF
ENABLE_CACHE
: Enable caching if available, e.g. ccache or sccache. Default:ON
ENABLE_COVERAGE
: Enable coverage reporting for gcc/clang. Default:OFF
ENABLE_DOXYGEN
: Enable doxygen documentation build (Doxygen must be installed). Default:ON
if Doxygen is installedOFF
otherwise._ENABLE_SPHINX
: Enable sphinx documentation build (Sphinx with Breath and sphinx-mdinclude must be installed). Default:ON
if Sphinx is installedOFF
otherwise._ENABLE_SANITIZERS
: Enable supported sanitizers". Default:OFF
ENABLE_SANITIZER_ADDRESS
: Enable address sanitizer. Default:ON
if supported by the compiler andENABLE_SANITIZERS
==ON
otherwiseOFF
.ENABLE_SANITIZER_LEAK
: Enable leak sanitizer. Default:OFF
ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
: Enable undefined behavior sanitizer. Default:ON
if supported by the compiler andENABLE_SANITIZERS
==ON
otherwiseOFF
.ENABLE_SANITIZER_THREAD
: Enable thread sanitizer. Default:OFF
ENABLE_SANITIZER_MEMORY
: Enable memory sanitizer. Default:OFF
ENABLE_IPO
: Enable intermodular optimization, aka Link Time Optimization (LTO). Default:OFF
ENABLE_CPPCHECK
: Enable static analysis with cppcheck. Default:ON
if cppcheck is installedOFF
otherwise.ENABLE_CLANG_TIDY
: Enable static analysis with clang-tidy. Default:ON
if clang-tidy is installedOFF
otherwise.ENABLE_INCLUDE_WHAT_YOU_USE
: Enable static analysis with include-what-you-use. Default:ON
if include-what-you-use is installedOFF
otherwise.ENABLE_LINK_WHAT_YOU_USE
: Enable link what you use cmake built-in static analysis. _Default:OFF
WARNINGS_AS_ERRORS
: Treat compiler warnings as errors. _Default:OFF
The following Pre-commit-hooks are used to check and format files before committing:
check-added-large-files
: Prevent giant files (> 500kB) from being committed.fix-byte-order-marker
: Forbid files which have a UTF-8 byte-order markercheck-case-conflict
: Check for files with names that would conflict on a case-insensitive filesystem like MacOS HFS+ or Windows FAT.check-merge-conflict
: Check for files that contain merge conflict strings.check-symlinks
: Checks for symlinks which do not point to anything.check-yaml
: Attempts to load all yaml files to verify syntax.check-json
: Attempts to load all json files to verify syntax.check-toml
: Attempts to load all TOML files to verify syntax.check-executables-have-shebangs
: Checks that non-binary executables have a proper shebang.end-of-file-fixer
: Makes sure files end in a newline and only a newline.mixed-line-ending
: Replaces or checks mixed line ending.trailing-whitespace
: Trims trailing whitespace in markdownclang-format
: Format C++ files using clang-formatcmake-format
: Format CMake files using cmake-formatyamllint
: Linter for yaml filesyamlfmt
: Format yaml files
Please install pre-commit hooks before committing any code.
pre-commit install -f --hook-type pre-commit
To manually check all files run:
pre-commit run --all-files
To start right away without installing anything on your local machine, you can simply use the button in the Project State section at the top of this README.
If you have direnv and nix installed everything should be setup to start upon entering the project folder, if use nix
is not commented out in .envrc. gcc (gcc14) is set as default C and C++ compiler. If you prefer clang (clang_18) change it in .envrc
You can also use nix-shell
directly to build when use nix
is disabled, e.g.:
nix-shell --command "conan profile detect"
nix-shell --command "conan install . --build=missing --settings=build_type=Debug"
nix-shell --command "cmake -S . --preset=linux-debug-ninja
nix-shell --command "cmake --build --preset=ninja-debug
When using nix, a new cmake is available and therefore configure and build CMakePresets can be used.