This repository is a template for C/C++ packages.
- CMake
- C/C++ compiler
- check (unit testing framework)
- Doxygen
- clang-format
- clang-tidy
- pre-commit
sudo apt-get install doxygen check clang-format clang-tidy
pip install pre-commit
mkdir ~/c_cpp_ws && cd ~/c_cpp_ws
mkdir build install src
Important
The workspace directory structure is recommended, but not mandatory. You can use any directory structure you prefer.
-
Click on
Use this template
from the repository toolbar and give it a new name. -
Clone the
new
repositorycd ~/c_cpp_ws/src git clone <url>
-
Rename the
PackageName
in the CMakeLists.txt file, header and source files, folder names, config file, etc.
or
-
Follow the package structure and create the necessary files and directories
-
Add the necessary content to the files
-
Initialize the git repository
git init
-
Make sure the
git
repository is initialized. -
Run the following command in the
root
directory of the package to install the pre-commit hooks.pre-commit install
-
Create a build directory for the package
cd ~/c_cpp_ws/build mkdir PackageName && cd PackageName
-
Run the following command in the build directory
cmake -DCMAKE_INSTALL_PREFIX=../../install ../../src/PackageName \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DENABLE_TESTS=ON
-DCMAKE_INSTALL_PREFIX=../../install
: Specifies the installation directory-DCMAKE_BUILD_TYPE=Debug
: Specifies the build type (Debug, Release, RelWithDebInfo, MinSizeRel)-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
: Generates compile_commands.json file-DENABLE_TESTS=ON
: Enables the unit tests-DENABLE_DOC=ON
: Enables the documentation generation
-
Build the package
make -j $(nproc)
- If
ENABLE_TESTS
is set toON
, the tests will be built as well.
- If
-
Install the package
make install
- To generate the documentation, you can use the MkDocs tool.
- The mkdocs.yaml file contains the configuration for the documentation.
- Refer to the Plugins and Reference sections in the Material for MkDocs documentation for more information about the configuration.
- To generate the documentation, you can use the Doxygen tool.
- The Doxyfile file contains the default configuration for the documentation.
Important
Configure the mkdocs.yaml and mkdocs_gh_pages_deploy.yml files accordingly based on whether your project has API documentation or not.
- The pre-commit-config.yaml file contains the configuration for the pre-commit hooks.
- Update the
build
andinstall
paths in theclang-format
andclang-tidy
hooks, based on your workspace setup. - Also, update the
Set up build
andConfigure and build
in the build_format_lint.yml, if you have a different build setup.
- The build_format_lint.yml file contains the configuration to test the package build, and check the code formatting and linting.
- The mkdocs_gh_pages_deploy.yml file contains the configuration to deploy the documentation to GitHub Pages.