A basic project template for modern C++. Below are some better resources:
- filipdutescu/modern-cpp-template
- cpp-best-practices/cmake_template
- cpp-best-practices/cpp_starter_project - ARCHIVED
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
- create application and test executables
- use conan 2.0
- generate a default conan profile. update profile in the
build
inmakefile
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
inMakefile
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
iscppdev:latest
. - docker container started from
$ make terminal
iscppdev_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
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 ofbasic
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. ======================== "
}
- 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.
- TODO:
cppcheck
can be an addendum.
- modify
.clangd
file .clang-tidy
options are merged with.clangd
when IDE suggests.
- C++ Core Guidelines
- Google C++ Style Guide
- LLVM Coding Standards — LLVM 19.0.0git documentation
- Chromium C++ style guide
- C++ Coding style — Firefox Source Docs documentation
- Code Style Guidelines | WebKit
- GNU Coding Standards
- Epic C++ Coding Standard For Unreal Engine
- C++ Coding Standards and Style Guide - NASA Technical Reports Server (NTRS)