https://github.com/mortinger91/cpp-cmake-template
Template for a C++ CMake project, using Github Actions and CTest.
https://github.com/mortinger91/cpp-cmake-template
cmake cpp ctest github-actions template
Last synced: 6 months ago
JSON representation
Template for a C++ CMake project, using Github Actions and CTest.
- Host: GitHub
- URL: https://github.com/mortinger91/cpp-cmake-template
- Owner: mortinger91
- Created: 2023-01-25T15:25:55.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-07T00:51:20.000Z (about 1 year ago)
- Last Synced: 2025-04-06T05:36:28.684Z (6 months ago)
- Topics: cmake, cpp, ctest, github-actions, template
- Language: CMake
- Homepage:
- Size: 115 KB
- Stars: 36
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://github.com/mortinger91/cpp-cmake-template/actions/workflows/main.yml)
# cpp-cmake-template
## Template for a multi-platform C++ CMake project
### Main features:
- CMake files
- CTest unit tests framework
- Github Actions that build and run the tests
- Scripts and VSCode files for ease of use
- Dockerfile for building and running the tests in a container
- Support for compiler cache tools: ccache and sccache
- Formatting via clang-format (that runs automatically in a git pre-commit hook)### Requirements:
- CMake
- Clang
- LLDB
- clang-format
- *(optional for compiler cache)* ccache
- *(optional for IDE debugging)* VSCode 'CodeLLDB' extension
- *(only on Windows)* MSVC compiler## Instructions
### How to set up the project:
Execute VSCode task `build_cmake_debug` or run this script:
./projectFolder/scripts/build_cmake_debug.shThis needs to run the first time and any time you make
changes to a CMake file or add new source or test files.### How to build the project:
Execute VSCode task `build_debug` or run this script:
./projectFolder/scripts/build_debug.shTo build for release execute VSCode task `create_release` or run this script:
./projectFolder/scripts/create_release.sh
All the artifacts will be in the build/ directory.
### How to debug the project:
Launch VSCode `DEBUG` configuration for IDE debugging.
If you want to debug in the command line run:lldb ./build/Debug/bin/cpp-cmake-template
### How to run the tests:
Execute VSCode task `run_tests` or run this script:
./projectFolder/scripts/run_tests.shIf you want to build and run the tests in a fresh Docker container
execute VSCode task `run_tests_in_Docker` or run this script:./projectFolder/scripts/run_tests_in_Docker.sh
### How to add new files to the project:
Add any new source file to a `projectFolder/src/dir` directory.
You can create any new `projectFolder/src/dir` directories.
Add any new test file to the `projectFolder/tests` directory.
Both these operations does not require any changes to CMake files.__Remember to re-run `build_cmake_debug` after you have added new files or directories.__
### Windows:
Use the same VSCode tasks listed above or run the scripts in
this directory: `projectFolder/scripts/windows`.## Possible future improvements:
- Fix Windows built files path
- Static checker (BASH and cpp)
- E2E tests (other than just building, also running the binary to see if there are any run-time errors)
- CMake `install` to install the release build in the system
- Better support for 3rd parties libraries