This repository is a template for C/C++ packages.
.
└── c_cpp_pkg_template
├── .clang-format
├── .clang-tidy
├── CMakeLists.txt
├── docs
│ ├── assets
│ │ └── placeholder
│ ├── index.md
│ └── javascripts
│ └── mathjax.js
├── .github
│ └── workflows
│ └── mkdocs_ci_gh_pages.yml
├── .gitignore
├── include
│ └── PackageName
│ ├── temp.hpp
│ └── template.h
├── mkdocs.yaml
├── PackageName-config.cmake.in
├── .pre-commit-config.yaml
├── README.md
├── src
│ ├── CMakeLists.txt
│ ├── example
│ │ ├── CMakeLists.txt
│ │ └── temp_ex.c
│ └── template.c
└── test
├── CMakeLists.txt
├── main_test.c
└── temp_test.c
- CMake
- C/C++ compiler
- check (unit testing framework)
- clang-format
- clang-tidy
- pre-commit
sudo apt-get install 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.
-
Clone the repository
cd ~/c_cpp_ws/src git clone [email protected]:secorolab/c_cpp_pkg_template.git
-
Rename the cloned repository
mv c_cpp_pkg_template <PackageName> cd <PackageName>
-
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
-
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
Important
Refer the best practices for more information.