Skip to content

feesmrt/cpp-template-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Template Project

WARNING: REPLACE WITH YOUR OWN README

Author: Martin Bauernschmitt

License: BSD 3-clause

This project is used to generate the base structure of a project automatically. It performs the following tasks:

  • Generates module classes:
    • Class header + source files
    • Class unit test file
    • Doxygen file for detailed module description
  • Generates vscode configuration to debug application
  • Generates version header to identify your project version via git

Usage

Setup

  1. Create a new folder with your project (e.g. francor_awesome)
  2. Initialize a empty repository inside the folder git init
  3. Copy the content of the template folder to the new project folder
  4. Config your project as described in the configuration section
  5. In VSCode press CTRL + B to show build tasks
  6. In VsCode press F5 to debug application

Versioning

The version of your project is determined via git tags. If you want to tag your project with the version 1.0.2 (MAJOR.MINOR.PATCH) execute:

git tag -a v1.0.2 -m "Release 1.0.2"

The next time you build your project the version information will be updated as followed:

/** \brief Major version number of project */
constexpr unsigned int VER_MAJOR = 1;

/** \brief Minor version number of project */
constexpr unsigned int VER_MINOR = 0;

/** \brief Patch version number of project */
constexpr unsigned int VER_PATCH = 2;

If you work on a clean "tagged" project the

constexpr bool VER_RELEASE_BUILD = true;

variable will be set to true. Otherwise it is set to false.

Organization

The project is organized as followed:

  • .vscode/: Visual Studio Code settings and launch files
  • cmake/: Template documents and helper functions for CMake
  • docs/: Documentation generated by doxygen and docs added by user
  • include/: Header files of module classes
    • project_name/:
      • module_name_1/:
        • class_name_1.h
        • class_name_2.h
  • src/: Source files of module classes
    • module_name_1/:
      • class_name_1.cpp
      • class_name_2.cpp
    • main.cpp: Main application
  • tests/: GTest unit-tests
    • module_name_1/:
      • class_name_1_tests.cpp
      • class_name_2_tests.cpp
    • unit_tests.cpp
  • CMakeLists.txt: CMake file to config your project

Most of the folders and files are generated automatically by running cmake in the build directory.

Configuration

You can config your project in the CMakeLists.txt via the following parameters:

# Project information
project(project_name) # Place here your project name (normally root folder name)

# Include functions
include(cmake/functions.cmake) # DO NOT EDIT

# Author information
set(COMPANY "Mustercompany") # Your company name
set(AUTHOR  "Max Mustermann") # Your name
set(E_MAIL  "max.mustermann@mustercompany.de") # E-Mail

# License information
set(LICENSE "BSD 3-clause") # License information

# Enable building version.h
set(GENERATE_VERSION_HEADER ON)

You can add module classes with the command described below. Additional a detailed description is placed in the docs/ folder and a unit test file is generated.

# ---------------------------------------------------------
# Generator settings

# Set namespace
set(PROJECT_NS "project_name_ns")

# Generate class (Namespace, ModuleName, ClassName, Filename of class)
GENERATE_CLASS("${PROJECT_NS}" "my_module" "MyClass" "my_class")

# Generates:
# docs/details/can_details.dox
# include/project_name/can/can_interface.h
# src/can/can_interface.cpp
# tests/can/can_interface_tests.cpp
GENERATE_CLASS("${PROJECT_NS}" "can" "CANInterface" can_interface")

Required tools

The following tools shall be installed

# Build Tools
sudo apt install build-essential git cmake gdb libgtest-dev

# Install GTest
sudo apt install libgtest-dev

# Config GTest to be foundable
cd /usr/src/gtest
sudo mkdir build && cd build
sudo cmake ..
sudo make
sudo cp *.a /usr/lib

# Clangd for Code Analysis
sudo apt install clang-10 clang-format-10 clang-tidy-10 clangd-10
sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-10 10

About

A C++ template project to fastly create the structure of a new project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages