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
justfilecommands should be run under a shell in which your.bashrc,.zshrcor equivalent has been sourced. Do not use the run button in your IDE,pyenvwill 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-depsFirst ensure you have pyenv and pyenv-virtualenv installed. Then:
just py-depsCheck if you already have a Conan profile with conan profile list. If you haven't already made one, create one:
just conan-profileThen, 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 = LinuxNote 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-depsFirst, go in the justfile and set the paths to the C and C++ compilers.
Then either run:
just cmake-configor 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 buildTo build a specific target:
just build docsTo run the default target with the default arguments specified in the justfile:
just runTo run a specific target:
just run cpp_projectTo run a target with arguments:
just run cpp_project arg1 arg2 arg3To open the documentation (must be built first via just build docs):
just docsTo 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 casejust testWhile developing, you may want to have some tasks automatically run with pre-commit.
just pre-commitCleans the build directory.
just cleanYou'll need to make the project's Conan dependencies and run the CMake config again with just conan-deps cmake-config.