Skip to content
/ cpp_project Public template

Template for a modern C++ project using CMake.

Notifications You must be signed in to change notification settings

rdong8/cpp_project

Repository files navigation

cpp_project

Template for a modern C++ project using CMake.

Read through both the README and the justfile to better understand how everything works.

Notes

  • Only Linux is supported
  • All justfile commands should be run under a shell in which your .bashrc, .zshrc or equivalent has been sourced.

Clone

git clone --recurse-submodules https://github.com/rdong8/cpp_project.git
cd cpp_project/

Dependencies

Python

First ensure you have uv installed. Then:

just venv # Creates a virtual environment
just py-deps # Installs the Python dependencies. Use `just py-deps 1` to force a reinstall.

Conan

Profile

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, edit the $(conan config home)/profiles/default profile that was generated by running just edit-conan-profile.

[buildenv]
CC=clang
CXX=clang++

[conf]
# tools.build:exelinkflags=["-fuse-ld=mold"]
# tools.build:sharedlinkflags=["-fuse-ld=mold"]
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config
# Paths to your compilers if they're not `clang` and `clang++`
# tools.build:compiler_executables={"c": "clang-19", "cpp": "clang++-19"}

[platform_tool_requires]
# Tell Conan to look for CMake on the machine instead of installing it itself
cmake/3.30

[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=23 # TODO: 26 causing problems
compiler.libcxx=libc++
compiler.version=19
os=Linux

# TODO: Causes dependency loop
# [tool_requires]
# !mold/*: mold/[*]

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.

Build Dependencies

Now build the project's C++ dependencies with Conan:

just conan-deps

Configure

First, go in the justfile and set the paths to the C and C++ compilers.

Then run:

just config

Build

To build the default target with the default arguments specified in the justfile:

just build

To build a specific target:

just build docs

Run

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

Docs

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

Test

just test

Pre-Commit

While developing, you may want to have some tasks automatically run with pre-commit.

just pre-commit

Clean

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 config.

About

Template for a modern C++ project using CMake.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published