This is a template for C++ projects. What you get:
- Library, executable and test code separated in distinct folders.
- Use of modern CMake for building and compiling.
- External libraries fetched by CMake or cloned by Git.
- External libraries installed and managed by Conan or VCPKG.
- Unit testing using Catch2
- General purpose libraries: JSON, spdlog, cxxopts and fmt.
- Continuous integration testing with Github Actions.
- Code coverage reports, including automatic upload to Codecov.
- Code documentation with Doxygen.
├── CMakeLists.txt
├── app
│ ├── CMakesLists.txt
│ └── main.cc
├── cmake
│ └── cmake modules
├── docs
│ ├── Doxyfile
│ └── html/
├── external
│ ├── CMakesLists.txt
│ ├── ...
├── src
│ ├── CMakesLists.txt
│ ├── my_lib.h
│ └── my_lib.cc
└── tests
├── CMakeLists.txt
└── main.cc
Library code goes into src/, main program code in app/ and tests go in tests/.
- CMake 3.16+
- GNU Makefile
- Doxygen
- Conan or VCPKG
- MSVC 2017 (or higher), G++9 (or higher), Clang++9 (or higher)
- Code Coverage (only on GNU|Clang): lcov, gcovr
First, clone this repo and do the preliminary work:
git clone --recursive https://github.com/franneck94/CppProjectTemplate
make prepare
- App Executable: The build type can be Debug/Release/MinSizeRel or RelWithDebInfo
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release --target main
cd bin
./main
- Unit testing: The build type should be Debug for GCC/Clang and Release for MSVC (due to bug).
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake --build . --config Debug --target unit_tests
cd bin
./unit_tests
- Documentation
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake --build . --config Debug --target docs
- Code Coverage (Unix only): The build type has to be Coverage.
cd build
cmake -DCMAKE_BUILD_TYPE=Coverage -DENABLE_CODE_COVERAGE=ON ..
cmake --build . --config Coverage --target coverage
For more info about CMake see here.