Skip to content

Challanger524/template-cpp

Repository files navigation

Template C++ CMake

CMake CMakePresets Ninja EditorConfig VS Code PCH app

Feel free to pick any part or snippet you find interesting.

Examples

  • .editocronfig - "must have", rules: file encoding, end of lines, trailing spaces, final newline, ..
  • .gitignore - "must have"
  • CMake
    • CMakeLists.txt - single-file build-gen description for the project <-- the most interesting part
    • CMakePresets.json - define configurations for MSVC GCC Clang (debug), used by CMake implicitly and CMakeLists.txt explicitly via cacheVariables to configure the build
  • project structure
    • src/
      • config.hpp - (optional) precompiled header with project-wide c++ defines
      • main.cpp
    • possible folders/files: include/, src/<int|internal>/ dep/, doc/, res/, misc/, misc/<cmake|script|other>, (UN)LICNESE, changelog.md
    • possible tools: Tests, CI/CD, Git Hooks, Git Submodules, Linters, Package Managers
  • VS Code - IDE
    • .vscode/c_cpp_properties.json - config vscode-cpptools: language server, ..
    • .vscode/extensions.json - list of extensions used in the project
    • .vscode/settings.json - folder settings, works when opened as folder (not as workspace)
    • ./*.code-workspace - user settings, overtakes .vscode/settings.json
      • "files.readonlyInclude":{ - prevent accidental editing
      • "files.associations:{" - prevent constant growth from opening C++ extension-less STL header files
      • "cmake.parallelJobs": 4 - 0 defaults to wrong 6 on 4-threaded CPU and slows configuration (in my case)
      • "files.trimTrailingWhitespace": false - stop racing with EditorConfig extension

Branches (diff)

Campare anything here: https://github.com/Challanger524/template-cpp/compare

Other C++ examples

Remark: I did not find any sane and useful C++ starting templates - they simply don't exist. For comparison, just take a look on what Golang community pulled out:

Projects and libraries

Since there no useful templates outside - real projects are the only source of examples.

https://www.reddit.com/r/cpp_questions/comments/n73n32/presenting_a_c_project_on_github_elegantly/

Templates examples and demos
Avoid this: