Skip to content

GLaDOS-418/cpp-project-template

Repository files navigation

Modern C++ Project Template

A basic project template for modern C++. Below are some better resources:

Setup Progress

Use the latest version of everything.

- [x] Compiler                        : clang++
- [x] Build                           : cmake
- [x] Package Management              : conan2.0
- [x] Unit Testing                    : catch2
- [x] Static Code Analysers           : clang-tidy
- [x] Code Formatter                  : clang-format
- [ ] Code Coverage                   : gcov
- [ ] Consolidate Built Artifacts     : cpack
- [x] Sharable Dev Environment        : docker
- [ ] CI workflows                    : github workflows
- [ ] Code documentation              : doxygen
- [ ] Mocking Framework               : gmock
- [ ] Fuzz Testing                    : libfuzzer
- [ ] Ccache Integration              : ccache
- [ ] Header File Manager             : include-what-you-use
- [x] Language Server                 : clangd

Build Instructions

  • create application and test executables
  • use conan 2.0
  • generate a default conan profile. update profile in the build in makefile if not default.
$ make clean     ## remove build dir
$ make deepclean ## remove build dir + remove conan cache
$ make format    ## format code using clag-format
$ make package   ## installs all package dependencies (using conan)
$ make build     ## build project inside build dir ( +package +format)
$ make rebuild   ## equivalent to `clean + build`
$ make test      ## run tests from test folder
$ make testprint ## run only failed tests and ouput on stdout
$ make image     ## build docker image using .devcontainer/Dockerfile for dev
$ make terminal  ## start a terminal and load current project dir as a volume
  • check build in Makefile for step by step build process
  • the cmake built artifacts are in the build folder.
  • build logs are in the logs folder.
  • to clear conan cache, run : $ conan remove -f '*'
  • here's a sample conan profile which can be gerenated using the command
  • conan.profile is used as a custom conan profile.
  • docker image generated from $ make image is cppdev:latest.
  • docker container started from $ make terminal is cppdev_container.
$ conan profile detect ## creates a default conan profile
$ cat ~/.conan2/profiles/default
[settings]
arch=x86_64
build_type=Debug
compiler=clang
compiler.cppstd=gnu23
compiler.libcxx=libstdc++11
compiler.version=18
os=Linux

New Project

you can add below function to your ~/.bashrc to set up new projects.

  • $ new_cpp_project foobar
  • creates a new project, foobar, with all the contents of basic branch of this repo.
  • provide the name of the new project as argument.
function new_cpp_project {
  if [ ! ${1} ]
  then
    echo "project name not supplied..."
    return
  fi

  git clone --depth 1 --single-branch --branch basic [email protected]:GLaDOS-418/cpp-project-template.git ${1}
  cd ${1}
  /usr/bin/rm -rf .git
  echo "# ${1}" >| README.md
  grep -rl --color=never 'project_name' | xargs sed -i "s/project_name/${1}/g"
  git init
  git add -f .
  git commit -m "created project ${1}."

  echo " ========================   PROJECT ${1} SETUP COMPLETE.  ======================== "
}

Clang-Format

  • the config in the repo is generated using the tool itself:
    • $ clang-format -style=chromium -dump-config > .clang-format.
  • supported styles: google, llvm, gnu, mozilla, chromium, microsoft, webkit.
  • change .clang-format file to customize.

Clang-Tidy

  • TODO: cppcheck can be an addendum.

Clangd

  • modify .clangd file
  • .clang-tidy options are merged with .clangd when IDE suggests.

Guidelines

About

A modern C++ Project Template.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published