A modern, feature-rich C++ project template designed for robustness and ease of use. This template provides a complete development workflow, from building and testing to releasing, all powered by CMake.
- Modern C++: Uses C++17 for modern language features.
- CMake Build System: A powerful and flexible build system that handles dependencies and build configurations.
- Dependency Management: Uses
FetchContentto automatically download and manage dependencies likegflags. - Command-Line Parsing: Integrated with
gflagsfor easy command-line argument parsing. - Structured Logging: A simple but effective logger that writes to timestamped files.
- Release Packaging: CPack configuration is included to easily create distributable packages.
- Clear Project Structure: A logical and scalable project structure.
- A C++17 compatible compiler (e.g., GCC, Clang, MSVC)
- CMake (version 3.16 or higher)
- Git
-
Clone the repository:
git clone <your-repository-url> cd <your-project-directory>
-
Configure the project: This will create a
builddirectory and prepare the build environment.cmake -S . -B build -
Compile the code:
cmake --build build -j
The executable will be created at
build/main.--massage [string to add]
--name: [pipeline name]
(base) pranjal@server:~/cpp_template_project/build$ ./main --message "Thank you for using the template" --name "pipeline_name" > Hello World! Thank you for using the template
Log files will be stored: ./cpp_template_project/build/logs/run_20250726_115134/pipline_name.log
[INFO] === Pipeline run started === [INFO] Output: Hello World! Thank you for using the template [INFO] Total time (ms): 0 [INFO] === Pipeline run finished ===
To use this repository as a template for your own C++ project, follow these steps:
- Fork the repository: Go to the GitHub page of this template and click the "Fork" button. This will create a copy of the repository under your GitHub account.
- Clone your forked repository:
git clone https://github.com/YOUR_USERNAME/YOUR_FORKED_REPO_NAME.git cd YOUR_FORKED_REPO_NAME - Rename your project:
- Update
CMakeLists.txt: Change theproject()name in the top-levelCMakeLists.txtfile to your desired project name. - Rename executable (optional): If you want your main executable to have a different name than
main, you can changeadd_executable(main ...)inCMakeLists.txttoadd_executable(YOUR_PROJECT_NAME ...)and also update any references tobuild/mainin the README.
- Update
- Customize your code:
- Modify
main.cc,include/process.h,src/process.cc, andinclude/utils/logger.h,src/utils/logger.ccto implement your project's specific logic. - Add new source files and headers as needed, and update
CMakeLists.txtto include them in your build.
- Modify
- Update README.md: Customize this
README.mdfile with information specific to your project, including its purpose, features, and usage instructions. - Remove
.githistory (optional): If you want to start with a clean Git history for your new project, you can remove the existing.gitdirectory and reinitialize Git:Then, link it to a new empty repository on GitHub.rm -rf .git git init git add . git commit -m "Initial commit for my new project"
- Set up GitHub Actions (optional): If you forked the repository, the GitHub Actions workflow (
.github/workflows/ci.yml) should work automatically. If you created a new repository, you might need to copy the workflow file.
Now you have a new C++ project based on this template, ready for your development!
This template provides a structured workflow for developing your C++ application.
The core application logic resides in the Process class.
include/process.h: Header file for theProcessclass.src/process.cc: Implementation of theProcessclass.
Modify the Process::run method in src/process.cc to implement your main algorithm. You can add new classes and files as needed and update the CMakeLists.txt to include them in the build.
To build the project, run the following commands from the project root:
-
Debug Build (for development):
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug cmake --build build -j -
Release Build (for performance):
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release cmake --build build -j
(Note: This section is a placeholder. You can add your testing framework of choice, such as GTest, and add the necessary CMake configuration.)
A robust testing setup is crucial for any project. We recommend using a testing framework like Google Test.
To add testing to this project, you would typically:
- Add GTest as a dependency in
CMakeLists.txtusingFetchContent. - Create a
tests/directory with your test files. - Add a
add_testcommand inCMakeLists.txtto define your tests. - Run the tests using
ctestfrom thebuilddirectory.
When you are ready to release your project, you can create a distributable package.
-
Configure for Release:
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -
Build the Project:
cmake --build build -j
-
Create the Package: This will create a
.tar.gzarchive in thebuild/directory.cmake --build build --target package
-
Create a GitHub Release:
- Go to the "Releases" page of your GitHub repository.
- Click "Draft a new release".
- Choose a tag version (e.g.,
v1.0.0). - Upload the generated package from the
build/directory. - Publish the release.
Contributions are welcome! If you have a suggestion or find a bug, please open an issue or submit a pull request.
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature/your-feature). - Open a pull request.
Pranjal Bhaskare
This project is licensed under the MIT License - see the LICENSE file for details.