Template for a modern C++ project using CMake.
Read through both the README and the justfile
to better understand how everything works.
- Only Linux is supported
- All
justfile
commands should be run under a shell in which your.bashrc
,.zshrc
or equivalent has been sourced. Do not use the run button in your IDE,pyenv
will likely not work.
git clone --recurse-submodules https://github.com/rdong8/cpp_project.git
cd cpp_project/
This recipe uses dnf
and snap
to install dependencies of this project. You may need to modify the command for your
distro.
just system-deps
First ensure you have pyenv and pyenv-virtualenv installed. Then:
just py-deps
Check if you already have a Conan profile with conan profile list
. If you haven't already made one, create one:
just conan-profile
Then, modify the $(conan config home)/profiles/default
profile generated to add a [buildenv]
section, and put in
your compiler and language details:
[buildenv]
CC = clang
CXX = clang++
[settings]
arch = x86_64
build_type = Release
compiler = clang
compiler.cppstd = 23
compiler.libcxx = libc++
compiler.version = 18
os = Linux
Note that the build type here is for your dependencies, which you can compile in release mode even if you are building
your own code in debug. A variable conan_build_type
is provided in the justfile
to override the build type.
Now build the project's C++ dependencies with Conan:
just conan-deps
First, go in the justfile
and set the paths to the C and C++ compilers.
Then either run:
just cmake-config
or create a CMake profile in CLion with the following settings:
- Name: Debug
- Build type: Debug
- Toolchain: Use Default
- Generator: Ninja Multi-Config
- CMake options:
-G "Ninja Multi-Config" -DCMAKE_TOOLCHAIN_FILE=build/Debug/generators/conan_toolchain.cmake
- Build directory:
build/
- Build options: empty
- Environment: empty
To build the default target with the default arguments specified in the justfile
:
just build
To build a specific target:
just build docs
To run the default target with the default arguments specified in the justfile
:
just run
To run a specific target:
just run cpp_project
To run a target with arguments:
just run cpp_project arg1 arg2 arg3
To open the documentation (must be built first via just build docs
):
just docs
To open with a particular browser, pass the path to the command that will be passed the index.html
file of the
browser:
just docs firefox
just docs "flatpak run com.brave.Browser" # You need to use Flatseal to give the flatpak permission in this case
just test
While developing, you may want to have some tasks automatically run with pre-commit.
just pre-commit
Cleans the build directory.
just clean
You'll need to make the project's Conan dependencies and run the CMake config again with just conan-deps cmake-config
.