This template contains all the things you need to get started with a clean and modern C++ project (formatter, linter, tests, continuous integration, etc.). It works on all platforms (Windows, Linux, MacOS).
First, create your own repository based on this one. If you are using GitHub you can use this repository as a template:
Otherwise simply create a repository on your own and copy-paste all the files in this repo to your new repo.
NB: you might also want to change or remove the LICENSE file. Your project does not need to use the same license as the one we use for this template.
Run this command inside the directory where you want to put this project:
git clone your_repo_url
If that is not already done, install a compiler.
If that is not already done, setup your IDE for C++ development.
Once that is done, open the project folder in your IDE: it will detect the CMakeLists.txt file automatically and you can just run the project:
You should see this, with the circle following your mouse cursor:
🎉 Congrats you are almost done! But keep reading, we will now install amazing tools that will make your life so much easier!
First, you need to install and setup clangd. It will provide even better C++ support than the default extensions, and is also required for the other tools to work.
If you want to rename the project (called "Simple-p6-Setup" by default), you need to change it in 3 places:
- In the
CMakeLists.txt
, change the lineproject(Simple-p6-Setup)
- In the
src/main.cpp
, change the lineauto ctx = p6::Context{{.title = "Simple-p6-Setup"}};
All your source files (.cpp) and header files (.hpp) need to go in the src
folder. It is recommended to have the corresponding .cpp and .hpp next to each other:
src
main.cpp
some_folder
some_file.cpp
some_file.hpp
another_file.cpp
another_file.hpp
another_folder
a_third_file.cpp
a_third_file.hpp
p6 is a 2D-drawing library that is designed to be extremely simple to use. In order to learn how to use it, read their tutorials. (Note that you can skip the first chapter "Creating a project" as this template already does everything you need).
This template comes with the Doctest testing library all set up. You can simply write something like
TEST_CASE("Addition is commutative")
{
CHECK(1 + 2 == 2 + 1);
CHECK(4 + 7 == 7 + 4);
}
in any source file and the tests will run whenever you run your project. You will see their output in the console:
To learn more about Doctest, see https://github.com/doctest/doctest/blob/master/doc/markdown/tutorial.md
If you want to have warnings as errors in your local project too (typically in order to fix a warning shown by the CI):